From a098f118b61b4276866efcaf3f8ea845af5b1ee8 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 17 May 2019 11:35:35 +0200 Subject: [PATCH] Follow-up of c62006048fb01dbcc3652fb4e5a03b9a5905abda -> Notify Windows only when the its registry is changed --- src/slic3r/GUI/GUI_App.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fd5a3e9f0..f1bbd0a0b 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -998,7 +998,7 @@ void GUI_App::associate_3mf_files() { // see as reference: https://stackoverflow.com/questions/20245262/c-program-needs-an-file-association - auto reg_set = [](HKEY hkeyHive, const wchar_t* pszVar, const wchar_t* pszValue) + auto reg_set = [](HKEY hkeyHive, const wchar_t* pszVar, const wchar_t* pszValue)->bool { wchar_t szValueCurrent[1000]; DWORD dwType; @@ -1010,26 +1010,32 @@ void GUI_App::associate_3mf_files() if ((iRC != ERROR_SUCCESS) && !bDidntExist) // an error occurred - return; + return false; if (!bDidntExist) { if (dwType != REG_SZ) // invalid type - return; + return false; if (::wcscmp(szValueCurrent, pszValue) == 0) // value already set - return; + return false; } DWORD dwDisposition; HKEY hkey; iRC = ::RegCreateKeyExW(hkeyHive, pszVar, 0, 0, 0, KEY_ALL_ACCESS, nullptr, &hkey, &dwDisposition); + bool ret = false; if (iRC == ERROR_SUCCESS) + { iRC = ::RegSetValueExW(hkey, L"", 0, REG_SZ, (BYTE*)pszValue, (::wcslen(pszValue) + 1) * sizeof(wchar_t)); + if (iRC == ERROR_SUCCESS) + ret = true; + } RegCloseKey(hkey); + return ret; }; wchar_t app_path[MAX_PATH]; @@ -1044,11 +1050,14 @@ void GUI_App::associate_3mf_files() std::wstring reg_prog_id = reg_base + L"\\" + prog_id; std::wstring reg_prog_id_command = reg_prog_id + L"\\Shell\\Open\\Command"; - reg_set(HKEY_CURRENT_USER, reg_extension.c_str(), prog_id.c_str()); - reg_set(HKEY_CURRENT_USER, reg_prog_id.c_str(), prog_desc.c_str()); - reg_set(HKEY_CURRENT_USER, reg_prog_id_command.c_str(), prog_command.c_str()); + bool is_new = false; + is_new |= reg_set(HKEY_CURRENT_USER, reg_extension.c_str(), prog_id.c_str()); + is_new |= reg_set(HKEY_CURRENT_USER, reg_prog_id.c_str(), prog_desc.c_str()); + is_new |= reg_set(HKEY_CURRENT_USER, reg_prog_id_command.c_str(), prog_command.c_str()); - ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr); + if (is_new) + // notify Windows only when any of the values gets changed + ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr); } #endif // __WXMSW__