Skip to content

Commit

Permalink
Wait for the termination of existing server process before uninstalla…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
PCMan committed Feb 2, 2016
1 parent 6d20995 commit 7691c27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion PIMELauncher/PIMELauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmd, int show) {
server_hwnd = FindWindow(wnd_class_name, NULL); // find existing instance
if (server_hwnd) {
if (quit) { // ask the existing instance to terminate by closing its window
SendMessage(server_hwnd, WM_CLOSE, 0, 0);
DWORD pid;
HANDLE process = INVALID_HANDLE_VALUE;
if (GetWindowThreadProcessId(server_hwnd, &pid)) {
process = OpenProcess(SYNCHRONIZE, FALSE, pid);
}
PostMessage(server_hwnd, WM_CLOSE, 0, 0); // post a request to close the window
if (process != INVALID_HANDLE_VALUE) {
WaitForSingleObject(process, 10000); // wait for the existing instance to terminate
CloseHandle(process);
}
}
return 0; // only one instance of PIME launcher is allowed
}
Expand Down
8 changes: 6 additions & 2 deletions installer/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ AllowSkipFiles off ; cannot skip a file
; icons of the generated installer and uninstaller
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
!define PRODUCT_VERSION "git"
!define PRODUCT_VERSION "0.03"

!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\PIME"
!define HOMEPAGE_URL "https://github.com/EasyIME/"
Expand Down Expand Up @@ -186,6 +186,11 @@ LangString DESC_SecMain ${LANG_ENGLISH} "A test section." ; What's this??
;Uninstaller Section
Section "Uninstall"

; Try to terminate running PIMELauncher and the server process
; Otherwise we cannot replace it.
ExecWait '"$INSTDIR\PIMELauncher.exe" /quit'
Delete "$INSTDIR\PIMELauncher.exe"

; Unregister COM objects (NSIS UnRegDLL command is broken and cannot be used)
ExecWait '"$SYSDIR\regsvr32.exe" /u /s "$INSTDIR\x86\PIMETextService.dll"'
${If} ${RunningX64}
Expand All @@ -197,7 +202,6 @@ Section "Uninstall"
RMDir /r "$INSTDIR\x86"
RMDir /r "$INSTDIR\server"
RMDIR /r "$INSTDIR\python"
Delete "$INSTDIR\PIMELauncher.exe"

DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PIME"
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "PIMELauncher"
Expand Down

0 comments on commit 7691c27

Please sign in to comment.