-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathptracker.nsh.in
276 lines (248 loc) · 9.67 KB
/
ptracker.nsh.in
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
Unicode True
!include x64.nsh
!include keyvalue.nsh
!define StrRep "!insertmacro StrRep"
!macro StrRep output string old new
Push `${string}`
Push `${old}`
Push `${new}`
Call StrRep
Pop ${output}
!macroend
!macro Func_StrRep un
Function StrRep
Exch $R2 ;new
Exch 1
Exch $R1 ;old
Exch 2
Exch $R0 ;string
Push $R3
Push $R4
Push $R5
Push $R6
Push $R7
Push $R8
Push $R9
StrCpy $R3 0
StrLen $R4 $R1
StrLen $R6 $R0
StrLen $R9 $R2
loop:
StrCpy $R5 $R0 $R4 $R3
StrCmp $R5 $R1 found
StrCmp $R3 $R6 done
IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character
Goto loop
found:
StrCpy $R5 $R0 $R3
IntOp $R8 $R3 + $R4
StrCpy $R7 $R0 "" $R8
StrCpy $R0 $R5$R2$R7
StrLen $R6 $R0
IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string
Goto loop
done:
Pop $R9
Pop $R8
Pop $R7
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Push $R0
Push $R1
Pop $R0
Pop $R1
Pop $R0
Pop $R2
Exch $R1
FunctionEnd
!macroend
!insertmacro Func_StrRep ""
Name "ptracker"
OutFile "%(target)s"
DirText "Choose the installation directory of Assetto Corsa!"
ShowInstDetails show
InstallDir "C:\Program Files (x86)\Steam\SteamApps\common\assettocorsa"
Var steamPath # Possible Steam install path
Var steamApps # steamapps directory
Var steamLibrariesVDF # path of libraryfolders.vdf
Var steamLibraryNum # libraryfolders.vdf has a bunch of numeric keys, starting at 1
Var steamLibraryPath # Additional Steam Library directory
Var acPath # Possible Assetto Corsa directory
Var acManifest # Steam's manifest file for AC in steamapps
Function TryACPath
# This can be called directly after reading registry
# so do the slash conversion here too
${StrRep} $steamPath $steamPath "/" "\"
# using a global label here doesn't work because the
# calling function is still returned to afterwards
IfFileExists "$acPath\AssettoCorsa.exe" end
SetErrors
end:
FunctionEnd
Function TrySteamApps
# First try proper, through manifest
StrCpy $acManifest "$steamApps\appmanifest_244210.acf"
IfFileExists $acManifest 0 manifest_error
${ReadVDFStr} $acPath $acManifest "AppState>installdir"
IfErrors manifest_error
StrCpy $acPath "$steamApps\common\$acPath"
Call TryACPath
IfErrors manifest_error end
manifest_error:
# Manifest not found or corrupt, try the standard
StrCpy $acPath "$steamApps\common\assettocorsa"
Call TryACPath
# no need to check error here, our caller will
end:
FunctionEnd
Function TrySteamPath
# Some registry keys have forward slashes for path
${StrRep} $steamPath $steamPath "/" "\"
# first check whether the default library has AC
StrCpy $steamApps "$steamPath\steamapps"
Call TrySteamApps
IfErrors 0 end
# default library doesn't have it, try the other libraries
StrCpy $steamLibrariesVDF "$steamPath\steamapps\libraryfolders.vdf"
IfFileExists $steamLibrariesVDF 0 error
StrCpy $steamLibraryNum 1
loop:
${ReadVDFStr} $steamLibraryPath $steamLibrariesVDF "LibraryFolders>$steamLibraryNum"
IfErrors error
StrCpy $steamApps "$steamLibraryPath\steamapps"
Call TrySteamApps
IfErrors 0 end
IntOp $steamLibraryNum $steamLibraryNum + 1
Goto loop
error:
SetErrors
end:
FunctionEnd
Function .onInit
# try to autodetect the location of the Assetto Corsa game path
# first, try the 3 Steam path registry keys
ReadRegStr $steamPath HKCU SOFTWARE\Valve\Steam steampath
Call TrySteamPath
IfErrors 0 acPathFound
ReadRegStr $steamPath HKLM SOFTWARE\WOW6432Node\Valve\Steam InstallPath
Call TrySteamPath
IfErrors 0 acPathFound
ReadRegStr $steamPath HKLM SOFTWARE\Valve\Steam InstallPath
Call TrySteamPath
IfErrors 0 acPathFound
# second, try uninstall registry keys
ReadRegStr $acPath HKLM "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 244210" InstallLocation
Call TryACPath
IfErrors 0 acPathFound
ReadRegStr $acPath HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 244210" InstallLocation
Call TryACPath
IfErrors 0 acPathFound
# if none of those worked, try the plausible default
StrCpy $acPath "C:\Program Files (x86)\Steam\SteamApps\common\assettocorsa"
acPathFound:
StrCpy $INSTDIR $acPath
FunctionEnd
Function .onVerifyInstDir
; check for sane installation directory
IfFileExists $INSTDIR\AssettoCorsa.exe PathGood
Abort "Must be installed in Assetto Corsa game directory."
PathGood:
FunctionEnd
Section "Installer Section"
SetOutPath $INSTDIR
; if ptracker already is installed, we remove it
IfFileExists $INSTDIR\apps\python\ptracker\*.* 0 uninst_complete
MessageBox MB_OKCANCEL "ptracker is already installed and will be removed." IDOK uninst IDCANCEL abort
uninst:
IfFileExists $INSTDIR\apps\python\ptracker\ptracker.nsh.in devmode usermode
devmode:
; devmode: assume we have a link
ExecWait 'cmd /c rmdir "$INSTDIR\apps\python\ptracker"' ; for the development system, try to rmdir before recursive rm
IfErrors failrmdir goodrmdir
failrmdir:
MessageBox MB_OK "Could not rmdir ptracker Stopping."
Abort "Could not rmdir ptracker Stopping."
usermode:
; usermode: recursive delete
RMDir /r $INSTDIR\apps\python\ptracker
goodrmdir:
IfErrors uninst_complete ; ignore errors
Goto uninst_complete
abort:
Abort "Old version needs to be removed before installation. Aborting."
uninst_complete:
; following statements will be expanded by the release script
%(DirStatements)s
%(FileStatements)s
DetailPrint "Check if ptracker.exe can be started..."
ExecWait '"$INSTDIR\apps\python\ptracker\dist\ptracker.exe" /check_install' $0
IfErrors exe_fail exe_good
exe_fail:
MessageBox MB_OK "Could not execute ptracker.exe. Maybe your virus scanner is blocking it? Try to add an exception. Aborting."
Abort "Could not execute ptracker.exe. Maybe your virus scanner is blocking it? Try to add an exception. Aborting."
exe_good:
IntCmp $0 7 ptok ptnok ptnok
ptok:
goto instok
ptnok:
MessageBox MB_OK "ptracker.exe had a problem and could not return seccessfully. Aborting."
Abort "ptracker.exe had a problem and could not return seccessfully. Aborting."
instok:
${If} ${RunningX64}
; 64 bits
; check if VS 2015 is installed
ReadRegDWORD $0 HKLM Software\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64 Installed
IfErrors vc2015nok
IntCmp $0 1 vc2015ok vc2015nok vc2015nok
vc2015nok:
DetailPrint "VC Redist 2015 is not installed on this system."
MessageBox MB_YESNO "It seems you do not have the Microsoft Redistributables 2015 installed on your system. These are needed for setup sharing. Download and install them now?" IDYES inst2015 IDNO vc2015ok
inst2015:
DetailPrint "Downloading VC Redist 2015"
NSISdl::download https://aka.ms/vs/16/release/vc_redist.x64.exe vc_redist.x64.exe
IfErrors download_failed download_good
download_failed:
MessageBox MB_OK "The download failed. You will not be able to share setups with ptracker. Go to http://n-e-y-s.de/ptracker_doc and check how to manually install the VS 2015 Redistributables."
goto theend
download_good:
ExecWait '"vc_redist.x64.exe"'
IfErrors exec_failed exec_good
exec_failed:
MessageBox MB_OK "Cannot execute the downloaded installer for VS 2015 redistributables. Go to http://n-e-y-s.de/ptracker_doc and check how to manually install the VS 2015 Redistributables."
goto theend
exec_good:
goto theend
vc2015ok:
DetailPrint "VC Redist 2015 installation skipped"
${Else}
; 32 bits
; check if VS 2015 is installed
ReadRegDWORD $0 HKLM Software\Microsoft\VisualStudio\14.0\VC\Runtimes\x32 Installed
IfErrors vc2015nok32
IntCmp $0 1 vc2015ok32 vc2015nok32 vc2015nok32
vc2015nok32:
DetailPrint "VC Redist 2015 is not installed on this system."
MessageBox MB_YESNO "It seems you do not have the Microsoft Redistributables 2015 installed on your system. These are needed for setup sharing. Download and install them now?" IDYES inst201532 IDNO vc2015ok32
inst201532:
DetailPrint "Downloading VC Redist 2015"
NSISdl::download https://aka.ms/vs/16/release/vc_redist.x86.exe vc_redist.x86.exe
IfErrors download_failed32 download_good32
download_failed32:
MessageBox MB_OK "The download failed. You will not be able to share setups with ptracker. Go to http://n-e-y-s.de/ptracker_doc and check how to manually install the VS 2015 Redistributables."
goto theend
download_good32:
ExecWait '"vc_redist.x86.exe"'
IfErrors exec_failed32 exec_good32
exec_failed32:
MessageBox MB_OK "Cannot execute the downloaded installer for VS 2015 redistributables. Go to http://n-e-y-s.de/ptracker_doc and check how to manually install the VS 2015 Redistributables."
goto theend
exec_good32:
goto theend
vc2015ok32:
DetailPrint "VC Redist 2015 installation skipped"
${EndIf}
theend:
MessageBox MB_OK "Successfully installed ptracker."
SectionEnd