diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-01-17 13:11:51 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-01-17 13:11:51 +0100 |
| commit | b746ee3c93454482d02fb8f64393350a79587b99 (patch) | |
| tree | 4eefd163e40b52526e63f4b8a100f4f9e8c38a7b | |
| parent | 346f4e99320d1aa38bea05d8dd8559416983048c (diff) | |
| parent | 9137a9d080d028f90e41fdd679b2105122357c00 (diff) | |
| download | mullvadvpn-b746ee3c93454482d02fb8f64393350a79587b99.tar.xz mullvadvpn-b746ee3c93454482d02fb8f64393350a79587b99.zip | |
Merge branch 'syspath-fix'
| -rw-r--r-- | dist-assets/windows/installer.nsh | 3 | ||||
| -rw-r--r-- | windows/nsis-plugins/src/pathedit/pathedit.cpp | 135 | ||||
| m--------- | windows/windows-libraries | 0 |
3 files changed, 96 insertions, 42 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh index ede24932ab..74c4a7f050 100644 --- a/dist-assets/windows/installer.nsh +++ b/dist-assets/windows/installer.nsh @@ -850,10 +850,9 @@ ${BreakInstallation} Abort ${EndIf} - - ${InstallTrayIcon} ${AddCLIToEnvironPath} + ${InstallTrayIcon} Pop $R0 diff --git a/windows/nsis-plugins/src/pathedit/pathedit.cpp b/windows/nsis-plugins/src/pathedit/pathedit.cpp index 8d371ce6d0..ff01fa8a0f 100644 --- a/windows/nsis-plugins/src/pathedit/pathedit.cpp +++ b/windows/nsis-plugins/src/pathedit/pathedit.cpp @@ -22,8 +22,9 @@ using namespace common::registry; using ValueStringType = RegistryKey::ValueStringType; using common::string::Lower; -static const wchar_t pathKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"; -static const wchar_t pathValName[] = L"Path"; +static constexpr wchar_t pathKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"; +static constexpr wchar_t pathValName[] = L"Path"; +static constexpr size_t messageTimeoutInterval = 5; namespace { @@ -111,35 +112,59 @@ 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); + DWORD result; + THROW_GLE_IF( + SendMessageTimeoutA( + HWND_BROADCAST, + WM_SETTINGCHANGE, + 0, + (LPARAM)"Environment", + SMTO_ABORTIFHUNG, + messageTimeoutInterval, + &result + ), + 0, + "SendMessageTimeoutA" + ); THROW_GLE_IF( - SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), + SendMessageTimeoutW( + HWND_BROADCAST, + WM_SETTINGCHANGE, + 0, + (LPARAM)L"Environment", + SMTO_ABORTIFHUNG, + messageTimeoutInterval, + &result + ), 0, - "SendNotifyMessage" + "SendMessageTimeoutW" ); pushstring(L""); @@ -184,27 +209,57 @@ 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) + { + DWORD result; + THROW_GLE_IF( + SendMessageTimeoutA( + HWND_BROADCAST, + WM_SETTINGCHANGE, + 0, + (LPARAM)"Environment", + SMTO_ABORTIFHUNG, + messageTimeoutInterval, + &result + ), + 0, + "SendMessageTimeoutA" + ); THROW_GLE_IF( - SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"), + SendMessageTimeoutW( + HWND_BROADCAST, + WM_SETTINGCHANGE, + 0, + (LPARAM)L"Environment", + SMTO_ABORTIFHUNG, + messageTimeoutInterval, + &result + ), 0, - "SendNotifyMessage" + "SendMessageTimeoutW" ); } diff --git a/windows/windows-libraries b/windows/windows-libraries -Subproject 4d6bf2967f1cd881806ac74aec099dd843af8d3 +Subproject a1a8fa847b29d828c45127d285ad506d1c38639 |
