diff --git a/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Task.php b/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Task.php index 474b1c6..3928c3e 100644 --- a/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Task.php +++ b/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Task.php @@ -85,7 +85,7 @@ public static function titleExists($title){ private static function exec($filter = false){ // cp изменит вывод на английский язык - $list = WSH::cmd('chcp 65001 | tasklist /V /FO CSV /NH' . ($filter === false ? '' : ' /FI ":filter"'), ['filter' => $filter], false, 'utf-8'); + $list = WSH::cmd('chcp 65001 | tasklist /V /FO CSV /NH' . ($filter === false ? '' : ' /FI ":filter"'), ['filter' => $filter], 'utf-8'); return self::parseAnswer($list); } diff --git a/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Windows.php b/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Windows.php index c6ce3d9..a4739d7 100644 --- a/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Windows.php +++ b/src/vendor/develnext.bundle.windows.WindowsBundle/bundle/windows/Windows.php @@ -15,7 +15,7 @@ class Windows { - const VERSION = '1.0.0.0'; + const VERSION = '1.1.0.0'; /** * --RU-- @@ -96,8 +96,8 @@ public static function getTemp() */ public static function getDriveSerial($drive){ $drive = str::endsWith($drive, ':') ? $drive : $drive . ':'; - $parts = WSH::WMIC('path Win32_LogicalDiskToPartition get', true); - $devices = WSH::WMIC('path Win32_PhysicalMedia get', true); + $parts = WSH::WMIC('path Win32_LogicalDiskToPartition get'); + $devices = WSH::WMIC('path Win32_PhysicalMedia get'); foreach($parts as $part){ if(str::contains($part['Dependent'], '"' . $drive . '"')){ @@ -133,7 +133,7 @@ public static function getDrives(){ * @return array */ public static function getOS(){ - return WSH::WMIC('OS get', true)[0]; + return WSH::WMIC('OS get')[0]; } /** @@ -143,7 +143,7 @@ public static function getOS(){ * @return string */ public static function getMotherboard(){ - return WSH::WMIC('baseboard get', true)[0]; + return WSH::WMIC('baseboard get')[0]; } /** @@ -153,7 +153,7 @@ public static function getMotherboard(){ * @return string */ public static function getMotherboardSerial(){ - return WSH::WMIC('baseboard get SerialNumber', true)[0]['SerialNumber']; + return WSH::WMIC('baseboard get SerialNumber')[0]['SerialNumber']; } /** @@ -162,7 +162,7 @@ public static function getMotherboardSerial(){ * @return string */ public static function getMotherboardManufacturer(){ - return WSH::WMIC('baseboard get Manufacturer', true)[0]['Manufacturer']; + return WSH::WMIC('baseboard get Manufacturer')[0]['Manufacturer']; } /** @@ -171,7 +171,7 @@ public static function getMotherboardManufacturer(){ * @return string */ public static function getMotherboardProduct(){ - return WSH::WMIC('baseboard get Product', true)[0]['Product']; + return WSH::WMIC('baseboard get Product')[0]['Product']; } /** @@ -180,7 +180,7 @@ public static function getMotherboardProduct(){ * @return string */ public static function getCpuVoltage(){ - return WSH::WMIC('CPU get CurrentVoltage', true)[0]['CurrentVoltage']; + return WSH::WMIC('CPU get CurrentVoltage')[0]['CurrentVoltage']; } /** @@ -189,16 +189,16 @@ public static function getCpuVoltage(){ * @return string */ public static function getCpuManufacturer(){ - return WSH::WMIC('CPU get Manufacturer', true)[0]['Manufacturer']; + return WSH::WMIC('CPU get Manufacturer')[0]['Manufacturer']; } /** * --RU-- - * Получить частоту процессора + * Получить максимальную частоту процессора * @return string */ public static function getCpuFrequency(){ - return WSH::WMIC('CPU get MaxClockSpeed', true)[0]['MaxClockSpeed']; + return WSH::WMIC('CPU get MaxClockSpeed')[0]['MaxClockSpeed']; } /** @@ -207,7 +207,7 @@ public static function getCpuFrequency(){ * @return string */ public static function getCpuSerial(){ - return WSH::WMIC('CPU get ProcessorId', true)[0]['ProcessorId']; + return WSH::WMIC('CPU get ProcessorId')[0]['ProcessorId']; } /** @@ -216,7 +216,7 @@ public static function getCpuSerial(){ * @return string */ public static function getCpuProduct(){ - return WSH::WMIC('CPU get Name', true)[0]['Name']; + return WSH::WMIC('CPU get Name')[0]['Name']; } /** @@ -225,7 +225,7 @@ public static function getCpuProduct(){ * @return string */ public static function getCPU(){ - return WSH::WMIC('CPU get', true)[0]; + return WSH::WMIC('CPU get')[0]; } /** @@ -234,7 +234,7 @@ public static function getCPU(){ * @return string */ public static function getVideoProduct(){ - return WSH::WMIC('Path Win32_VideoController Get VideoProcessor', true)[0]['VideoProcessor']; + return WSH::WMIC('Path Win32_VideoController Get VideoProcessor')[0]['VideoProcessor']; } /** @@ -243,7 +243,7 @@ public static function getVideoProduct(){ * @return string */ public static function getVideoManufacturer(){ - return WSH::WMIC('Path Win32_VideoController Get AdapterCompatibility', true)[0]['AdapterCompatibility']; + return WSH::WMIC('Path Win32_VideoController Get AdapterCompatibility')[0]['AdapterCompatibility']; } /** @@ -252,7 +252,7 @@ public static function getVideoManufacturer(){ * @return string */ public static function getVideoRAM(){ - return WSH::WMIC('Path Win32_VideoController Get AdapterRAM', true)[0]['AdapterRAM']; + return WSH::WMIC('Path Win32_VideoController Get AdapterRAM')[0]['AdapterRAM']; } /** @@ -261,7 +261,7 @@ public static function getVideoRAM(){ * @return string */ public static function getVideoMode(){ - return WSH::WMIC('Path Win32_VideoController Get VideoModeDescription', true)[0]['VideoModeDescription']; + return WSH::WMIC('Path Win32_VideoController Get VideoModeDescription')[0]['VideoModeDescription']; } /** @@ -270,7 +270,7 @@ public static function getVideoMode(){ * @return string */ public static function getVideo(){ - return WSH::WMIC('Path Win32_VideoController Get', true); + return WSH::WMIC('Path Win32_VideoController Get'); } /** @@ -279,7 +279,7 @@ public static function getVideo(){ * @return string */ public static function getSound(){ - return WSH::WMIC('Sounddev Get', true); + return WSH::WMIC('Sounddev Get'); } /** @@ -288,7 +288,7 @@ public static function getSound(){ * @return string */ public static function getUUID(){ - return WSH::WMIC('path win32_computersystemproduct get', true)[0]['UUID']; + return WSH::WMIC('path win32_computersystemproduct get')[0]['UUID']; //return WSH::PowerShell('get-wmiobject Win32_ComputerSystemProduct | Select-Object -ExpandProperty UUID'); } @@ -311,14 +311,24 @@ public static function getMAC(){ return UXApplication::getMacAddress(); } + /** + * Количество миллисекунд с момента запуска системы + * @var int + */ + protected static $bootupTime; + /** * --RU-- * Получить метку времени (в миллисекундах) запуска системы * @return int */ public static function getBootUptime(){ - $data = explode('.', WSH::WMIC('Os Get LastBootUpTime', true)[0]['LastBootUpTime'])[0]; - return (new TimeFormat('yyyyMMddHHmmss'))->parse($data)->getTime(); + if(is_null(self::$bootupTime)){ + $data = explode('.', WSH::WMIC('Os Get LastBootUpTime')[0]['LastBootUpTime'])[0]; + self::$bootupTime = (new TimeFormat('yyyyMMddHHmmss'))->parse($data)->getTime(); + } + + return self::$bootupTime; } /** @@ -337,7 +347,68 @@ public static function getUptime(){ * @return array */ public static function getBatteryInfo(){ - return WSH::WMIC('Path Win32_Battery Get')[0]; + try{ + return WSH::WMIC('Path Win32_Battery Get')[0]; + } catch (\Exception $e){ + throw new WindowsException('Battery does not support'); + } + } + + /** + * --RU-- + * Получить предположительное оставшееся время работы в миллисекундах (на основе данных об батарее) + * (при зарядке АКБ могут быть слишком большие значения) + * @return int + * @throws WindowsException + */ + public static function getBatteryTimeRemaining(){ + try{ + return ((int) WSH::WMIC('Path Win32_Battery Get EstimatedRunTime')[0]['EstimatedRunTime']) * 60 * 1000; + } catch (\Exception $e){ + throw new WindowsException('Battery does not support'); + } + } + + /** + * --RU-- + * Получить процент заряда батареи + * @return int + * @throws WindowsException + */ + public static function getBatteryPercent(){ + try{ + return ++(WSH::WMIC('Path Win32_Battery Get EstimatedChargeRemaining')[0]['EstimatedChargeRemaining']); + } catch (\Exception $e){ + throw new WindowsException('Battery does not support'); + } + } + + /** + * --RU-- + * Получить напряжение батареи (мВ) + * @return int + * @throws WindowsException + */ + public static function getBatteryVoltage(){ + try{ + return (int) WSH::WMIC('Path Win32_Battery Get DesignVoltage')[0]['DesignVoltage']; + } catch (\Exception $e){ + throw new WindowsException('Battery does not support'); + } + } + + /** + * --RU-- + * Находится ли батарея на зарядке + * @return int + * @throws WindowsException + */ + public static function isBatteryCharging(){ + try{ + return ((int)WSH::WMIC('Path Win32_Battery Get BatteryStatus')[0]['BatteryStatus']) > 1; + } catch (\Exception $e){ + throw new WindowsException('Battery does not support'); + } } /** @@ -375,4 +446,140 @@ public static function speak($text){ return WSH::vbScript('CreateObject("SAPI.SpVoice").Speak("'.$text.'")(window.close)'); } + /** + * --RU-- + * Установить уровень яркости (Windows 10 only) + * @param int $level + * @param int $time + * @throws WindowsException + */ + public static function setBrightnessLevel($level, $time = 1){ + try{ + WSH::PowerShell('(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(:time, :level)', ['time' => 1, 'level' => $level], false); + return true; + } catch (\Exception $e){ + throw new WindowsException('Video driver does not support changing the brightness level'); + } + } + + /** + * --RU-- + * Получить уровень яркости (Windows 10 only) + * @return int + * @throws WindowsException + */ + public static function getBrightnessLevel(){ + try{ + return (int) WSH::PowerShell('Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness | select -ExpandProperty CurrentBrightness'); + } catch (\Exception $e){ + throw new WindowsException('Video driver does not support changing the brightness level'); + } + } + + /** + * --RU-- + * Установить уровень громкости (Windows 10 only) + * @param int $level Уровень от 0 до 100 + * @throws WindowsException + */ + public static function setVolumeLevel($level){ + return self::psAudioQuery('Volume', $level/100); + } + + /** + * --RU-- + * Получить уровень громкости (Windows 10 only) + * @return int + * @throws WindowsException + */ + public static function getVolumeLevel(){ + $vol = self::psAudioQuery('Volume'); + $vol = floatval(str_replace(',', '.', $vol)); + return (int)($vol * 100); + } + + + /** + * --RU-- + * Включиь / выключить режим "без звука" + * @param bool $value + * @throws WindowsException + */ + public static function setMute($value){ + return self::psAudioQuery('Mute', ($value ? 1 : 0)); + } + + /** + * --RU-- + * Проверить, включен ли режим "без звука" + * @return bool + * @throws WindowsException + */ + public static function getMute(){ + return self::psAudioQuery('Mute') == 'True'; + } + + private static $psAudioClass = << $query], $saveCache); + public static function WMIC($query){ + $data = self::cmd('WMIC :query /Format:List | more', ['query' => $query]); $reg = '([^\n=]+)=([^\n\r]+)'; $regex = Regex::of($reg, Regex::CASE_INSENSITIVE + Regex::MULTILINE)->with($data); @@ -90,9 +79,9 @@ public static function WMIC($query, $saveCache = false){ * @return string * @throws WindowsException */ - public static function PowerShell($query, $params = []){ + public static function PowerShell($query, $params = [], $wait = true){ $command = Prepare::Query($query, $params); - return self::Exec(['powershell.exe', '-inputformat', 'none', '-command', $command], true); + return self::Exec(['powershell.exe', '-inputformat', 'none', '-command', $command], $wait); } /** @@ -105,23 +94,4 @@ public static function PowerShell($query, $params = []){ public static function vbScript($query){ return self::cmd('mshta vbscript:Execute(":query")', ['query' => str::replace($query, '"', '""')]); } - - protected static $cacheLive = 60, // sec - $cached = []; - - protected static function isCached($command){ - $key = str::hash(implode(' ', $command), 'MD5'); - - if(array_key_exists($key, self::$cached) and self::$cached[$key]['live'] > time()){ - return self::$cached[$key]['answer']; - } else { - return false; - } - } - - protected static function cache($command, $answer){ - $command = is_array($command) ? implode(' ', $command) : $command; - $key = str::hash($command, 'MD5'); - self::$cached[$key] = ['answer' => $answer, 'live' => (time() + self::$cacheLive)]; - } } \ No newline at end of file diff --git a/test/test-brightness.php.bat b/test/test-brightness.php.bat new file mode 100644 index 0000000..53f3afc --- /dev/null +++ b/test/test-brightness.php.bat @@ -0,0 +1,40 @@ +nul&chcp 65001&cls&java -jar "%~dp0jphp-exec.jar" "%~0"&pause&exit /b +define('DS', '\\'); +define('DIR', __DIR__ . DS); +include DIR . "autoloader.inc.php"; + +### + +use bundle\windows\Windows; +/* +Windows::setMute(true); +var_dump(Windows::getMute()); +sleep(3); + +Windows::setMute(false); +var_dump(Windows::getMute()); +sleep(3); + +$level = rand(1,10); +var_dump([ + 'setVolumeLevel('.$level.')' => Windows::setVolumeLevel($level), + 'getVolumeLevel' => Windows::getVolumeLevel(), +]); + +sleep(10);*/ + +$level = rand(50,100); +var_dump(['setBrightnessLevel('.$level.')' => Windows::setBrightnessLevel($level)]); + +//var_dump(Windows::getBrightnessLevel()); + +var_dump([ + 'getBatteryTimeRemaining' => Windows::getBatteryTimeRemaining(), + 'getBatteryPercent' => Windows::getBatteryPercent(), + 'getBatteryVoltage' => Windows::getBatteryVoltage(), + 'isBatteryCharging' => Windows::isBatteryCharging(), +]); + +var_dump(Windows::getBatteryInfo()); + +// Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness \ No newline at end of file diff --git a/test/test-registry2.php.bat b/test/test-registry2.php.bat new file mode 100644 index 0000000..fbe84b8 --- /dev/null +++ b/test/test-registry2.php.bat @@ -0,0 +1,19 @@ +nul&chcp 65001&cls&java -jar "%~dp0jphp-exec.jar" "%~0"&pause&exit /b +define('DS', '\\'); +define('DIR', __DIR__ . DS); +include DIR . "autoloader.inc.php"; + +### + +use bundle\windows\Windows; +use bundle\windows\Registry; +use bundle\windows\Task; + + +$reg = Registry::of('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer')->readFully(true); +foreach($reg as $r){ + echo "\n[" . $r->path . "]\n"; + foreach($r as $v){ + echo $v->key .' = '. $v->value . "\n"; + } +}