diff --git a/Source/exehead/Main.c b/Source/exehead/Main.c index 91937597..102ce7d1 100644 --- a/Source/exehead/Main.c +++ b/Source/exehead/Main.c @@ -49,6 +49,8 @@ HWND g_hwnd; HANDLE g_hInstance; #endif +void NSISCALL CleanUp(); + char *ValidateTempDir() { validate_filename(state_temp_dir); @@ -230,21 +232,34 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, #endif//NSIS_CONFIG_LOG end: - if (g_db_hFile != INVALID_HANDLE_VALUE) CloseHandle(g_db_hFile); -#ifdef NSIS_COMPRESS_WHOLE - if (dbd_hFile != INVALID_HANDLE_VALUE) CloseHandle(dbd_hFile); -#endif - if (m_Err) my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20)); + CleanUp(); -#ifdef NSIS_CONFIG_PLUGIN_SUPPORT - // Clean up after plug-ins - if (state_plugins_dir[0]) doRMDir(state_plugins_dir, 1); -#endif // NSIS_CONFIG_PLUGIN_SUPPORT - if (g_hIcon) DeleteObject(g_hIcon); + if (m_Err) + my_MessageBox(m_Err, MB_OK | MB_ICONSTOP | (IDOK << 20)); #if defined(NSIS_SUPPORT_ACTIVEXREG) || defined(NSIS_SUPPORT_CREATESHORTCUT) OleUninitialize(); #endif ExitProcess(ret); +} + +void NSISCALL CleanUp() +{ + if (g_db_hFile != INVALID_HANDLE_VALUE) + { + CloseHandle(g_db_hFile); + g_db_hFile = INVALID_HANDLE_VALUE; + } +#ifdef NSIS_COMPRESS_WHOLE + if (dbd_hFile != INVALID_HANDLE_VALUE) + { + CloseHandle(dbd_hFile); + dbd_hFile = INVALID_HANDLE_VALUE; + } +#endif +#ifdef NSIS_CONFIG_PLUGIN_SUPPORT + // Clean up after plug-ins + doRMDir(state_plugins_dir, 1); +#endif // NSIS_CONFIG_PLUGIN_SUPPORT } \ No newline at end of file diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index fa7182e7..ba87b188 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -79,6 +79,8 @@ static BOOL CALLBACK UninstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l static DWORD WINAPI install_thread(LPVOID p); +void NSISCALL CleanUp(); + HWND insthwnd, insthwnd2, insthwndbutton; HWND m_curwnd; @@ -630,6 +632,11 @@ skipPage: SendMessage(m_curwnd, WM_COMMAND, wParam, lParam); } } + if (uMsg == WM_ENDSESSION && wParam) + { + // the session can end any time after we process this message so we better clean up now + CleanUp(); + } return HandleStaticBkColor(); } diff --git a/Source/exehead/state.h b/Source/exehead/state.h index 9d1321b4..a7befa32 100644 --- a/Source/exehead/state.h +++ b/Source/exehead/state.h @@ -16,9 +16,7 @@ extern char g_caption[NSIS_MAX_STRLEN*2]; extern HWND g_hwnd; extern HANDLE g_hInstance; extern HWND insthwnd,insthwndbutton; -extern HICON g_hIcon; #else #define g_hwnd 0 #define g_hInstance 0 -#define g_hIcon 0 #endif//NSIS_CONFIG_VISIBLE_SUPPORT \ No newline at end of file