-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathmain.nsi
376 lines (307 loc) · 9.3 KB
/
main.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
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "XML.nsh"
!include "nsArray.nsh"
!include "WinMessages.nsh"
!include "FileFunc.nsh"
SetCompressor /SOLID lzma
!define MUI_ICON "Icon.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "bg.bmp"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "gpl-3.0.rtf"
Page custom VersionSelect
!define MUI_PAGE_CUSTOMFUNCTION_PRE PreDirectory
!define MUI_PAGE_CUSTOMFUNCTION_SHOW RetrieveInfo
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\USBHelperLauncher.exe"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show Changelog"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Changelog.txt"
!define MUI_FINISHPAGE_LINK "View USBHelperLauncher on Github!"
!define MUI_FINISHPAGE_LINK_LOCATION "https://github.com/FailedShack/USBHelperLauncher"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
!define VERSION 0.0.1.2
!define ARCHIVE_URL https://archive.org/download/WiiUUSBHelper/
!define ARCHIVE_MIRROR https://dl.nul.sh/WiiUUSBHelper/
!define GITHUB_URL https://api.github.com/repos/FailedShack/USBHelperLauncher/releases/latest
!define GITHUB_MIRROR https://dl.nul.sh/USBHelperLauncher/latest
!define METRICS_URL https://api.nul.sh/metrics
!define UNINST_LOG Uninstall.log
VIProductVersion ${VERSION}
VIAddVersionKey "ProductName" "USBHelperInstaller"
VIAddVersionKey "ProductVersion" ${VERSION}
VIAddVersionKey "LegalCopyright" "Copyright (C) 2019 FailedShack"
VIAddVersionKey "FileDescription" "USBHelperInstaller"
VIAddVersionKey "FileVersion" ${VERSION}
RequestExecutionLevel user
Name "USBHelperLauncher"
OutFile "USBHelperInstaller.exe"
Var Dialog
Var DropDown
Var TempFile
Var Guid
/* Helper Release */
Var HelperVersion
/* Launcher Release */
Var Version
Var Size
Var DownloadUrl
Var ChangeLog
Section Launcher launcher
Push $DownloadUrl
Push 0
Call DownloadTemp
Push $TempFile
Call Unzip
Delete $TempFile
SectionEnd
Section Helper helper
Push "${ARCHIVE_MIRROR}$HelperVersion.zip"
Push "${ARCHIVE_URL}$HelperVersion.zip"
Push 0
Call DownloadTemp
Push $TempFile
Call Unzip
Delete $TempFile
SectionEnd
Section Finish
SetOutPath $INSTDIR
File "Icon.ico"
FileOpen $0 "$INSTDIR\Changelog.txt" w
FileWrite $0 "USBHelperLauncher $Version Changelog:$\r$\n$\r$\n"
FileWrite $0 $ChangeLog
FileClose $0
CreateShortCut "$DESKTOP\Wii U USB Helper.lnk" "$INSTDIR\USBHelperLauncher.exe"
CreateShortCut "$SMPROGRAMS\Wii U USB Helper.lnk" "$INSTDIR\USBHelperLauncher.exe"
Call SendMetrics
FileOpen $0 "$INSTDIR\guid" w
FileWrite $0 $Guid
FileClose $0
${If} ${FileExists} "$LocalAppData\Hikari06"
${OrIf} ${FileExists} "$AppData\USB_HELPER"
${If} ${Cmd} 'MessageBox MB_YESNO|MB_ICONEXCLAMATION "Data from a previous installation has been found.$\r$\n\
Do you wish to delete it?" /SD IDYES IDNO'
RMDir /r "$LocalAppData\Hikari06"
RMDir /r "$AppData\USB_HELPER"
${EndIf}
${EndIf}
WriteUninstaller "$INSTDIR\Uninstall.exe"
StrCpy $0 "Software\Microsoft\Windows\CurrentVersion\Uninstall\USBHelperLauncher"
WriteRegStr HKCU $0 "DisplayName" "USBHelperLauncher"
WriteRegStr HKCU $0 "UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
WriteRegStr HKCU $0 "QuietUninstallString" "$\"$INSTDIR\Uninstall.exe$\" /S"
WriteRegStr HKCU $0 "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKCU $0 "DisplayIcon" "$\"$INSTDIR\Icon.ico$\""
WriteRegStr HKCU $0 "Publisher" "FailedShack"
WriteRegStr HKCU $0 "DisplayVersion" $Version
WriteRegDWORD HKCU $0 "NoModify" 1
WriteRegDWORD HKCU $0 "NoRepair" 1
SectionEnd
Section Uninstall
${IfNot} ${FileExists} "$INSTDIR\${UNINST_LOG}"
MessageBox MB_OK|MB_ICONSTOP "Missing ${UNINST_LOG}. Cannot uninstall."
Quit
${EndIf}
FileOpen $0 "$INSTDIR\guid" r
FileRead $0 $2
FileClose $0
FileOpen $0 "$INSTDIR\${UNINST_LOG}" r
${Do}
ClearErrors
FileRead $0 $1
${If} ${Errors}
${Break}
${EndIf}
StrCpy $1 "$INSTDIR\$1" -2
Delete $1
/* Attempt to remove directories */
${DoUntil} ${Errors}
${GetParent} $1 $1
RMDir $1
${LoopUntil} $1 == $INSTDIR
${Loop}
FileClose $0
Delete "$INSTDIR\guid"
Delete "$INSTDIR\Patched.exe"
Delete "$INSTDIR\conf.json"
Delete "$INSTDIR\Icon.ico"
Delete "$INSTDIR\Changelog.txt"
Delete "$INSTDIR\Uninstall.exe"
Delete "$INSTDIR\${UNINST_LOG}"
RMDir $INSTDIR
Delete "$DESKTOP\Wii U USB Helper.lnk"
Delete "$SMPROGRAMS\Wii U USB Helper.lnk"
RMDir /r "$LocalAppData\Hikari06"
RMDir /r "$AppData\USB_HELPER"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\USBHelperLauncher"
nsJSON::Set /tree metrics /value `{ "Url": "${METRICS_URL}", "Verb": "POST", "DataType": "JSON" }`
nsJSON::Set /tree metrics "Data" "guid" /value `"$2"` /end
nsJSON::Set /tree metrics "Data" "event" /value `"uninstall"` /end
nsJSON::Set /http metrics
SectionEnd
Function VersionSelect
/* Disable input */
Push 0
Call ChangeButtonState
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateComboBox} 0 0 50% 100% ""
Pop $DropDown
/* Load Wii U USB Helper releases */
GetTempFileName $TempFile
Push "${ARCHIVE_MIRROR}WiiUUSBHelper_files.xml"
Push "${ARCHIVE_URL}WiiUUSBHelper_files.xml"
Push 1
Call DownloadTemp
${xml::LoadFile} "$TempFile" $0
${xml::GotoPath} "/files" $0
${xml::FirstChild} "file" $1 $0
${While} $0 == 0
${xml::GetAttribute} "name" $2 $0
${xml::FirstChild} "size" $1 $0
${xml::GetText} $3 $0
${xml::NextSibling} "format" $1 $0
${xml::GetText} $1 $0
${If} $1 S== "ZIP"
StrCpy $2 $2 -4 # Remove extension
IntOp $3 $3 / 1000 # Bytes to KB
nsArray::Set releases /key=$2 $3
${EndIf}
${xml::Parent} $1 $0
${xml::NextSibling} "file" $1 $0
${EndWhile}
${xml::Unload}
/* Sort descending by key */
nsArray::Sort releases 9
nsArray::Length releases
Pop $0
StrCpy $1 0
${DoWhile} $1 < $0
nsArray::Get releases /at=$1
Pop $2
Pop $3 # Don't care about value
${NSD_CB_AddString} $DropDown $2
IntOp $1 $1 + 1
${Loop}
/* Select 0.6.1.653 by default */
StrCpy $HelperVersion "Wii U USB Helper 0.6.1.653"
${NSD_CB_SelectString} $DropDown $HelperVersion
nsArray::Get releases $HelperVersion
Pop $0
SectionSetSize ${helper} $0
${NSD_OnChange} $DropDown OnDropDownChanged
/* Enable input */
Push 1
Call ChangeButtonState
!insertmacro MUI_HEADER_TEXT "Choose Wii U USB Helper Version" "The default selection is recommended for most users."
nsDialogs::Show
FunctionEnd
Function ChangeButtonState
Pop $0
Push $1
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 $0
GetDlgItem $1 $HWNDPARENT 2
EnableWindow $1 $0
GetDlgItem $1 $HWNDPARENT 3
EnableWindow $1 $0
Pop $1
FunctionEnd
Function DownloadTemp
Pop $0
StrCpy $1 0
${DoUntil} ${Errors}
Pop $2
${If} $1 = 0
${If} $0 = 1
inetc::get /silent $2 $TempFile /end
${Else}
inetc::get $2 $TempFile /end
${EndIf}
Pop $3
${If} $3 S== "OK"
StrCpy $1 1
${EndIf}
${EndIf}
${Loop}
${If} $1 = 0
MessageBox MB_OK|MB_ICONSTOP "Could not establish a connection.$\r$\n\
Please check your internet connection and try again.$\r$\n\
Reason: $3"
Quit
${EndIf}
FunctionEnd
Function Unzip
Pop $0
CreateDirectory $INSTDIR
FileOpen $1 "$INSTDIR\${UNINST_LOG}" a
FileSeek $1 0 END
nsisunz::UnzipToStack $0 $INSTDIR
Pop $0
${DoUntil} ${Errors}
Pop $0
FileWrite $1 "$0$\r$\n"
DetailPrint "Extract: $0"
${Loop}
FileClose $1
FunctionEnd
Function OnDropDownChanged
Pop $DropDown
SendMessage $DropDown ${CB_GETCURSEL} 0 0 $0
nsArray::Get releases /at=$0
Pop $HelperVersion
Pop $1
SectionSetSize ${helper} $1
FunctionEnd
Function RetrieveInfo
/* Disable input */
Push 0
Call ChangeButtonState
Push ${GITHUB_MIRROR}
Push ${GITHUB_URL}
Push 1
Call DownloadTemp
nsJSON::Set /file $TempFile
nsJSON::Get "tag_name" /end
Pop $Version
nsJSON::Get "body" /end
Pop $ChangeLog
nsJSON::Get "assets" /index 0 "size" /end
Pop $Size
IntOp $Size $Size / 1000
SectionSetSize ${launcher} $Size
nsJSON::Get "assets" /index 0 "browser_download_url" /end
Pop $DownloadUrl
Delete $TempFile
/* Enable input */
Push 1
Call ChangeButtonState
FunctionEnd
Function SendMetrics
System::Call 'kernel32::GetSystemDefaultLangID() i .r0'
System::Call 'kernel32::GetLocaleInfoA(i 1024, i 0x59, t .r1, i ${NSIS_MAX_STRLEN}) i r0'
System::Call 'kernel32::GetLocaleInfoA(i 1024, i 0x5A, t .r2, i ${NSIS_MAX_STRLEN}) i r0'
StrCpy $0 "$1-$2"
System::Call `ole32::CoCreateGuid(g .r1)`
StrCpy $Guid $1 -1 1
ReadRegStr $2 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" ProductName
${If} $2 == ""
ReadRegStr $2 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" ProductName
${EndIf}
nsJSON::Set /tree metrics /value `{ "Url": "${METRICS_URL}", "Verb": "POST", "DataType": "JSON" }`
nsJSON::Set /tree metrics "Data" "guid" /value `"$Guid"` /end
nsJSON::Set /tree metrics "Data" "event" /value `"install"` /end
nsJSON::Set /tree metrics "Data" "context" /value `"USBHelperInstaller"` /end
nsJSON::Set /tree metrics "Data" "version" /value `"${VERSION}"` /end
nsJSON::Set /tree metrics "Data" "os" /value `"$2"` /end
nsJSON::Set /tree metrics "Data" "locale" /value `"$0"` /end
nsJSON::Set /tree metrics "Data" "products" "USBHelperLauncher" /value `"$Version"` /end
nsJSON::Set /tree metrics "Data" "products" "Wii U USB Helper" /value `"$HelperVersion"` /end
nsJSON::Set /http metrics
FunctionEnd
Function PreDirectory
StrCpy $INSTDIR "$AppData\USBHelperLauncher"
FunctionEnd