-
Notifications
You must be signed in to change notification settings - Fork 0
/
friggaDataCenter.nsi
246 lines (216 loc) · 8.12 KB
/
friggaDataCenter.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
; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "Frigga Data Center"
!define PRODUCT_VERSION "1.3.0.0"
!define PRODUCT_FILE_VERSION "1.3.0"
!define PRODUCT_PUBLISHER "Frigga, Inc."
!define PRODUCT_WEB_SITE "https://www.friggatech.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\Frigga Data Center.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; 定义 GUID 变量
!define MY_GUID "friggaDataCenter"
SetCompressor lzma
RequestExecutionLevel user
; ------ MUI 现代界面定义1.67 版本以上兼容) ------
!include "MUI.nsh"
!include "nsProcess.nsh"
!include "Sections.nsh"
; MUI 预定义常量
!define MUI_ABORTWARNING
!define MUI_ICON ".\modern-install.ico"
!define MUI_UNICON ".\modern-uninstall.ico"
;!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
;!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 语言选择窗口常量设置
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; 欢迎页面
!define MUI_PAGE_CUSTOMFUNCTION_SHOW FindProcess
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
;!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_SHOW mulu
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\Frigga Data Center.exe"
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
;配置多语言额外字段
LangString RunPrompt ${LANG_ENGLISH} "Detected that the application is running, do you want to close it?"
LangString RunPrompt ${LANG_SimpChinese} "检测到应用正在运行,是否关闭?"
LangString YesButton ${LANG_SimpChinese} "是"
LangString NoButton ${LANG_SimpChinese} "否"
LangString YesButton ${LANG_ENGLISH} "Yes"
LangString NoButton ${LANG_ENGLISH} "No"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile ".\OutFile\Frigga_Data_Center_${PRODUCT_FILE_VERSION}_.exe"
InstallDir "D:\Program Files\Frigga"
;InstallDir "F:\project\nsis\Frigga"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File ".\FilesToInstall\Frigga Data Center.exe"
CreateDirectory "$SMPROGRAMS\Frigga Data Center"
CreateShortCut "$SMPROGRAMS\Frigga Data Center\Frigga Data Center.lnk" "$INSTDIR\Frigga Data Center.exe"
CreateShortCut "$DESKTOP\Frigga Data Center.lnk" "$INSTDIR\Frigga Data Center.exe"
File /r ".\FilesToInstall\*.*"
Delete "$SMPROGRAMS\Frigga Data Center.lnk"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\Frigga Data Center\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\Frigga Data Center\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\Frigga Data Center.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\Frigga Data Center.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr HKCU "Software\${MY_GUID}" "InstallLocation" "$INSTDIR"
SectionEnd
Function FindProcess
nsProcess::_FindProcess "${PRODUCT_NAME}.exe"
;nsProcess::_FindProcess "NoTePad.exe"
Pop $R0
${If} $R0 == 0
MessageBox MB_YESNO "$(RunPrompt)" IDYES label_yes IDNO label_no
${ElseIf} $R0 == 603
Goto run
${EndIf}
label_yes:
nsProcess::_KillProcess "${PRODUCT_NAME}.exe"
;nsProcess::_KillProcess "NoTePad.exe"
Goto run
label_no:
Quit
run:
FunctionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function .onInit
Call setPath
!insertmacro MUI_LANGDLL_DISPLAY
;!insertmacro FindProcess
; Call FindProcess
FunctionEnd
Var isSetpath
Function setPath
ReadRegStr $0 HKCU "Software\${MY_GUID}" "InstallLocation"
ReadRegStr $1 HKLM "SOFTWARE\${MY_GUID}" "InstallLocation"
${If} $0 != ""
; 如果$0不为空,则执行这里的逻辑
StrCpy $INSTDIR "$0"
SetOutPath $INSTDIR
StrCpy $isSetpath "$0"
;MessageBox MB_OK "注册表值为0: $0"
;${ElseIf} $1 != ""
; ; 如果$1不为空,则执行这里的逻辑
;StrCpy $INSTDIR "$1"
;SetOutPath $INSTDIR
;StrCpy $isSetpath "$1"
;MessageBox MB_OK "注册表值为1: $1"
${Else}
; 如果$0为空,则执行这里的逻辑
;MessageBox MB_OK "注册表值为空"
${EndIf}
FunctionEnd
Function mulu
${If} $isSetpath != ""
;禁用浏览按钮
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1001
EnableWindow $0 0
;禁止编辑目录
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1019
EnableWindow $0 0
${Else}
; 如果$0为空,则执行这里的逻辑
;MessageBox MB_OK "注册表值为空"
${EndIf}
FunctionEnd
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\Frigga Data Center.exe"
Delete "$SMPROGRAMS\Frigga Data Center\Uninstall.lnk"
Delete "$SMPROGRAMS\Frigga Data Center\Website.lnk"
Delete "$DESKTOP\Frigga Data Center.lnk"
Delete "$SMPROGRAMS\Frigga Data Center\Frigga Data Center.lnk"
RMDir "$SMPROGRAMS\Frigga Data Center"
RMDir /r $INSTDIR
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
DeleteRegKey HKCU "Software\${MY_GUID}"
DeleteRegKey HKLM "SOFTWARE\${MY_GUID}"
DeleteRegKey HKLM "SOFTWARE\WOW6432Node\${MY_GUID}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function un.onInit
;nsProcess::_FindProcess "NoTePad.exe"
nsProcess::_FindProcess "${PRODUCT_NAME}.exe"
Pop $R0
${If} $R0 == 0
MessageBox MB_YESNO "$(RunPrompt)" IDYES label_yes IDNO label_no
${ElseIf} $R0 == 603
Goto run
${EndIf}
label_yes:
nsProcess::_KillProcess "${PRODUCT_NAME}.exe"
;nsProcess::_KillProcess "NoTePad.exe"
Goto run
label_no:
Quit
run:
!insertmacro MUI_UNGETLANGUAGE
StrCmp $LANGUAGE 2052 ZH_INI EN_INI
EN_INI:
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^ Name) and all its components?" IDYES +2
Abort
;想干啥干啥
Goto END
ZH_INI:
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name)及其所有的组件?" IDYES +2
Abort
END:
FunctionEnd
Function un.onUninstSuccess
HideWindow
StrCmp $LANGUAGE 2052 ZH_INI EN_INI
EN_INI:
;想干啥干啥
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) has been successfully removed from your computer."
Goto END
ZH_INI:
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
END:
FunctionEnd
VIProductVersion "${PRODUCT_VERSION}" ;版本号,格式为 X.X.X.X若使用则本条必须)
VIAddVersionKey "ProductName" "${PRODUCT_NAME}" ;产品名称
VIAddVersionKey "Comments" "${PRODUCT_NAME}" ;备注
VIAddVersionKey "CompanyName" "Frigga" ;公司名称
; VIAddVersionKey "LegalTrademarks" "Test Application is a trademark of Fake company" ;合法商标
VIAddVersionKey "LegalCopyright" "Copyright(C)2023" ;合法版权
VIAddVersionKey "FileDescription" "${PRODUCT_NAME}" ;文件描述(标准信息)
VIAddVersionKey "FileVersion" "${PRODUCT_FILE_VERSION}" ;文件版本
VIAddVersionKey "ProductVersion" "${PRODUCT_FILE_VERSION}" ;产品版本