diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-01-17 09:55:38 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-01-17 12:46:13 +0100 |
| commit | a7f29921f3341d5fe6c68785d1e4614feb254656 (patch) | |
| tree | 9c4adc79eb2ccf44ceaa149e5487606eda465759 | |
| parent | 19c1d7623a2bb96fbaada42483b789a557023b74 (diff) | |
| download | mullvadvpn-a7f29921f3341d5fe6c68785d1e4614feb254656.tar.xz mullvadvpn-a7f29921f3341d5fe6c68785d1e4614feb254656.zip | |
Flush registry key before notifying explorer of changes in pathedit
| -rw-r--r-- | windows/nsis-plugins/src/pathedit/pathedit.cpp | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/windows/nsis-plugins/src/pathedit/pathedit.cpp b/windows/nsis-plugins/src/pathedit/pathedit.cpp index 8d371ce6d0..8b4e2b4b7e 100644 --- a/windows/nsis-plugins/src/pathedit/pathedit.cpp +++ b/windows/nsis-plugins/src/pathedit/pathedit.cpp @@ -111,35 +111,37 @@ void __declspec(dllexport) NSISCALL AddSysEnvPath try { - const auto pathToAppend = PopString(); + { + const auto pathToAppend = PopString(); + auto pathRegKey = Registry::OpenKey( + HKEY_LOCAL_MACHINE, + pathKeyName, + true, + RegistryView::Force64 + ); + std::wstring path = ReadPathValue(*pathRegKey); - auto pathRegKey = Registry::OpenKey( - HKEY_LOCAL_MACHINE, - pathKeyName, - true, - RegistryView::Force64 - ); - std::wstring path = ReadPathValue(*pathRegKey); + if (SysPathExists(path, pathToAppend)) + { + pushstring(L""); + pushint(NsisStatus::SUCCESS); + return; + } - if (SysPathExists(path, pathToAppend)) - { - pushstring(L""); - pushint(NsisStatus::SUCCESS); - return; - } + if (!path.empty()) + { + path.append(L";"); + } + path.append(pathToAppend); - if (!path.empty()) - { - path.append(L";"); + pathRegKey->writeValue(pathValName, path, ValueStringType::ExpandableString); + pathRegKey->flush(); } - path.append(pathToAppend); - - pathRegKey->writeValue(pathValName, path, ValueStringType::ExpandableString); THROW_GLE_IF( - SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), + SendNotifyMessageW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), 0, - "SendNotifyMessage" + "SendNotifyMessageW" ); pushstring(L""); @@ -184,27 +186,35 @@ void __declspec(dllexport) NSISCALL RemoveSysEnvPath { const auto pathToRemove = PopString(); - auto pathRegKey = Registry::OpenKey( - HKEY_LOCAL_MACHINE, - pathKeyName, - true, - RegistryView::Force64 - ); - std::wstring path = ReadPathValue(*pathRegKey); + bool updatedPath = false; - // remove value if it exists in PATH - auto pathTokens = common::string::Tokenize(path, L";"); - auto match = FindSysPath(pathTokens, pathToRemove); - if (match != pathTokens.end()) { - pathTokens.erase(match); - path = common::string::Join(pathTokens, L";"); - pathRegKey->writeValue(pathValName, path, ValueStringType::ExpandableString); + auto pathRegKey = Registry::OpenKey( + HKEY_LOCAL_MACHINE, + pathKeyName, + true, + RegistryView::Force64 + ); + std::wstring path = ReadPathValue(*pathRegKey); + // remove value if it exists in PATH + auto pathTokens = common::string::Tokenize(path, L";"); + auto match = FindSysPath(pathTokens, pathToRemove); + if (match != pathTokens.end()) + { + pathTokens.erase(match); + path = common::string::Join(pathTokens, L";"); + pathRegKey->writeValue(pathValName, path, ValueStringType::ExpandableString); + updatedPath = true; + } + } + + if (updatedPath) + { THROW_GLE_IF( - SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), + SendNotifyMessageW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), 0, - "SendNotifyMessage" + "SendNotifyMessageW" ); } |
