diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 97efcfe..5daa730 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -275,6 +275,11 @@ jobs: - name: Initialize submodules run: git submodule update --init --recursive + - name: Copy nsProcess plugin to NSIS folder + run: | + $nsisPluginDir = "C:\Program Files (x86)\NSIS\Plugins\x86-unicode" + copy "${{ github.workspace }}\scripts\windows\nsProcess.dll" $nsisPluginDir + - name: Build CrossDesk run: xmake b -vy crossdesk diff --git a/scripts/windows/nsProcess.dll b/scripts/windows/nsProcess.dll new file mode 100644 index 0000000..2478624 Binary files /dev/null and b/scripts/windows/nsProcess.dll differ diff --git a/scripts/windows/nsis_script.nsi b/scripts/windows/nsis_script.nsi index c7d3751..81daee6 100644 --- a/scripts/windows/nsis_script.nsi +++ b/scripts/windows/nsis_script.nsi @@ -38,6 +38,9 @@ RequestExecutionLevel admin !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ; ------ End of MUI Definition ------ +; Include LogicLib for process handling +!include "LogicLib.nsh" + Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" OutFile "crossdesk-win-x64-${PRODUCT_VERSION}.exe" InstallDir "$PROGRAMFILES\CrossDesk" @@ -66,6 +69,29 @@ Section "VC++ Runtime" SectionEnd Section "MainSection" + ; Check if CrossDesk is running + StrCpy $1 "crossdesk.exe" + + nsProcess::_FindProcess "$1" + Pop $R0 + ${If} $R0 = 0 ; + MessageBox MB_ICONQUESTION|MB_YESNO "CrossDesk is running. Do you want to close it and continue the installation?" IDYES closeApp IDNO cancelInstall + ${Else} + Goto installApp + ${EndIf} + +closeApp: + nsProcess::_KillProcess "$1" + Pop $R0 + Sleep 500 + Goto installApp + +cancelInstall: + SetDetailsPrint both + MessageBox MB_ICONEXCLAMATION|MB_OK "Installation has been aborted." + Abort + +installApp: SetOutPath "$INSTDIR" SetOverwrite ifnewer @@ -108,6 +134,29 @@ Section -AdditionalIcons SectionEnd Section "Uninstall" + ; Check if CrossDesk is running + StrCpy $1 "crossdesk.exe" + + nsProcess::_FindProcess "$1" + Pop $R0 + ${If} $R0 = 0 + MessageBox MB_ICONQUESTION|MB_YESNO "CrossDesk is running. Do you want to close it and uninstall?" IDYES closeApp IDNO cancelUninstall + ${Else} + Goto uninstallApp + ${EndIf} + +closeApp: + nsProcess::_KillProcess "$1" + Pop $R0 + Sleep 500 + Goto uninstallApp + +cancelUninstall: + SetDetailsPrint both + MessageBox MB_ICONEXCLAMATION|MB_OK "Uninstallation has been aborted." + Abort + +uninstallApp: ; Delete main executable and uninstaller Delete "$INSTDIR\crossdesk.exe" Delete "$INSTDIR\uninstall.exe" @@ -133,4 +182,4 @@ SectionEnd ; ------ Functions ------ Function LaunchApp Exec "$INSTDIR\crossdesk.exe" -FunctionEnd \ No newline at end of file +FunctionEnd