返回 CodeWhale
codewhale.nsi
根目录 / scripts / installer / codewhale.nsi
1 ; codewhale.nsi — NSIS installer for CodeWhale (Windows)
2 ;
3 ; Requirements (see https://github.com/codewhale-hq/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/codewhale-hq/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 !ifdef COMPILED_HOST
55 !insertmacro MUI_PAGE_COMPONENTS
56 !endif
57 !insertmacro MUI_PAGE_DIRECTORY
58 !insertmacro MUI_PAGE_INSTFILES
59 !insertmacro MUI_PAGE_FINISH
60
61 !insertmacro MUI_UNPAGE_CONFIRM
62 !insertmacro MUI_UNPAGE_INSTFILES
63
64 ;--------------------------------
65 ; Languages
66 ;--------------------------------
67 !insertmacro MUI_LANGUAGE "English"
68 !insertmacro MUI_LANGUAGE "SimpChinese"
69
70 ;--------------------------------
71 ; Installer Sections
72 ;--------------------------------
73 Section "Install" SecInstall
74 SetOutPath "$INSTDIR"
75 File "update-user-path.ps1"
76
77 SetOutPath "$INSTDIR\bin"
78
79 ; Copy binaries (single binary) and the Windows Terminal launcher (#1854)
80 File "codewhale.exe"
81 File "codew.exe"
82 File "codewhale.bat"
83
84 ; Write uninstaller
85 WriteUninstaller "$INSTDIR\Uninstall.exe"
86
87 CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
88 CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\bin\codewhale.bat" "" "$INSTDIR\bin\codewhale.exe" 0
89
90 ; NSIS strings default to 1024 characters. ReadRegStr returns an empty string
91 ; when a registry value exceeds that limit, which used to make a long user
92 ; PATH look absent and overwrite it. Use PowerShell/.NET registry APIs so the
93 ; complete raw value and its REG_SZ/REG_EXPAND_SZ kind are preserved.
94 Call AddToUserPath
95
96 ; Store install directory for uninstaller
97 WriteRegStr HKCU "Software\${PRODUCT_NAME}" "InstallDir" "$INSTDIR"
98 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}"
99 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
100 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "QuietUninstallString" "$\"$INSTDIR\Uninstall.exe$\" /S"
101 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "${PRODUCT_PUBLISHER}"
102 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
103 WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayVersion" "${VERSION}"
104 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoModify" 1
105 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1
106
107 ; Calculate and store installed size
108 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
109 IntFmt $0 "0x%08X" $0
110 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "EstimatedSize" "$0"
111 SectionEnd
112
113 Function AddToUserPath
114 ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$INSTDIR\update-user-path.ps1" -Operation Add -Entry "$INSTDIR\bin"' $0
115 IntCmp $0 0 add_path_done
116 DetailPrint "Failed to add CodeWhale to the current-user PATH (exit code $0)."
117 IfSilent +2
118 MessageBox MB_ICONSTOP|MB_OK "CodeWhale could not safely update your user PATH. Installation has stopped without replacing the existing PATH."
119 SetErrorLevel 1
120 Abort
121
122 add_path_done:
123 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
124 FunctionEnd
125
126 ;--------------------------------
127 ; Uninstaller Section
128 ;--------------------------------
129 ; Only a reviewed release build defines COMPILED_HOST. The component is
130 ; explicitly opt-in and never changes [extension_host] runtime = "node".
131 !ifdef COMPILED_HOST
132 Section /o "Compiled extension host (Bun, opt-in)" SecCompiledHost
133 SetOutPath "$INSTDIR\bin"
134 File "codewhale-extension-host.exe"
135 File "codewhale-extension-host.LICENSES.txt"
136 File "codewhale-extension-host.relink-source.tar.gz"
137 File "codewhale-extension-host.release.json"
138 WriteRegDWORD HKCU "Software\${PRODUCT_NAME}" "CompiledHostInstalled" 1
139 SectionEnd
140 !endif
141
142 Section "Uninstall"
143 ; Remove only CodeWhale's exact entry before deleting the helper. The helper
144 ; handles PATH values longer than NSIS_MAX_STRLEN without truncation.
145 Call un.RemoveFromUserPath
146
147 ; Remove binaries, launcher, and Start Menu shortcut (single binary)
148 Delete "$INSTDIR\bin\codewhale.exe"
149 Delete "$INSTDIR\bin\codew.exe"
150 Delete "$INSTDIR\bin\codewhale.bat"
151 ReadRegDWORD $R0 HKCU "Software\${PRODUCT_NAME}" "CompiledHostInstalled"
152 ${If} $R0 == 1
153 Delete "$INSTDIR\bin\codewhale-extension-host.exe"
154 Delete "$INSTDIR\bin\codewhale-extension-host.LICENSES.txt"
155 Delete "$INSTDIR\bin\codewhale-extension-host.relink-source.tar.gz"
156 Delete "$INSTDIR\bin\codewhale-extension-host.release.json"
157 ${EndIf}
158 Delete "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk"
159 RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
160 Delete "$INSTDIR\update-user-path.ps1"
161 Delete "$INSTDIR\Uninstall.exe"
162 RMDir "$INSTDIR\bin"
163 RMDir "$INSTDIR"
164
165 ; Remove registry keys
166 DeleteRegKey HKCU "Software\${PRODUCT_NAME}"
167 DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
168 SectionEnd
169
170 Function un.RemoveFromUserPath
171 ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$INSTDIR\update-user-path.ps1" -Operation Remove -Entry "$INSTDIR\bin"' $0
172 IntCmp $0 0 remove_path_done
173 DetailPrint "Failed to remove CodeWhale from the current-user PATH (exit code $0)."
174 IfSilent +2
175 MessageBox MB_ICONSTOP|MB_OK "CodeWhale could not safely update your user PATH. Uninstallation has stopped without replacing the existing PATH."
176 SetErrorLevel 1
177 Abort
178
179 remove_path_done:
180 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
181 FunctionEnd
182
182 lines Plain Text