-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathinstall.nsi
396 lines (338 loc) · 14 KB
/
install.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
; weasel installation script
!include FileFunc.nsh
!include LogicLib.nsh
!include MUI2.nsh
!include x64.nsh
!include winVer.nsh
Unicode true
;--------------------------------
; General
!ifndef WEASEL_VERSION
!define WEASEL_VERSION 0.1.0
!endif
!ifndef WEASEL_BUILD
!define WEASEL_BUILD 0
!endif
!define WEASEL_ROOT $INSTDIR\weasel-${WEASEL_VERSION}
!define REG_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Weasel"
; The name of the installer
Name "小狼毫 ${WEASEL_VERSION}"
; The file to write
OutFile "archives\weasel-${PRODUCT_VERSION}-installer.exe"
VIProductVersion "${WEASEL_VERSION}.${WEASEL_BUILD}"
VIAddVersionKey /LANG=2052 "ProductName" "小狼毫"
VIAddVersionKey /LANG=2052 "Comments" "Powered by RIME | 中州韻輸入法引擎"
VIAddVersionKey /LANG=2052 "CompanyName" "式恕堂"
VIAddVersionKey /LANG=2052 "LegalCopyright" "Copyleft RIME Developers"
VIAddVersionKey /LANG=2052 "FileDescription" "小狼毫輸入法"
VIAddVersionKey /LANG=2052 "FileVersion" "${WEASEL_VERSION}"
!define MUI_ICON ..\resource\weasel.ico
SetCompressor /SOLID lzma
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages
!insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
; Languages
!insertmacro MUI_LANGUAGE "TradChinese"
LangString DISPLAYNAME ${LANG_TRADCHINESE} "小狼毫輸入法"
LangString LNKFORMANUAL ${LANG_TRADCHINESE} "【小狼毫】說明書"
LangString LNKFORSETTING ${LANG_TRADCHINESE} "【小狼毫】輸入法設定"
LangString LNKFORDICT ${LANG_TRADCHINESE} "【小狼毫】用戶詞典管理"
LangString LNKFORSYNC ${LANG_TRADCHINESE} "【小狼毫】用戶資料同步"
LangString LNKFORDEPLOY ${LANG_TRADCHINESE} "【小狼毫】重新部署"
LangString LNKFORSERVER ${LANG_TRADCHINESE} "小狼毫算法服務"
LangString LNKFORUSERFOLDER ${LANG_TRADCHINESE} "【小狼毫】用戶文件夾"
LangString LNKFORAPPFOLDER ${LANG_TRADCHINESE} "【小狼毫】程序文件夾"
LangString LNKFORUPDATER ${LANG_TRADCHINESE} "【小狼毫】檢查新版本"
LangString LNKFORSETUP ${LANG_TRADCHINESE} "【小狼毫】安裝選項"
LangString LNKFORUNINSTALL ${LANG_TRADCHINESE} "卸載小狼毫"
LangString CONFIRMATION ${LANG_TRADCHINESE} "安裝前,請先卸載舊版本的小狼毫。$\n$\n按下「確定」移除舊版本,按下「取消」放棄本次安裝。"
LangString SYSTEMVERSIONNOTOK ${LANG_TRADCHINESE} "您的系统不被支持,最低系統要求:Windows 8.1!"
LangString AUTOCHKUPDATE ${LANG_TRADCHINESE} "自動檢查版本更新?"
!insertmacro MUI_LANGUAGE "SimpChinese"
LangString DISPLAYNAME ${LANG_SIMPCHINESE} "小狼毫输入法"
LangString LNKFORMANUAL ${LANG_SIMPCHINESE} "【小狼毫】说明书"
LangString LNKFORSETTING ${LANG_SIMPCHINESE} "【小狼毫】输入法设定"
LangString LNKFORDICT ${LANG_SIMPCHINESE} "【小狼毫】用户词典管理"
LangString LNKFORSYNC ${LANG_SIMPCHINESE} "【小狼毫】用户资料同步"
LangString LNKFORDEPLOY ${LANG_SIMPCHINESE} "【小狼毫】重新部署"
LangString LNKFORSERVER ${LANG_SIMPCHINESE} "小狼毫算法服务"
LangString LNKFORUSERFOLDER ${LANG_SIMPCHINESE} "【小狼毫】用户文件夹"
LangString LNKFORAPPFOLDER ${LANG_SIMPCHINESE} "【小狼毫】程序文件夹"
LangString LNKFORUPDATER ${LANG_SIMPCHINESE} "【小狼毫】检查新版本"
LangString LNKFORSETUP ${LANG_SIMPCHINESE} "【小狼毫】安装选项"
LangString LNKFORUNINSTALL ${LANG_SIMPCHINESE} "卸载小狼毫"
LangString CONFIRMATION ${LANG_SIMPCHINESE} '安装前,请先卸载旧版本的小狼毫。$\n$\n点击 "确定" 移除旧版本,或点击 "取消" 放弃本次安装。'
LangString SYSTEMVERSIONNOTOK ${LANG_SIMPCHINESE} "您的系統不被支持,最低系统要求:Windows 8.1!"
LangString AUTOCHKUPDATE ${LANG_SIMPCHINESE} "自动检查版本更新?"
!insertmacro MUI_LANGUAGE "English"
LangString DISPLAYNAME ${LANG_ENGLISH} "Weasel"
LangString LNKFORMANUAL ${LANG_ENGLISH} "Weasel Manual"
LangString LNKFORSETTING ${LANG_ENGLISH} "Weasel Settings"
LangString LNKFORDICT ${LANG_ENGLISH} "Weasel Dictionary Manager"
LangString LNKFORSYNC ${LANG_ENGLISH} "Weasel Sync User Profile"
LangString LNKFORDEPLOY ${LANG_ENGLISH} "Weasel Deploy"
LangString LNKFORSERVER ${LANG_ENGLISH} "Weasel Server"
LangString LNKFORUSERFOLDER ${LANG_ENGLISH} "Weasel User Folder"
LangString LNKFORAPPFOLDER ${LANG_ENGLISH} "Weasel App Folder"
LangString LNKFORUPDATER ${LANG_ENGLISH} "Weasel Check for Updates"
LangString LNKFORSETUP ${LANG_ENGLISH} "Weasel Installation Preference"
LangString LNKFORUNINSTALL ${LANG_ENGLISH} "Uninstall Weasel"
LangString CONFIRMATION ${LANG_ENGLISH} "Before installation, please uninstall the old version of Weasel.$\n$\nPress 'OK' to remove the old version, or 'Cancel' to abort installation."
LangString SYSTEMVERSIONNOTOK ${LANG_ENGLISH} "Your system not supported, minimium system required: Windows 8.1!"
LangString AUTOCHKUPDATE ${LANG_ENGLISH} "Automatically check for updates?"
;--------------------------------
Function .onInit
; if not version >= 8.1, quit and MessageBox(if not silent)
${IfNot} ${AtLeastWin8.1}
IfSilent toquit
MessageBox MB_OK '$(SYSTEMVERSIONNOTOK)'
toquit:
Quit
${EndIf}
ReadRegStr $R0 HKLM "Software\Rime\Weasel" "InstallDir"
StrCmp $R0 "" 0 skip
; The default installation directory
; install x64 build for NativeARM64_WINDOWS11 and NativeAMD64_WINDOWS11
${If} ${AtLeastWin11} ; Windows 11 and above
${If} ${IsNativeARM64}
StrCpy $INSTDIR "$PROGRAMFILES64\Rime"
${ElseIf} ${IsNativeAMD64}
StrCpy $INSTDIR "$PROGRAMFILES64\Rime"
${Else}
StrCpy $INSTDIR "$PROGRAMFILES\Rime"
${Endif}
; install x64 build for NativeAMD64_BELLOW_WINDOWS11
${Else} ; Windows 10 or bellow
${If} ${IsNativeAMD64}
StrCpy $INSTDIR "$PROGRAMFILES64\Rime"
${Else}
StrCpy $INSTDIR "$PROGRAMFILES\Rime"
${Endif}
${Endif}
skip:
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\Weasel" \
"UninstallString"
StrCmp $R0 "" done
StrCpy $0 "Upgrade"
IfSilent uninst 0
MessageBox MB_OKCANCEL|MB_ICONINFORMATION "$(CONFIRMATION)" IDOK uninst
Abort
uninst:
; Backup data directory from previous installation, user files may exist
ReadRegStr $R1 HKLM SOFTWARE\Rime\Weasel "WeaselRoot"
StrCmp $R1 "" call_uninstaller
IfFileExists $R1\data\*.* 0 call_uninstaller
CreateDirectory $TEMP\weasel-backup
CopyFiles $R1\data\*.* $TEMP\weasel-backup
call_uninstaller:
ExecWait '$R0 /S'
Sleep 800
done:
FunctionEnd
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\Rime\Weasel" "InstallDir"
; The stuff to install
Section "Weasel"
SectionIn RO
; Write the new installation path into the registry
; redirect on 64 bit system
; HKLM SOFTWARE\WOW6432Node\Rime\Weasel "InstallDir" "$INSTDIR"
WriteRegStr HKLM SOFTWARE\Rime\Weasel "InstallDir" "$INSTDIR"
; Reset INSTDIR for the new version
StrCpy $INSTDIR "${WEASEL_ROOT}"
IfFileExists "$INSTDIR\WeaselServer.exe" 0 +2
ExecWait '"$INSTDIR\WeaselServer.exe" /quit'
SetOverwrite try
; Set output path to the installation directory.
SetOutPath $INSTDIR
IfFileExists $TEMP\weasel-backup\*.* 0 program_files
CreateDirectory $INSTDIR\data
CopyFiles $TEMP\weasel-backup\*.* $INSTDIR\data
RMDir /r $TEMP\weasel-backup
program_files:
File "LICENSE.txt"
File "README.txt"
File "7-zip-license.txt"
File "7z.dll"
File "7z.exe"
File "COPYING-curl.txt"
File "curl.exe"
File "curl-ca-bundle.crt"
File "rime-install.bat"
File "rime-install-config.bat"
File "start_service.bat"
File "stop_service.bat"
File "weasel.dll"
${If} ${RunningX64}
File "weaselx64.dll"
${EndIf}
${If} ${IsNativeARM64}
File /nonfatal "weaselARM.dll"
File /nonfatal "weaselARM64.dll"
File /nonfatal "weaselARM64X.dll"
${EndIf}
File "weasel.ime"
${If} ${RunningX64}
File "weaselx64.ime"
${EndIf}
${If} ${IsNativeARM64}
File /nonfatal "weaselARM.ime"
File /nonfatal "weaselARM64.ime"
File /nonfatal "weaselARM64X.ime"
${EndIf}
; install x64 build for NativeARM64_WINDOWS11 and NativeAMD64_WINDOWS11
${If} ${AtLeastWin11} ; Windows 11 and above
${If} ${IsNativeARM64}
File "WeaselDeployer.exe"
File "WeaselServer.exe"
File "rime.dll"
File "WinSparkle.dll"
${ElseIf} ${IsNativeAMD64}
File "WeaselDeployer.exe"
File "WeaselServer.exe"
File "rime.dll"
File "WinSparkle.dll"
${Else}
File "Win32\WeaselDeployer.exe"
File "Win32\WeaselServer.exe"
File "Win32\rime.dll"
File "Win32\WinSparkle.dll"
${Endif}
; install x64 build for NativeAMD64_BELLOW_WINDOWS11
${Else} ; Windows 10 or bellow
${If} ${IsNativeAMD64}
File "WeaselDeployer.exe"
File "WeaselServer.exe"
File "rime.dll"
File "WinSparkle.dll"
${Else}
File "Win32\WeaselDeployer.exe"
File "Win32\WeaselServer.exe"
File "Win32\rime.dll"
File "Win32\WinSparkle.dll"
${Endif}
${Endif}
File "WeaselSetup.exe"
; shared data files
SetOutPath $INSTDIR\data
File "data\*.yaml"
File /nonfatal "data\*.txt"
File /nonfatal "data\*.gram"
; opencc data files
SetOutPath $INSTDIR\data\opencc
File "data\opencc\*.json"
File "data\opencc\*.ocd*"
; images
SetOutPath $INSTDIR\data\preview
File "data\preview\*.png"
SetOutPath $INSTDIR
; test /T flag for zh_TW locale
StrCpy $R2 "/i"
${GetParameters} $R0
ClearErrors
${GetOptions} $R0 "/S" $R1
IfErrors +2 0
StrCpy $R2 "/s"
${GetOptions} $R0 "/T" $R1
IfErrors +2 0
StrCpy $R2 "/t"
ExecWait '"$INSTDIR\WeaselSetup.exe" $R2'
; Write the uninstall keys for Windows
WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayName" "$(DISPLAYNAME)"
WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayIcon" '"$INSTDIR\WeaselServer.exe"'
WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayVersion" "${WEASEL_VERSION}.${WEASEL_BUILD}"
WriteRegStr HKLM "${REG_UNINST_KEY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegStr HKLM "${REG_UNINST_KEY}" "Publisher" "式恕堂"
WriteRegStr HKLM "${REG_UNINST_KEY}" "URLInfoAbout" "https://rime.im/"
WriteRegStr HKLM "${REG_UNINST_KEY}" "HelpLink" "https://rime.im/docs/"
WriteRegDWORD HKLM "${REG_UNINST_KEY}" "NoModify" 1
WriteRegDWORD HKLM "${REG_UNINST_KEY}" "NoRepair" 1
WriteUninstaller "$INSTDIR\uninstall.exe"
; run as user...
IfSilent deploy_silently
ExecWait "$INSTDIR\WeaselDeployer.exe /install"
GoTo deploy_done
deploy_silently:
ExecWait "$INSTDIR\WeaselDeployer.exe /deploy"
deploy_done:
; don't redirect on 64 bit system for auto run setting
${If} ${IsNativeARM64}
SetRegView 64
${ElseIf} ${IsNativeAMD64}
SetRegView 64
${Endif}
; Write autorun key
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "WeaselServer" "$INSTDIR\WeaselServer.exe"
; Start WeaselServer
Exec "$INSTDIR\WeaselServer.exe"
; option CheckForUpdates
IfSilent DisableAutoCheckUpdate
MessageBox MB_YESNO|MB_ICONINFORMATION "$(AUTOCHKUPDATE)" IDYES EnableAutoCheckUpdate
DisableAutoCheckUpdate:
WriteRegStr HKCU "Software\Rime\Weasel\Updates" "CheckForUpdates" "0"
GoTo end
EnableAutoCheckUpdate:
WriteRegStr HKCU "Software\Rime\Weasel\Updates" "CheckForUpdates" "1"
end:
; Prompt reboot
StrCmp $0 "Upgrade" 0 +2
SetRebootFlag true
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
SetShellVarContext all
CreateDirectory "$SMPROGRAMS\$(DISPLAYNAME)"
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORMANUAL).lnk" "$INSTDIR\README.txt"
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORSETTING).lnk" "$INSTDIR\WeaselDeployer.exe" "" "$SYSDIR\shell32.dll" 21
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORDICT).lnk" "$INSTDIR\WeaselDeployer.exe" "/dict" "$SYSDIR\shell32.dll" 6
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORSYNC).lnk" "$INSTDIR\WeaselDeployer.exe" "/sync" "$SYSDIR\shell32.dll" 26
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORDEPLOY).lnk" "$INSTDIR\WeaselDeployer.exe" "/deploy" "$SYSDIR\shell32.dll" 144
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORSERVER).lnk" "$INSTDIR\WeaselServer.exe" "" "$INSTDIR\WeaselServer.exe" 0
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORUSERFOLDER).lnk" "$INSTDIR\WeaselServer.exe" "/userdir" "$SYSDIR\shell32.dll" 126
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORAPPFOLDER).lnk" "$INSTDIR\WeaselServer.exe" "/weaseldir" "$SYSDIR\shell32.dll" 19
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORUPDATER).lnk" "$INSTDIR\WeaselServer.exe" "/update" "$SYSDIR\shell32.dll" 13
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORSETUP).lnk" "$INSTDIR\WeaselSetup.exe" "" "$SYSDIR\shell32.dll" 162
CreateShortCut "$SMPROGRAMS\$(DISPLAYNAME)\$(LNKFORUNINSTALL).lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
ExecWait '"$INSTDIR\WeaselServer.exe" /quit'
ExecWait '"$INSTDIR\WeaselSetup.exe" /u'
; Remove registry keys
DeleteRegKey HKLM SOFTWARE\Rime
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Weasel"
; don't redirect on 64 bit system for auto run setting
${If} ${IsNativeARM64}
SetRegView 64
${ElseIf} ${IsNativeAMD64}
SetRegView 64
${Endif}
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "WeaselServer"
; Remove files and uninstaller
SetOutPath $TEMP
Delete /REBOOTOK "$INSTDIR\data\opencc\*.*"
Delete /REBOOTOK "$INSTDIR\data\preview\*.*"
Delete /REBOOTOK "$INSTDIR\data\*.*"
Delete /REBOOTOK "$INSTDIR\*.*"
RMDir /REBOOTOK "$INSTDIR\data\opencc"
RMDir /REBOOTOK "$INSTDIR\data\preview"
RMDir /REBOOTOK "$INSTDIR\data"
RMDir /REBOOTOK "$INSTDIR"
SetShellVarContext all
Delete /REBOOTOK "$SMPROGRAMS\$(DISPLAYNAME)\*.*"
RMDir /REBOOTOK "$SMPROGRAMS\$(DISPLAYNAME)"
; Prompt reboot
SetRebootFlag true
SectionEnd