Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting Registry Value for JPHP 1.0.3 (7.1.99) #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: windows
version: 2.2
version: 2.4
description: Пакет для взаимодействия с API Windows

plugins:
Expand Down Expand Up @@ -36,7 +36,7 @@ config:
- /gradlew.**

develnext-bundle:
version: 2.2
version: 2.3
name: windows
description: Плагин для взаимодействия с API Windows
author: Ts.Saltan
Expand Down
17 changes: 12 additions & 5 deletions src/bundle/windows/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,18 @@ public function readFully($recursive = false){
$exec = $this->query('query ":path"' . ($recursive ? ' /s' : ''), ['path' => $this->path]);
return $this->parseAnswer($exec);
}

/**
* --RU--
* Чтение ключа
* @param string $key имя ключа
* @return registryItem
* @return registryItem|null
*/
public function read($key){
public function read($key) {
$exec = $this->query('query ":path" /v ":key"', ['path' => $this->path, 'key' => $key]);
$result = $this->parseAnswer($exec);
return isset($result[0]) ? $result[0]->next() : null;
$answer = $this->parseAnswer($exec);

return isset($answer[0]) ? $answer[0]->current() : null; // fix ->next() to ->current() for JPHP 1.0.3 (7.1.99)
}

/**
Expand Down Expand Up @@ -178,6 +179,12 @@ public function searchValue($search, $recursive = false, $fullEqual = false){
return $this->parseAnswer($exec);
}

/**
* -- RU --
* Чтение результата выполнения запроса в реестр
* @param $answer Ответ запроса в реестр
* @return registryResult[]
*/
private function parseAnswer($answer){
$parts = explode("\nHKEY_", $answer);
$return = [];
Expand Down
32 changes: 26 additions & 6 deletions src/bundle/windows/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,20 +906,39 @@ protected static function updateDesktopWallpaper(){
}

/**
* Путь к системной папке windows\system32
* Путь к файлу папке windows\system32
*
* @return string
*/
public static function getSystem32($path) : string {
return self::getSystemDrive() . ':\\Windows\\System32\\' . $path;
$path = self::getSystem32Path() . $path;
return fs::exists($path) ? $path : null;
}

/**
* Путь к системной папке windows\system32
*
* @return string
*/
public static function getSystem32path(): string {
return self::getWindowsPath() . '\\System32\\';
}

/**
* Путь к папке, где установлена Windows
*
* @return string
*/
public static function getWindowsPath() : string {
return $_ENV['WinDir'] ?? $_ENV['SystemRoot'] ?? 'C:\\Windows';
}

/**
* Возвращает букву системного диска
* @return string
*/
public static function getSystemDrive() : string {
$path = $_ENV['HOMEDRIVE'] ?? $_ENV['SystemRoot'] ?? 'C';
$path = $_ENV['SystemDrive'] ?? $_ENV['SystemRoot'] ?? $_ENV['HOMEDRIVE'] ?? 'C';
return str::sub($path, 0, 1);
}

Expand All @@ -933,9 +952,10 @@ public static function getSystemDrive() : string {
* @todo test on win7
*/
public static function getSysNative($path) : string {
return fs::exists(self::getSystemDrive() . ':\\Windows\\SysNative\\' . $path)
? (self::getSystemDrive() . ':\\Windows\\SysNative\\' . $path)
: (self::getSystemDrive() . ':\\Windows\\System32\\' . $path);
$windows = self::getWindowsPath();
return fs::exists("$windows\\SysNative\\$path")
? "$windows\\SysNative\\$path"
: self::getSystem32($path);
}

/**
Expand Down