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