Skip to content

Commit b808b52

Browse files
xomxdonho
authored andcommitted
Fix Win11 Explorer crash in SafeMode
It's due to NppShell unhandled exception. Sparse packages handling does not work in the Windows OS SafeMode. Fix #45, close #46
1 parent fc47a3b commit b808b52

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Installer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ Package GetSparsePackage()
208208

209209
HRESULT NppShell::Installer::RegisterSparsePackage()
210210
{
211+
if (::GetSystemMetrics(SM_CLEANBOOT) > 0)
212+
return S_FALSE; // Otherwise we will get an unhandled exception later due to HRESULT 0x8007043c (ERROR_NOT_SAFEBOOT_SERVICE).
213+
211214
PackageManager packageManager;
212215
AddPackageOptions options;
213216

@@ -232,6 +235,9 @@ HRESULT NppShell::Installer::RegisterSparsePackage()
232235

233236
HRESULT NppShell::Installer::UnregisterSparsePackage()
234237
{
238+
if (::GetSystemMetrics(SM_CLEANBOOT) > 0)
239+
return S_FALSE; // Only to speed up things a bit here. (code in the following GetSparsePackage() is safe against the ERROR_NOT_SAFEBOOT_SERVICE)
240+
235241
PackageManager packageManager;
236242
IIterable<Package> packages;
237243

@@ -291,6 +297,9 @@ HRESULT NppShell::Installer::UnregisterOldContextMenu()
291297

292298
void ReRegisterSparsePackage()
293299
{
300+
if (::GetSystemMetrics(SM_CLEANBOOT) > 0)
301+
return; // Sparse package reg/unreg cannot be done in the Windows OS SafeMode.
302+
294303
winrt::init_apartment();
295304

296305
// Since we are on Windows 11, we unregister the sparse package as well.
@@ -420,4 +429,4 @@ STDAPI CleanupDll()
420429

421430
// Then we get it moved out of the way and scheduled for deletion.
422431
return MoveFileToTempAndScheduleDeletion(currentFilePath, true);
423-
}
432+
}

0 commit comments

Comments
 (0)