| 1 | ; codewhale.nsi — NSIS installer for CodeWhale (Windows) |
| 2 | ; |
| 3 | ; Requirements (see https://github.com/Hmbown/CodeWhale/issues/1983): |
| 4 | ; - Install codewhale.exe, codew.exe, and codewhale-tui.exe side-by-side |
| 5 | ; - Default to %LOCALAPPDATA%\Programs\CodeWhale\bin |
| 6 | ; - Add install dir to current-user PATH |
| 7 | ; - Uninstaller removes the PATH entry |
| 8 | ; |
| 9 | ; Usage: |
| 10 | ; 1. Place all .exe files next to this script: |
| 11 | ; codewhale.exe |
| 12 | ; codew.exe |
| 13 | ; codewhale-tui.exe |
| 14 | ; 2. Build: |
| 15 | ; makensis /DVERSION=1.2.3 codewhale.nsi |
| 16 | ; 3. Output: CodeWhaleSetup.exe (in current directory) |
| 17 | |
| 18 | ;-------------------------------- |
| 19 | ; Includes |
| 20 | ;-------------------------------- |
| 21 | !include "MUI2.nsh" |
| 22 | !include "FileFunc.nsh" |
| 23 | |
| 24 | ;-------------------------------- |
| 25 | ; General |
| 26 | ;-------------------------------- |
| 27 | !ifndef VERSION |
| 28 | !define VERSION "0.0.0" |
| 29 | !endif |
| 30 | |
| 31 | !define PRODUCT_NAME "CodeWhale" |
| 32 | !define PRODUCT_PUBLISHER "Hmbown" |
| 33 | !define PRODUCT_WEB_SITE "https://github.com/Hmbown/CodeWhale" |
| 34 | |
| 35 | Name "${PRODUCT_NAME} ${VERSION}" |
| 36 | OutFile "CodeWhaleSetup.exe" |
| 37 | InstallDir "$LOCALAPPDATA\Programs\CodeWhale" |
| 38 | RequestExecutionLevel user |
| 39 | BrandingText "${PRODUCT_NAME} Installer" |
| 40 | |
| 41 | ;-------------------------------- |
| 42 | ; Interface Settings |
| 43 | ;-------------------------------- |
| 44 | !define MUI_ABORTWARNING |
| 45 | !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" |
| 46 | !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" |
| 47 | |
| 48 | ;-------------------------------- |
| 49 | ; Pages |
| 50 | ;-------------------------------- |
| 51 | !insertmacro MUI_PAGE_WELCOME |
| 52 | !insertmacro MUI_PAGE_LICENSE "..\..\LICENSE" |
| 53 | !insertmacro MUI_PAGE_DIRECTORY |
| 54 | !insertmacro MUI_PAGE_INSTFILES |
| 55 | !insertmacro MUI_PAGE_FINISH |
| 56 | |
| 57 | !insertmacro MUI_UNPAGE_CONFIRM |
| 58 | !insertmacro MUI_UNPAGE_INSTFILES |
| 59 | |
| 60 | ;-------------------------------- |
| 61 | ; Languages |
| 62 | ;-------------------------------- |
| 63 | !insertmacro MUI_LANGUAGE "English" |
| 64 | !insertmacro MUI_LANGUAGE "SimpChinese" |
| 65 | |
| 66 | ;-------------------------------- |
| 67 | ; Installer Sections |
| 68 | ;-------------------------------- |
| 69 | Section "Install" SecInstall |
| 70 | SetOutPath "$INSTDIR" |
| 71 | File "update-user-path.ps1" |
| 72 | |
| 73 | SetOutPath "$INSTDIR\bin" |
| 74 | |
| 75 | ; Copy binaries |
| 76 | File "codewhale.exe" |
| 77 | File "codew.exe" |
| 78 | File "codewhale-tui.exe" |
| 79 | |
| 80 | ; Write uninstaller |
| 81 | WriteUninstaller "$INSTDIR\Uninstall.exe" |
| 82 | |
| 83 | ; NSIS strings default to 1024 characters. ReadRegStr returns an empty string |
| 84 | ; when a registry value exceeds that limit, which used to make a long user |
| 85 | ; PATH look absent and overwrite it. Use PowerShell/.NET registry APIs so the |
| 86 | ; complete raw value and its REG_SZ/REG_EXPAND_SZ kind are preserved. |
| 87 | Call AddToUserPath |
| 88 | |
| 89 | ; Store install directory for uninstaller |
| 90 | WriteRegStr HKCU "Software\${PRODUCT_NAME}" "InstallDir" "$INSTDIR" |
| 91 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}" |
| 92 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" |
| 93 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "QuietUninstallString" "$\"$INSTDIR\Uninstall.exe$\" /S" |
| 94 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "${PRODUCT_PUBLISHER}" |
| 95 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" |
| 96 | WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayVersion" "${VERSION}" |
| 97 | WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoModify" 1 |
| 98 | WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1 |
| 99 | |
| 100 | ; Calculate and store installed size |
| 101 | ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 |
| 102 | IntFmt $0 "0x%08X" $0 |
| 103 | WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "EstimatedSize" "$0" |
| 104 | SectionEnd |
| 105 | |
| 106 | Function AddToUserPath |
| 107 | ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$INSTDIR\update-user-path.ps1" -Operation Add -Entry "$INSTDIR\bin"' $0 |
| 108 | IntCmp $0 0 add_path_done |
| 109 | DetailPrint "Failed to add CodeWhale to the current-user PATH (exit code $0)." |
| 110 | IfSilent +2 |
| 111 | MessageBox MB_ICONSTOP|MB_OK "CodeWhale could not safely update your user PATH. Installation has stopped without replacing the existing PATH." |
| 112 | SetErrorLevel 1 |
| 113 | Abort |
| 114 | |
| 115 | add_path_done: |
| 116 | SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 |
| 117 | FunctionEnd |
| 118 | |
| 119 | ;-------------------------------- |
| 120 | ; Uninstaller Section |
| 121 | ;-------------------------------- |
| 122 | Section "Uninstall" |
| 123 | ; Remove only CodeWhale's exact entry before deleting the helper. The helper |
| 124 | ; handles PATH values longer than NSIS_MAX_STRLEN without truncation. |
| 125 | Call un.RemoveFromUserPath |
| 126 | |
| 127 | ; Remove binaries |
| 128 | Delete "$INSTDIR\bin\codewhale.exe" |
| 129 | Delete "$INSTDIR\bin\codew.exe" |
| 130 | Delete "$INSTDIR\bin\codewhale-tui.exe" |
| 131 | Delete "$INSTDIR\update-user-path.ps1" |
| 132 | Delete "$INSTDIR\Uninstall.exe" |
| 133 | RMDir "$INSTDIR\bin" |
| 134 | RMDir "$INSTDIR" |
| 135 | |
| 136 | ; Remove registry keys |
| 137 | DeleteRegKey HKCU "Software\${PRODUCT_NAME}" |
| 138 | DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" |
| 139 | SectionEnd |
| 140 | |
| 141 | Function un.RemoveFromUserPath |
| 142 | ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$INSTDIR\update-user-path.ps1" -Operation Remove -Entry "$INSTDIR\bin"' $0 |
| 143 | IntCmp $0 0 remove_path_done |
| 144 | DetailPrint "Failed to remove CodeWhale from the current-user PATH (exit code $0)." |
| 145 | IfSilent +2 |
| 146 | MessageBox MB_ICONSTOP|MB_OK "CodeWhale could not safely update your user PATH. Uninstallation has stopped without replacing the existing PATH." |
| 147 | SetErrorLevel 1 |
| 148 | Abort |
| 149 | |
| 150 | remove_path_done: |
| 151 | SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 |
| 152 | FunctionEnd |
| 153 |