|
2 | 2 | #include "Installer.h"
|
3 | 3 |
|
4 | 4 | #include "EditWithNppExplorerCommandHandler.h"
|
| 5 | +#include "PathHelper.h" |
| 6 | +#include "AclHelper.h" |
5 | 7 |
|
6 | 8 | #define GUID_STRING_SIZE 40
|
7 | 9 |
|
@@ -126,7 +128,7 @@ LRESULT CreateRegistryKey(const HKEY hive, const wstring& key, const wstring& na
|
126 | 128 | return lResult;
|
127 | 129 | }
|
128 | 130 |
|
129 |
| -LRESULT CleanupRegistry(const wstring guid) |
| 131 | +LRESULT CleanupRegistry(const wstring& guid) |
130 | 132 | {
|
131 | 133 | constexpr int bufferSize = MAX_PATH + GUID_STRING_SIZE;
|
132 | 134 | WCHAR buffer[bufferSize];
|
@@ -233,12 +235,24 @@ HRESULT MoveFileToTempAndScheduleDeletion(const wstring& filePath)
|
233 | 235 | return S_OK;
|
234 | 236 | }
|
235 | 237 |
|
| 238 | +HRESULT ResetAclPermissionsOnApplicationFolder() |
| 239 | +{ |
| 240 | + // First we get the path where Notepad++ is installed. |
| 241 | + const wstring applicationPath = GetApplicationPath(); |
| 242 | + |
| 243 | + // Create a new AclHelper |
| 244 | + AclHelper aclHelper; |
| 245 | + |
| 246 | + // Reset the ACL of the folder where Notepad++ is installed. |
| 247 | + aclHelper.ResetAcl(applicationPath); |
| 248 | +} |
| 249 | + |
236 | 250 | HRESULT NppShell::Installer::RegisterSparsePackage()
|
237 | 251 | {
|
238 | 252 | PackageManager packageManager;
|
239 | 253 | AddPackageOptions options;
|
240 | 254 |
|
241 |
| - const wstring externalLocation = GetInstallationPath(); |
| 255 | + const wstring externalLocation = GetContextMenuPath(); |
242 | 256 | const wstring sparsePkgPath = externalLocation + L"\\NppShell.msix";
|
243 | 257 |
|
244 | 258 | Uri externalUri(externalLocation);
|
@@ -290,12 +304,15 @@ HRESULT NppShell::Installer::UnregisterSparsePackage()
|
290 | 304 | break;
|
291 | 305 | }
|
292 | 306 |
|
| 307 | + // After unregistering the sparse package, we reset the folder permissions of the folder where we are installed. |
| 308 | + ResetAclPermissionsOnApplicationFolder(); |
| 309 | + |
293 | 310 | return S_OK;
|
294 | 311 | }
|
295 | 312 |
|
296 | 313 | HRESULT NppShell::Installer::RegisterOldContextMenu()
|
297 | 314 | {
|
298 |
| - const wstring installationPath = GetInstallationPath(); |
| 315 | + const wstring installationPath = GetContextMenuPath(); |
299 | 316 | const wstring guid = GetCLSIDString();
|
300 | 317 |
|
301 | 318 | CreateRegistryKey(HKEY_LOCAL_MACHINE, ShellKey, L"ExplorerCommandHandler", guid.c_str());
|
@@ -340,9 +357,11 @@ HRESULT NppShell::Installer::Install()
|
340 | 357 | result = RegisterOldContextMenu();
|
341 | 358 | }
|
342 | 359 |
|
343 |
| - // Ensure NppModernShell files have been moved away. |
344 |
| - MoveFileToTempAndScheduleDeletion(GetInstallationPath() + L"\\NppModernShell.dll"); |
345 |
| - MoveFileToTempAndScheduleDeletion(GetInstallationPath() + L"\\NppModernShell.msix"); |
| 360 | + // Ensure NppModernShell and NppShell files have been moved away from the main program directory. |
| 361 | + MoveFileToTempAndScheduleDeletion(GetApplicationPath() + L"\\NppShell.dll"); |
| 362 | + MoveFileToTempAndScheduleDeletion(GetApplicationPath() + L"\\NppShell.msix"); |
| 363 | + MoveFileToTempAndScheduleDeletion(GetApplicationPath() + L"\\NppModernShell.dll"); |
| 364 | + MoveFileToTempAndScheduleDeletion(GetApplicationPath() + L"\\NppModernShell.msix"); |
346 | 365 |
|
347 | 366 | SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
|
348 | 367 |
|
|
0 commit comments