Skip to content

Commit ed6b43a

Browse files
committed
Refactored installer script: Removed some gotos, simplified VC redist check
1 parent 34da81a commit ed6b43a

File tree

1 file changed

+79
-101
lines changed

1 file changed

+79
-101
lines changed

Shared/installer/nightly.nsi

Lines changed: 79 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Var CreateSMShortcuts
2020
Var CreateDesktopIcon
2121
Var RegisterProtocol
2222
Var AddToGameExplorer
23-
Var RedistVC12Installed
2423
Var ExeMD5
2524
Var PatchInstalled
2625
Var DEFAULT_INSTDIR
@@ -248,19 +247,6 @@ Function .onInit
248247
${LogText} "${PRODUCT_VERSION}"
249248
${LogText} "Function begin - .onInit"
250249

251-
; Check if we must install the Microsoft Visual Studio 2013 redistributable
252-
ClearErrors
253-
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
254-
StrCmp "$0" "1" DontInstallVC12Redist
255-
StrCpy $RedistVC12Installed "0"
256-
${LogText} " VS2013 runtime not installed"
257-
Goto PostVC12Check
258-
DontInstallVC12Redist:
259-
StrCpy $RedistVC12Installed "1"
260-
${LogText} " VS2013 runtime already installed"
261-
PostVC12Check:
262-
263-
264250
; Try to find previously saved MTA:SA install path
265251
ReadRegStr $Install_Dir HKLM "SOFTWARE\Multi Theft Auto: San Andreas All\${0.0}" "Last Install Location"
266252
${If} $Install_Dir == ""
@@ -465,11 +451,7 @@ SectionGroup /e "$(INST_SEC_CLIENT)" SECGCLIENT
465451
SectionIn 1 RO ; section is required
466452
${LogText} "Section begin - CLIENT CORE"
467453

468-
StrCmp "$RedistVC12Installed" "1" DontInstallRedistVC12
469-
Call InstallVC12Redistributable
470-
StrCmp "$RedistVC12Installed" "1" DontInstallRedistVC12
471-
Abort
472-
DontInstallRedistVC12:
454+
Call UpdateVCRedistributables
473455

474456
SetShellVarContext all
475457

@@ -809,11 +791,7 @@ SectionGroup /e "$(INST_SEC_SERVER)" SECGSERVER
809791
${LogText} "Section begin - SERVER CORE"
810792
SectionIn 1 2 RO ; section is required
811793

812-
StrCmp "$RedistVC12Installed" "1" DontInstallRedistVC12
813-
Call InstallVC12Redistributable
814-
StrCmp "$RedistVC12Installed" "1" DontInstallRedistVC12
815-
Abort
816-
DontInstallRedistVC12:
794+
Call UpdateVCRedistributables
817795

818796
SetOutPath "$INSTDIR\server"
819797
SetOverwrite on
@@ -1143,6 +1121,17 @@ Function SkipDirectoryPage
11431121
FunctionEnd
11441122

11451123

1124+
;====================================================================================
1125+
; Download and install Microsoft Visual Studio redistributables if required
1126+
;====================================================================================
1127+
Function UpdateVCRedistributables
1128+
Call IsVC12RedistributableInstalled
1129+
${If} $0 != "1"
1130+
Call InstallVC12Redistributable
1131+
${EndIf}
1132+
FunctionEnd
1133+
1134+
11461135
;====================================================================================
11471136
; Download and install Microsoft Visual Studio 2013 redistributable
11481137
;====================================================================================
@@ -1159,43 +1148,39 @@ Function InstallVC12Redistributable
11591148
StrCpy $REDISTVC12 "$TEMP\vcredist12_x86.exe"
11601149
NSISdl::download "http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe" $REDISTVC12
11611150
Pop $0
1162-
StrCmp "$0" "success" DownloadSuccessful
1163-
1164-
DetailPrint "* Download of Microsoft Visual Studio 2013 redistributable failed:"
1165-
DetailPrint "* $0"
1166-
DetailPrint "* Installation continuing anyway"
1167-
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR1)"
1168-
Goto InstallEnd
1169-
1170-
DownloadSuccessful:
1171-
; /passive = 'This option will display a progress dialog (but requires no user interaction) and perform an install.'
1172-
; /quiet = 'This option will suppress all UI and perform an install.'
1173-
ExecWait '"$REDISTVC12" /quiet'
1174-
ClearErrors
1175-
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
1176-
StrCmp "$0" "1" 0 VC12RedistInstallFailed
1177-
1178-
StrCpy $RedistVC12Installed "1"
1179-
Goto InstallEnd
1180-
1181-
VC12RedistInstallFailed:
1182-
StrCpy $RedistVC12Installed "0"
1183-
DetailPrint "* Some error occured installing Microsoft Visual Studio 2013 redistributable"
1184-
DetailPrint "* It is required in order to run Multi Theft Auto : San Andreas"
1185-
DetailPrint "* Installation continuing anyway"
1186-
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR2)"
1187-
1188-
1189-
InstallEnd:
11901151

1191-
StrCmp "$RedistVC12Installed" "1" InstallEnd2
1192-
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR3)"
1193-
StrCpy $RedistVC12Installed "1"
1152+
${If} $0 != "success"
1153+
DetailPrint "* Download of Microsoft Visual Studio 2013 redistributable failed:"
1154+
DetailPrint "* $0"
1155+
DetailPrint "* Installation continuing anyway"
1156+
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR3)"
1157+
${Else}
1158+
; /passive = 'This option will display a progress dialog (but requires no user interaction) and perform an install.'
1159+
; /quiet = 'This option will suppress all UI and perform an install.'
1160+
ExecWait '"$REDISTVC12" /quiet'
1161+
Call IsVC12RedistributableInstalled
1162+
${If} $0 != "1"
1163+
DetailPrint "* Some error occured installing Microsoft Visual Studio 2013 redistributable"
1164+
DetailPrint "* It is required in order to run Multi Theft Auto : San Andreas"
1165+
DetailPrint "* Installation continuing anyway"
1166+
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR2)"
1167+
MessageBox MB_ICONSTOP "$(MSGBOX_VC12RED_ERROR3)"
1168+
${EndIf}
1169+
${EndIf}
11941170

1195-
InstallEnd2:
11961171
${LogText} "Function end - InstallVC12Redistributable"
11971172
FunctionEnd
11981173

1174+
;----------------------------------------
1175+
; Out $0 = result ("1" = yes, "0" = no)
1176+
Function IsVC12RedistributableInstalled
1177+
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\DevDiv\vc\Servicing\12.0\RuntimeMinimum" "Install"
1178+
${If} $0 != "1"
1179+
StrCpy $0 "0"
1180+
${EndIf}
1181+
FunctionEnd
1182+
1183+
11991184
;====================================================================================
12001185
; Patcher related functions
12011186
;====================================================================================
@@ -1209,36 +1194,29 @@ Function InstallPatch
12091194
StrCpy $PATCHFILE "$TEMP\$ExeMD5.GTASAPatch"
12101195
NSISdl::download "http://mirror.multitheftauto.com/gdata/$ExeMD5.GTASAPatch" $PATCHFILE
12111196
Pop $0
1212-
StrCmp "$0" "success" PatchDownloadSuccessful
1213-
1214-
DetailPrint "* Download of patch file failed:"
1215-
DetailPrint "* $0"
1216-
DetailPrint "* Installation continuing anyway"
1217-
MessageBox MB_ICONSTOP "$(MSGBOX_PATCH_FAIL1)"
1218-
StrCpy $PatchInstalled "0"
1219-
Goto FinishPatch
1220-
1221-
PatchDownloadSuccessful:
1222-
DetailPrint "Patch download successful. Installing patch..."
1223-
vpatch::vpatchfile "$PATCHFILE" "$GTA_DIR\gta_sa.exe.bak" "$GTA_DIR\gta_sa.exe"
1224-
Pop $R0
1225-
1226-
${If} $R0 == "OK"
1227-
StrCpy $PatchInstalled "1"
1228-
Goto FinishPatch
1229-
${ElseIf} $R0 == "OK, new version already installed"
1230-
StrCpy $PatchInstalled "1"
1231-
Goto FinishPatch
1197+
${If} $0 != "success"
1198+
DetailPrint "* Download of patch file failed:"
1199+
DetailPrint "* $0"
1200+
DetailPrint "* Installation continuing anyway"
1201+
MessageBox MB_ICONSTOP "$(MSGBOX_PATCH_FAIL1)"
1202+
StrCpy $PatchInstalled "0"
1203+
${Else}
1204+
DetailPrint "Patch download successful. Installing patch..."
1205+
vpatch::vpatchfile "$PATCHFILE" "$GTA_DIR\gta_sa.exe.bak" "$GTA_DIR\gta_sa.exe"
1206+
Pop $R0
1207+
${If} $R0 == "OK"
1208+
StrCpy $PatchInstalled "1"
1209+
${ElseIf} $R0 == "OK, new version already installed"
1210+
StrCpy $PatchInstalled "1"
1211+
${Else}
1212+
StrCpy $PatchInstalled "0"
1213+
DetailPrint "* Some error occured installing the patch for Grand Theft Auto: San Andreas:"
1214+
DetailPrint "* $R0"
1215+
DetailPrint "* It is required in order to run Multi Theft Auto : San Andreas"
1216+
DetailPrint "* Installation continuing anyway"
1217+
MessageBox MB_ICONSTOP MSGBOX_PATCH_FAIL2
1218+
${EndIf}
12321219
${EndIf}
1233-
1234-
DetailPrint "* Some error occured installing the patch for Grand Theft Auto: San Andreas:"
1235-
DetailPrint "* $R0"
1236-
DetailPrint "* It is required in order to run Multi Theft Auto : San Andreas"
1237-
DetailPrint "* Installation continuing anyway"
1238-
MessageBox MB_ICONSTOP MSGBOX_PATCH_FAIL2
1239-
StrCpy $PatchInstalled "0"
1240-
1241-
FinishPatch:
12421220
${LogText} "Function end - InstallPatch"
12431221
FunctionEnd
12441222

@@ -1254,22 +1232,22 @@ LangString UAC_RIGHTS4 ${LANG_ENGLISH} "Unable to elevate"
12541232
!insertmacro UAC_RunElevated
12551233
#MessageBox mb_TopMost "0=$0 1=$1 2=$2 3=$3"
12561234
${Switch} $0
1257-
${Case} 0
1258-
${IfThen} $1 = 1 ${|} Quit ${|} ;we are the outer process, the inner process has done its work, we are done
1259-
${IfThen} $3 <> 0 ${|} ${Break} ${|} ;we are admin, let the show go on
1260-
${If} $1 = 3 ;RunAs completed successfully, but with a non-admin user
1261-
MessageBox mb_IconExclamation|mb_TopMost|mb_SetForeground "${AdminError}" /SD IDNO IDOK uac_tryagain IDNO 0
1262-
${EndIf}
1263-
;fall-through and die
1264-
${Case} 1223
1265-
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "${AdminError}"
1266-
Quit
1267-
${Case} 1062
1268-
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(UAC_RIGHTS3)"
1269-
Quit
1270-
${Default}
1271-
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(UAC_RIGHTS4), error $0"
1272-
Quit
1235+
${Case} 0
1236+
${IfThen} $1 = 1 ${|} Quit ${|} ; we are the outer process, the inner process has done its work, we are done
1237+
${IfThen} $3 <> 0 ${|} ${Break} ${|} ; we are admin, let the show go on
1238+
${If} $1 = 3 ; RunAs completed successfully, but with a non-admin user
1239+
MessageBox mb_IconExclamation|mb_TopMost|mb_SetForeground "${AdminError}" /SD IDNO IDOK uac_tryagain IDNO 0
1240+
${EndIf}
1241+
;fall-through and die
1242+
${Case} 1223
1243+
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "${AdminError}"
1244+
Quit
1245+
${Case} 1062
1246+
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(UAC_RIGHTS3)"
1247+
Quit
1248+
${Default}
1249+
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "$(UAC_RIGHTS4), error $0"
1250+
Quit
12731251
${EndSwitch}
12741252
!macroend
12751253

0 commit comments

Comments
 (0)