Clone
ixen
committed
on 22 Dec 20
Fixed problem with shell extension registration/unregistration when there are missing keys in registry (CH-369)
src/chext/DllRegistration.cpp (+14 -9)
39 39         {
40 40                 wchar_t szPath[MAX_PATH + 2] = {};
41 41                 DWORD dwSize = ::GetModuleFileName(hModule, szPath, MAX_PATH + 1);
42 42                 if (dwSize != 0 && dwSize < MAX_PATH)
43 43                 {
44 44                         szPath[dwSize] = L'\0';
45 45                         return szPath;
46 46                 }
47 47
48 48                 return std::wstring();
49 49         }
50 50
51 51         void CreateSingleValue(HKEY key, const wchar_t* pszKey, const wchar_t* pszValueKey, const wchar_t* pszValue)
52 52         {
53 53                 TRegistry reg(key, pszKey, false);
54 54                 reg.SetString(pszValueKey, pszValue);
55 55         }
56 56
57 57         void DeleteSingleValue(HKEY key, const wchar_t* pszKey, const wchar_t* pszValueKey)
58 58         {
59                   TRegistry reg(key, pszKey, false);
  59                 TRegistry reg(key, pszKey, false, false);
  60                 if(reg.IsOpen())
60 61                         reg.DeleteValue(pszValueKey);
61 62         }
62 63
  64         void CreateNodes(HKEY key, const wchar_t* pszKey, std::wstring strSubKey)
  65         {
  66                 TRegistry reg(key, pszKey, false);
  67                 reg.CreateSubKey(strSubKey.c_str());
  68         }
  69
63 70         void CreateNodeWithDefaultValue(HKEY key, const wchar_t* pszKey, const wchar_t* pszSubKey, const wchar_t* pszValue)
64 71         {
  72                 // ensure key exists
  73                 CreateNodes(key, L"", pszKey);
  74
65 75                 TRegistry reg(key, pszKey, false);
66 76                 reg.CreateSubKey(pszSubKey);
67 77
68 78                 std::wstring strNewKey = pszKey;
69 79                 strNewKey += L'\\';
70 80                 strNewKey += pszSubKey;
71 81
72 82                 reg.ReOpen(key, strNewKey.c_str(), false);
73 83                 reg.SetString(L"", pszValue);
74 84         }
75 85
76 86         void DeleteSingleNode(HKEY key, const wchar_t* pszKey, const wchar_t* pszValueKey)
77 87         {
78                   TRegistry reg(key, pszKey, false);
  88                 TRegistry reg(key, pszKey, false, false);
  89                 if(reg.IsOpen())
79 90                         reg.DeleteSubKey(pszValueKey);
80 91         }
81  
82           void CreateNodes(HKEY key, const wchar_t* pszKey, std::wstring strSubKey)
83           {
84                   TRegistry reg(key, pszKey, false);
85                   reg.CreateSubKey(strSubKey.c_str());
86 92 }
87   }
88 93
89 94 DllRegistration::DllRegistration(HMODULE hModule)
90 95 {
91 96         if (hModule == nullptr)
92 97                 throw std::invalid_argument("hModule");
93 98
94 99         m_strModulePath = GetModulePath(hModule);
95 100         if (m_strModulePath.empty())
96 101                 throw std::runtime_error("Cannot retrieve module path");
97 102 }
98 103
99 104 void DllRegistration::RegisterAll()
100 105 {
101 106         RemoveLegacyEntries();
102 107
103 108         RegisterShellExtensionControl();
104 109         RegisterMenuExt();
105 110         RegisterDropMenuExt();
106 111 }
107 112