mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
(Windows) Added proper Unicode support to the Windows Registry find rules 'winregistrypath' and 'winregistryvalue'
This commit is contained in:
parent
4a390fb8e0
commit
ae66e6a317
|
@ -1727,23 +1727,27 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
||||||
HKEY registryKey;
|
HKEY registryKey;
|
||||||
LSTATUS keyStatus {-1};
|
LSTATUS keyStatus {-1};
|
||||||
LSTATUS pathStatus {-1};
|
LSTATUS pathStatus {-1};
|
||||||
char registryPath[1024] {0};
|
std::wstring registryPath(1024, 0);
|
||||||
DWORD pathSize {1024};
|
DWORD pathSize {1024};
|
||||||
|
|
||||||
// First look in HKEY_CURRENT_USER.
|
// First look in HKEY_CURRENT_USER.
|
||||||
keyStatus = RegOpenKeyEx(HKEY_CURRENT_USER, registryKeyPath.c_str(), 0, KEY_QUERY_VALUE,
|
keyStatus = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||||
®istryKey);
|
Utils::String::stringToWideString(registryKeyPath).c_str(), 0,
|
||||||
|
KEY_QUERY_VALUE, ®istryKey);
|
||||||
|
|
||||||
// If not found, then try in HKEY_LOCAL_MACHINE.
|
// If not found, then try in HKEY_LOCAL_MACHINE.
|
||||||
if (keyStatus != ERROR_SUCCESS) {
|
if (keyStatus != ERROR_SUCCESS) {
|
||||||
keyStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryKeyPath.c_str(), 0,
|
keyStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
Utils::String::stringToWideString(registryKeyPath).c_str(), 0,
|
||||||
KEY_QUERY_VALUE, ®istryKey);
|
KEY_QUERY_VALUE, ®istryKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the key exists, then try to retrieve its default value.
|
// If the key exists, then try to retrieve its default value.
|
||||||
if (keyStatus == ERROR_SUCCESS) {
|
if (keyStatus == ERROR_SUCCESS) {
|
||||||
pathStatus = RegGetValue(registryKey, nullptr, nullptr, RRF_RT_REG_SZ, nullptr,
|
pathStatus = RegGetValue(registryKey, nullptr, nullptr, RRF_RT_REG_SZ, nullptr,
|
||||||
®istryPath, &pathSize);
|
®istryPath[0], &pathSize);
|
||||||
|
registryPath.erase(std::find(registryPath.begin(), registryPath.end(), '\0'),
|
||||||
|
registryPath.end());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RegCloseKey(registryKey);
|
RegCloseKey(registryKey);
|
||||||
|
@ -1753,9 +1757,10 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
||||||
// That a value was found does not guarantee that the emulator binary actually exists,
|
// That a value was found does not guarantee that the emulator binary actually exists,
|
||||||
// so check for that as well.
|
// so check for that as well.
|
||||||
if (pathStatus == ERROR_SUCCESS) {
|
if (pathStatus == ERROR_SUCCESS) {
|
||||||
if (Utils::FileSystem::isRegularFile(registryPath) ||
|
if (Utils::FileSystem::isRegularFile(Utils::String::wideStringToString(registryPath)) ||
|
||||||
Utils::FileSystem::isSymlink(registryPath)) {
|
Utils::FileSystem::isSymlink(Utils::String::wideStringToString(registryPath))) {
|
||||||
exePath = Utils::FileSystem::getEscapedPath(registryPath);
|
exePath = Utils::FileSystem::getEscapedPath(
|
||||||
|
Utils::String::wideStringToString(registryPath));
|
||||||
command.replace(startPos, endPos - startPos + 1, exePath);
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
||||||
RegCloseKey(registryKey);
|
RegCloseKey(registryKey);
|
||||||
return exePath;
|
return exePath;
|
||||||
|
@ -1783,43 +1788,48 @@ const std::string FileData::findEmulatorPath(std::string& command)
|
||||||
HKEY registryKey;
|
HKEY registryKey;
|
||||||
LSTATUS keyStatus {-1};
|
LSTATUS keyStatus {-1};
|
||||||
LSTATUS pathStatus {-1};
|
LSTATUS pathStatus {-1};
|
||||||
char path[1024] {0};
|
std::wstring path(1024, 0);
|
||||||
DWORD pathSize {1024};
|
DWORD pathSize {1024};
|
||||||
|
|
||||||
// First look in HKEY_CURRENT_USER.
|
// First look in HKEY_CURRENT_USER.
|
||||||
keyStatus = RegOpenKeyEx(HKEY_CURRENT_USER, registryValueKey.c_str(), 0, KEY_QUERY_VALUE,
|
keyStatus = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||||
®istryKey);
|
Utils::String::stringToWideString(registryValueKey).c_str(), 0,
|
||||||
|
KEY_QUERY_VALUE, ®istryKey);
|
||||||
|
|
||||||
// If not found, then try in HKEY_LOCAL_MACHINE.
|
// If not found, then try in HKEY_LOCAL_MACHINE.
|
||||||
if (keyStatus != ERROR_SUCCESS) {
|
if (keyStatus != ERROR_SUCCESS) {
|
||||||
keyStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryValueKey.c_str(), 0,
|
keyStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
Utils::String::stringToWideString(registryValueKey).c_str(), 0,
|
||||||
KEY_QUERY_VALUE, ®istryKey);
|
KEY_QUERY_VALUE, ®istryKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the key exists, then try to retrieve the defined value.
|
// If the key exists, then try to retrieve the defined value.
|
||||||
if (keyStatus == ERROR_SUCCESS) {
|
if (keyStatus == ERROR_SUCCESS) {
|
||||||
pathStatus =
|
pathStatus = RegGetValue(registryKey, nullptr,
|
||||||
RegGetValue(registryKey, nullptr, reinterpret_cast<LPCSTR>(registryValue.c_str()),
|
Utils::String::stringToWideString(registryValue).c_str(),
|
||||||
RRF_RT_REG_SZ, nullptr, &path, &pathSize);
|
RRF_RT_REG_SZ, nullptr, &path[0], &pathSize);
|
||||||
|
path.erase(std::find(path.begin(), path.end(), '\0'), path.end());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RegCloseKey(registryKey);
|
RegCloseKey(registryKey);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(path) == 0) {
|
if (path.empty()) {
|
||||||
RegCloseKey(registryKey);
|
RegCloseKey(registryKey);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appendString.empty())
|
if (!appendString.empty())
|
||||||
strncat_s(path, 1024, appendString.c_str(), appendString.length());
|
path.append(Utils::String::stringToWideString(appendString));
|
||||||
|
|
||||||
// That a value was found does not guarantee that the emulator binary actually exists,
|
// That a value was found does not guarantee that the emulator binary actually exists,
|
||||||
// so check for that as well.
|
// so check for that as well.
|
||||||
if (pathStatus == ERROR_SUCCESS) {
|
if (pathStatus == ERROR_SUCCESS) {
|
||||||
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
|
if (Utils::FileSystem::isRegularFile(Utils::String::wideStringToString(path)) ||
|
||||||
exePath = Utils::FileSystem::getEscapedPath(path);
|
Utils::FileSystem::isSymlink(Utils::String::wideStringToString(path))) {
|
||||||
|
exePath =
|
||||||
|
Utils::FileSystem::getEscapedPath(Utils::String::wideStringToString(path));
|
||||||
command.replace(startPos, endPos - startPos + 1, exePath);
|
command.replace(startPos, endPos - startPos + 1, exePath);
|
||||||
RegCloseKey(registryKey);
|
RegCloseKey(registryKey);
|
||||||
return exePath;
|
return exePath;
|
||||||
|
|
Loading…
Reference in a new issue