-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.nsi
458 lines (383 loc) · 14.1 KB
/
setup.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
######################################################################
!define APP_NAME "AudioSharp"
!define COMP_NAME "Stefan 'Heufneutje' Frijters"
!define WEB_SITE "https://github.com/Heufneutje/AudioSharp"
!define VERSION "1.8.2.0"
!define DESCRIPTION "AudioSharp"
!define LICENSE_TXT "LICENSE.txt"
!define INSTALLER_NAME "Release\AudioSharp Setup.exe"
!define MAIN_APP_EXE "AudioSharp.exe"
!define INSTALL_TYPE "SetShellVarContext current"
!define REG_ROOT "HKCU"
!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}"
!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Run AudioSharp"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define REG_START_MENU "Start Menu Folder"
var SM_Folder
######################################################################
VIProductVersion "${VERSION}"
VIAddVersionKey "ProductName" "${APP_NAME}"
VIAddVersionKey "CompanyName" "${COMP_NAME}"
VIAddVersionKey "FileDescription" "${DESCRIPTION}"
VIAddVersionKey "FileVersion" "${VERSION}"
######################################################################
SetCompressor ZLIB
Name "${APP_NAME}"
Caption "${APP_NAME}"
OutFile "${INSTALLER_NAME}"
BrandingText "${APP_NAME}"
XPStyle on
InstallDirRegKey "${REG_ROOT}" "${REG_APP_PATH}" ""
######################################################################
!include "MUI.nsh"
!include x64.nsh
!include LogicLib.nsh
InstallDir "$PROGRAMFILES\AudioSharp"
Function .onInit
${If} ${RunningX64}
SetRegView 64
StrCpy $INSTDIR "$PROGRAMFILES64\AudioSharp"
${EndIf}
Push "UPDATELOCATION" ; push the search string onto the stack
Push ''
Call GetParameterValue
Pop $2
Var /GLOBAL UPDATELOCATION ;
${If} $2 = ''
Messagebox MB_OK|MB_ICONINFORMATION "The AudioSharp update will now be installed."
StrCpy $INSTDIR $2
${EndIf}
StrCpy $UPDATELOCATION $2
FunctionEnd
Function LaunchLink
ExecShell "" "$INSTDIR\AudioSharp.exe"
FunctionEnd
; GetParameterValue
; Chris Morgan<cmorgan@alum.wpi.edu> 5/10/2004
; -Updated 4/7/2005 to add support for retrieving a command line switch
; and additional documentation
;
; Searches the command line input, retrieved using GetParameters, for the
; value of an option given the option name. If no option is found the
; default value is placed on the top of the stack upon function return.
;
; This function can also be used to detect the existence of just a
; command line switch like /OUTPUT Pass the default and "OUTPUT"
; on the stack like normal. An empty return string "" will indicate
; that the switch was found, the default value indicates that
; neither a parameter or switch was found.
;
; Inputs - Top of stack is default if parameter isn't found,
; second in stack is parameter to search for, ex. "OUTPUT"
; Outputs - Top of the stack contains the value of this parameter
; So if the command line contained /OUTPUT=somedirectory, "somedirectory"
; will be on the top of the stack when this function returns
;
; Register usage
;$R0 - default return value if the parameter isn't found
;$R1 - input parameter, for example OUTPUT from the above example
;$R2 - the length of the search, this is the search parameter+2
; as we have '/OUTPUT='
;$R3 - the command line string
;$R4 - result from StrStr calls
;$R5 - search for ' ' or '"'
Function GetParameterValue
Exch $R0 ; get the top of the stack(default parameter) into R0
Exch ; exchange the top of the stack(default) with
; the second in the stack(parameter to search for)
Exch $R1 ; get the top of the stack(search parameter) into $R1
;Preserve on the stack the registers used in this function
Push $R2
Push $R3
Push $R4
Push $R5
Strlen $R2 $R1+2 ; store the length of the search string into R2
Call GetParameters ; get the command line parameters
Pop $R3 ; store the command line string in R3
# search for quoted search string
StrCpy $R5 '"' ; later on we want to search for a open quote
Push $R3 ; push the 'search in' string onto the stack
Push '"/$R1=' ; push the 'search for'
Call StrStr ; search for the quoted parameter value
Pop $R4
StrCpy $R4 $R4 "" 1 ; skip over open quote character, "" means no maxlen
StrCmp $R4 "" "" next ; if we didn't find an empty string go to next
# search for non-quoted search string
StrCpy $R5 ' ' ; later on we want to search for a space since we
; didn't start with an open quote '"' we shouldn't
; look for a close quote '"'
Push $R3 ; push the command line back on the stack for searching
Push '/$R1=' ; search for the non-quoted search string
Call StrStr
Pop $R4
; $R4 now contains the parameter string starting at the search string,
; if it was found
next:
StrCmp $R4 "" check_for_switch ; if we didn't find anything then look for
; usage as a command line switch
# copy the value after /$R1= by using StrCpy with an offset of $R2,
# the length of '/OUTPUT='
StrCpy $R0 $R4 "" $R2 ; copy commandline text beyond parameter into $R0
# search for the next parameter so we can trim this extra text off
Push $R0
Push $R5 ; search for either the first space ' ', or the first
; quote '"'
; if we found '"/output' then we want to find the
; ending ", as in '"/output=somevalue"'
; if we found '/output' then we want to find the first
; space after '/output=somevalue'
Call StrStr ; search for the next parameter
Pop $R4
StrCmp $R4 "" done ; if 'somevalue' is missing, we are done
StrLen $R4 $R4 ; get the length of 'somevalue' so we can copy this
; text into our output buffer
StrCpy $R0 $R0 -$R4 ; using the length of the string beyond the value,
; copy only the value into $R0
goto done ; if we are in the parameter retrieval path skip over
; the check for a command line switch
; See if the parameter was specified as a command line switch, like '/output'
check_for_switch:
Push $R3 ; push the command line back on the stack for searching
Push '/$R1' ; search for the non-quoted search string
Call StrStr
Pop $R4
StrCmp $R4 "" done ; if we didn't find anything then use the default
StrCpy $R0 "" ; otherwise copy in an empty string since we found the
; parameter, just didn't find a value
done:
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0 ; put the value in $R0 at the top of the stack
FunctionEnd
; GetParameters
; input, none
; output, top of stack (replaces, with e.g. whatever)
; modifies no other variables.
Function GetParameters
Push $R0
Push $R1
Push $R2
Push $R3
StrCpy $R2 1
StrLen $R3 $CMDLINE
;Check for quote or space
StrCpy $R0 $CMDLINE $R2
StrCmp $R0 '"' 0 +3
StrCpy $R1 '"'
Goto loop
StrCpy $R1 " "
loop:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 $R1 get
StrCmp $R2 $R3 get
Goto loop
get:
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 " " get
StrCpy $R0 $CMDLINE "" $R2
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!define StrStr "!insertmacro StrStr"
!macro StrStr ResultVar String SubString
Push `${String}`
Push `${SubString}`
Call StrStr
Pop `${ResultVar}`
!macroend
Function StrStr
/*After this point:
------------------------------------------
$R0 = SubString (input)
$R1 = String (input)
$R2 = SubStringLen (temp)
$R3 = StrLen (temp)
$R4 = StartCharPos (temp)
$R5 = TempStr (temp)*/
;Get input from user
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
Push $R4
Push $R5
;Get "String" and "SubString" length
StrLen $R2 $R0
StrLen $R3 $R1
;Start "StartCharPos" counter
StrCpy $R4 0
;Loop until "SubString" is found or "String" reaches its end
${Do}
;Remove everything before and after the searched part ("TempStr")
StrCpy $R5 $R1 $R2 $R4
;Compare "TempStr" with "SubString"
${IfThen} $R5 == $R0 ${|} ${ExitDo} ${|}
;If not "SubString", this could be "String"'s end
${IfThen} $R4 >= $R3 ${|} ${ExitDo} ${|}
;If not, continue the loop
IntOp $R4 $R4 + 1
${Loop}
/*After this point:
------------------------------------------
$R0 = ResultVar (output)*/
;Remove part before "SubString" on "String" (if there has one)
StrCpy $R0 $R1 `` $R4
;Return output to user
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
!insertmacro MUI_PAGE_WELCOME
!ifdef LICENSE_TXT
!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
!endif
!insertmacro MUI_PAGE_DIRECTORY
!ifdef REG_START_MENU
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "AudioSharp"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}"
!insertmacro MUI_PAGE_STARTMENU Application $SM_Folder
!endif
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
######################################################################
Section -MainProgram
${INSTALL_TYPE}
SetOverwrite ifnewer
SetOutPath "$INSTDIR"
File "Release\AudioSharp.Config.dll"
File "Release\AudioSharp.Core.dll"
File "Release\AudioSharp.exe"
File "Release\AudioSharp.exe.config"
File "Release\AudioSharp.GUI.CustomControls.dll"
File "Release\AudioSharp.Translations.dll"
File "Release\AudioSharp.Utils.dll"
File "Release\GlobalHotKey.dll"
File "Release\Hardcodet.Wpf.TaskbarNotification.dll"
File "Release\libmp3lame.32.dll"
File "Release\libmp3lame.64.dll"
File "Release\License.txt"
File "Release\NAudio.dll"
File "Release\NAudio.Lame.dll"
File "Release\Newtonsoft.Json.dll"
File "Release\Xceed.Wpf.AvalonDock.dll"
File "Release\Xceed.Wpf.AvalonDock.Themes.Aero.dll"
File "Release\Xceed.Wpf.AvalonDock.Themes.Metro.dll"
File "Release\Xceed.Wpf.AvalonDock.Themes.VS2010.dll"
File "Release\Xceed.Wpf.DataGrid.dll"
File "Release\Xceed.Wpf.Toolkit.dll"
SectionEnd
######################################################################
Section -Icons_Reg
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\uninstall.exe"
!ifdef REG_START_MENU
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$SM_Folder"
CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
!ifdef WEB_SITE
WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}"
CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url"
!endif
!insertmacro MUI_STARTMENU_WRITE_END
!endif
!ifndef REG_START_MENU
CreateDirectory "$SMPROGRAMS\AudioSharp"
CreateShortCut "$SMPROGRAMS\AudioSharp\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
CreateShortCut "$SMPROGRAMS\AudioSharp\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
!ifdef WEB_SITE
WriteIniStr "$INSTDIR\${APP_NAME} website.url" "InternetShortcut" "URL" "${WEB_SITE}"
CreateShortCut "$SMPROGRAMS\AudioSharp\${APP_NAME} Website.lnk" "$INSTDIR\${APP_NAME} website.url"
!endif
!endif
WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}"
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}"
!ifdef WEB_SITE
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "URLInfoAbout" "${WEB_SITE}"
!endif
${If} ${Silent}
${AndIf} $UPDATELOCATION != ''
Messagebox MB_OK|MB_ICONINFORMATION "The AudioSharp update has been installed."
Call LaunchLink
${EndIf}
SectionEnd
######################################################################
Section Uninstall
${INSTALL_TYPE}
Delete "$INSTDIR\AudioSharp.Config.dll"
Delete "$INSTDIR\AudioSharp.Core.dll"
Delete "$INSTDIR\AudioSharp.exe"
Delete "$INSTDIR\AudioSharp.exe.config"
Delete "$INSTDIR\AudioSharp.GUI.CustomControls.dll"
Delete "$INSTDIR\AudioSharp.Translations.dll"
Delete "$INSTDIR\AudioSharp.Utils.dll"
Delete "$INSTDIR\GlobalHotKey.dll"
Delete "$INSTDIR\Hardcodet.Wpf.TaskbarNotification.dll"
Delete "$INSTDIR\libmp3lame.32.dll"
Delete "$INSTDIR\libmp3lame.64.dll"
Delete "$INSTDIR\License.txt"
Delete "$INSTDIR\NAudio.dll"
Delete "$INSTDIR\NAudio.Lame.dll"
Delete "$INSTDIR\Newtonsoft.Json.dll"
Delete "$INSTDIR\Xceed.Wpf.AvalonDock.dll"
Delete "$INSTDIR\Xceed.Wpf.AvalonDock.Themes.Aero.dll"
Delete "$INSTDIR\Xceed.Wpf.AvalonDock.Themes.Metro.dll"
Delete "$INSTDIR\Xceed.Wpf.AvalonDock.Themes.VS2010.dll"
Delete "$INSTDIR\Xceed.Wpf.DataGrid.dll"
Delete "$INSTDIR\Xceed.Wpf.Toolkit.dll"
Delete "$INSTDIR\uninstall.exe"
!ifdef WEB_SITE
Delete "$INSTDIR\${APP_NAME} website.url"
!endif
RmDir "$INSTDIR"
!ifdef REG_START_MENU
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder
Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk"
!endif
Delete "$DESKTOP\${APP_NAME}.lnk"
RmDir "$SMPROGRAMS\$SM_Folder"
!endif
!ifndef REG_START_MENU
Delete "$SMPROGRAMS\AudioSharp\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\AudioSharp\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
Delete "$SMPROGRAMS\AudioSharp\${APP_NAME} Website.lnk"
!endif
Delete "$DESKTOP\${APP_NAME}.lnk"
Delete "$SMSTARTUP\${APP_NAME}.lnk"
RmDir "$SMPROGRAMS\AudioSharp"
!endif
DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
SectionEnd
######################################################################