Skip to content

Commit df2e480

Browse files
committed
Move all Download URL in 1 spot
1 parent eafa673 commit df2e480

File tree

2 files changed

+101
-40
lines changed

2 files changed

+101
-40
lines changed

windows/web/dlmacro.nsh

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,71 @@
1-
; Macro: dlFiles
2-
; Downloads a file from a specified URL, saves it locally, and unzips it to a target directory.
1+
; Macro: dlFile
2+
; Downloads a file from a URL or extracts a local file to ${SLIMETEMP}, based on source_type.
33
; Parameters:
4-
; name - Display name of the file (for user messages)
5-
; version - Version string (for user messages)
6-
; url - URL to download the file from
7-
; local_file - Name to save the downloaded file as (in temp directory)
8-
; local_dir - Directory to unzip the file into (relative to temp directory)
9-
#
10-
!macro dlFiles name version url local_file local_dir
4+
; source_type - "url" to download, "local" to extract from local file (embedded in installer)
5+
; name - Display name of the file (for user messages)
6+
; version - Version string (for user messages)
7+
; url_or_path - URL to download from (if source_type is "url"), or local file path (if "local")
8+
; local_file - File name to save as in ${SLIMETEMP} (e.g., "archive.zip")
9+
; Notes:
10+
; - If source_type is "url", uses NScurl::http with /CANCEL and /RESUME; pops status text into $0 ("OK" on success)
11+
; - If source_type is "local", embeds the file at compile time and extracts it to ${SLIMETEMP} at install time
12+
; - Call unzipFile separately to extract the downloaded or copied archive
13+
; Example:
14+
; !insertmacro dlFile "url" "Java JRE" "17.0.15+6" "https://example.com/jre.zip" "jre.zip"
15+
; !insertmacro dlFile "local" "Java JRE" "17.0.15+6" "assets\\jre.zip" "jre.zip"
16+
!macro dlFile source_type name version url_or_path local_file
17+
!if "${source_type}" == "url"
18+
DetailPrint "Downloading ${name} ${version}..."
19+
NScurl::http GET "${url_or_path}" "${SLIMETEMP}\${local_file}" /CANCEL /RESUME /END
20+
Pop $0 ; Status text ("OK" for success)
21+
${If} $0 != "OK"
22+
Abort "Failed to download ${name} ${version}. Reason: $0."
23+
${EndIf}
24+
DetailPrint "Downloaded!"
25+
!else
26+
!if "${source_type}" == "local"
27+
DetailPrint "Using bundled ${name} ${version}..."
28+
Push $0
29+
StrCpy $0 $OUTDIR
30+
CreateDirectory "${SLIMETEMP}"
31+
SetOutPath "${SLIMETEMP}"
32+
File "/oname=${local_file}" "${url_or_path}"
33+
SetOutPath $0
34+
Pop $0
35+
IfFileExists "${SLIMETEMP}\${local_file}" +2 0
36+
Abort "Failed to place bundled ${name} ${version} at ${SLIMETEMP}\\${local_file}."
37+
DetailPrint "Bundled file ready: ${SLIMETEMP}\\${local_file}"
38+
!else
39+
Abort "dlFile: Unknown source_type '${source_type}'. Use 'url' or 'local'."
40+
!endif
41+
!endif
42+
!macroend
1143

12-
DetailPrint "Downloading ${name} ${version}..."
13-
NScurl::http GET "${url}" "${SLIMETEMP}\${local_file}" /CANCEL /RESUME /END
14-
Pop $0 ; Status text ("OK" for success)
15-
${If} $0 != "OK"
16-
Abort "Failed to download ${name} ${version}. Reason: $0."
17-
${EndIf}
18-
DetailPrint "Downloaded!"
44+
45+
46+
; Macro: unzipFile
47+
; Extracts a ZIP archive from the temporary installer directory into a target subdirectory.
48+
; Parameters:
49+
; name - Friendly display name shown in the log (e.g., "Java JRE")
50+
; version - Version label shown in the log (e.g., "17.0.15+6" or "latest")
51+
; local_file - ZIP file name located under ${SLIMETEMP} (e.g., "archive.zip")
52+
; local_dir - Destination directory name to extract into
53+
; (e.g., "${SLIMETEMP}\OpenJDK\" -> extracts to "${SLIMETEMP}\OpenJDK\...")
54+
; Behavior:
55+
; - Logs start/end messages with DetailPrint
56+
; - Calls Nsisunz plugin to unzip: nsisunz::Unzip "${local_file}" "${local_dir}"
57+
; - Pops plugin return value into $0 (status depends on plugin build)
58+
; Requirements:
59+
; - ${SLIMETEMP} must be defined and writable
60+
; - Nsisunz plugin must be available via !AddPluginDir
61+
; Notes:
62+
; - This macro does not validate the unzip result; add checks after calling if needed.
63+
; Example:
64+
; !insertmacro unzipFile "Java JRE" "${JREVersion}" "${JREDownloadedFileZip}" "OpenJDK"
65+
!macro unzipFile name version local_file local_dir
1966

2067
DetailPrint "Unzipping ${name} ${version} to installation folder...."
21-
nsisunz::Unzip "${SLIMETEMP}\${local_file}" "${SLIMETEMP}\${local_dir}\"
68+
nsisunz::Unzip "${SLIMETEMP}\${local_file}" "${local_dir}"
2269
Pop $0
2370
DetailPrint "Unzipping finished with $0."
2471

windows/web/slimevr_web_installer.nsi

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,36 @@ Unicode True
3131
!define MUI_HEADERIMAGE_RIGHT
3232
!define SLIMETEMP "$TEMP\SlimeVRInstaller"
3333

34+
# Define all download URLs and versions here for easy editing
35+
!define MVCVersion ""
36+
!define MVCURLType "url" ; "url" or "local"
37+
!define MVCDLURL "https://aka.ms/vs/17/release/vc_redist.x64.exe"
38+
!define MVCDLFileZip "vc_redist.x64.exe"
39+
40+
!define WV2Version ""
41+
!define WV2URLType "url" ; "url" or "local"
42+
!define WV2DLURL "https://go.microsoft.com/fwlink/p/?LinkId=2124703"
43+
!define WV2DLFileZip "MicrosoftEdgeWebView2RuntimeInstaller.exe"
3444
# Define the Java Version Strings and to Check (JRE\relase -> JAVA_RUNTIME_VERSION=)
3545
!define JREVersion "17.0.15+6"
36-
!define JREDownloadURL "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.15%2B6/OpenJDK17U-jre_x64_windows_hotspot_17.0.15_6.zip"
37-
!define JREDownloadedFileZip "OpenJDK17U-jre_x64_windows_hotspot_17.0.15_6.zip"
46+
!define JREURLType "url" ; "url" or "local"
47+
!define JREDLURL "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.15%2B6/OpenJDK17U-jre_x64_windows_hotspot_17.0.15_6.zip"
48+
!define JREDLFileZip "OpenJDK17U-jre_x64_windows_hotspot_17.0.15_6.zip"
3849

3950
!define SVRServerVersion "latest"
40-
!define SVRServerDownloadURL "https://github.com/SlimeVR/SlimeVR-Server/releases/latest/download/SlimeVR-win64.zip"
41-
!define SVRServerDownloadedFileZip "SlimeVR-Server-latest.zip"
51+
!define SVRServerURLType "url" ; "url" or "local"
52+
!define SVRServerDLURL "https://github.com/SlimeVR/SlimeVR-Server/releases/latest/download/SlimeVR-win64.zip"
53+
!define SVRServerDLFileZip "SlimeVR-Server-latest.zip"
4254

4355
!define SVRDriverVersion "latest"
44-
!define SVRDriverDownloadURL "https://github.com/SlimeVR/SlimeVR-OpenVR-Driver/releases/latest/download/slimevr-openvr-driver-win64.zip"
45-
!define SVRDriverDownloadedFileZip "slimevr-openvr-driver-win64.zip"
56+
!define SVRDriverURLType "url" ; "url" or "local"
57+
!define SVRDriverDLURL "https://github.com/SlimeVR/SlimeVR-OpenVR-Driver/releases/latest/download/slimevr-openvr-driver-win64.zip"
58+
!define SVRDriverDLFileZip "slimevr-openvr-driver-win64.zip"
4659

4760
!define SVRFeederVersion "latest"
48-
!define SVRFeederDownloadURL "https://github.com/SlimeVR/SlimeVR-Feeder-App/releases/latest/download/SlimeVR-Feeder-App-win64.zip"
49-
!define SVRFeederDownloadedFileZip "SlimeVR-Feeder-App-latest.zip"
61+
!define SVRFeederURLType "url" ; "url" or "local"
62+
!define SVRFeederDLURL "https://github.com/SlimeVR/SlimeVR-Feeder-App/releases/latest/download/SlimeVR-Feeder-App-win64.zip"
63+
!define SVRFeederDLFileZip "SlimeVR-Feeder-App-latest.zip"
5064

5165
Var JREneedInstall
5266
Var /GLOBAL SteamVRResult
@@ -424,7 +438,8 @@ Section "SlimeVR Server" SEC_SERVER
424438

425439
SetOutPath $INSTDIR
426440

427-
!insertmacro dlFiles "SlimeVR Server" "${SVRServerVersion}" "${SVRServerDownloadURL}" "${SVRServerDownloadedFileZip}" "SlimeVR"
441+
!insertmacro dlFile "${SVRServerURLType}" "SlimeVR Server" "${SVRServerVersion}" "${SVRServerDLURL}" "${SVRServerDLFileZip}"
442+
!insertmacro unzipFile "SlimeVR Server" "${SVRServerVersion}" "${SLIMETEMP}\${SVRServerDLFileZip}" "SlimeVR"
428443

429444
${If} $SELECTED_INSTALLER_ACTION == "update"
430445
Delete "$INSTDIR\slimevr-ui.exe"
@@ -448,10 +463,9 @@ SectionEnd
448463

449464
Section "Webview2" SEC_WEBVIEW
450465
SectionIn RO
451-
452466
# Read Only protects it from Installing when it is not needed
453-
DetailPrint "Downloading webview2!"
454-
NScurl::http GET "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "${SLIMETEMP}\MicrosoftEdgeWebView2RuntimeInstaller.exe" /CANCEL /RESUME /END
467+
468+
!insertmacro dlFile "${WV2URLType}" "webview2" "${WV2Version}" "${WV2DLURL}" "${WV2DLFileZip}"
455469

456470
DetailPrint "Installing webview2!"
457471
nsExec::ExecToLog '"${SLIMETEMP}\MicrosoftEdgeWebView2RuntimeInstaller.exe" /silent /install' $0
@@ -465,8 +479,9 @@ SectionEnd
465479

466480
Section "Java JRE" SEC_JRE
467481
SectionIn RO
468-
469-
!insertmacro dlFiles "Java JRE" "${JREVersion}" "${JREDownloadURL}" "${JREDownloadedFileZip}" "OpenJDK"
482+
483+
!insertmacro dlFile "${JREURLType}" "Java JRE" "${JREVersion}" "${JREDLURL}" "${JREDLFileZip}"
484+
!insertmacro unzipFile "Java JRE" "${JREVersion}" "${SLIMETEMP}\${JREDLFileZip}" "OpenJDK"
470485

471486
# Make sure to delete all files on a update from jre, so if there is a new version no old files are left.
472487
IfFileExists "$INSTDIR\jre" 0 SEC_JRE_DIRNOTFOUND
@@ -488,7 +503,8 @@ SectionEnd
488503
Section "SteamVR Driver" SEC_VRDRIVER
489504
SetOutPath $INSTDIR
490505

491-
!insertmacro dlFiles "SteamVR Driver" "${SVRDriverVersion}" "${SVRDriverDownloadURL}" "${SVRDriverDownloadedFileZip}" "slimevr-openvr-driver-win64"
506+
!insertmacro dlFile "${SVRDriverURLType}" "SteamVR Driver" "${SVRDriverVersion}" "${SVRDriverDLURL}" "${SVRDriverDLFileZip}"
507+
!insertmacro unzipFile "SteamVR Driver" "${SVRDriverVersion}" "${SLIMETEMP}\${SVRDriverDLFileZip}" "slimevr-openvr-driver-win64"
492508

493509
# Include SteamVR powershell script to register/unregister driver
494510
File "steamvr.ps1"
@@ -512,7 +528,9 @@ SectionEnd
512528
Section "SlimeVR Feeder App" SEC_FEEDER_APP
513529
SetOutPath $INSTDIR
514530

515-
!insertmacro dlFiles "SlimeVR Feeder App" "${SVRFeederVersion}" "${SVRFeederDownloadURL}" "${SVRFeederDownloadedFileZip}" ""
531+
!insertmacro dlFile "${SVRFeederURLType}" "SlimeVR Feeder App" "${SVRFeederVersion}" "${SVRFeederDLURL}" "${SVRFeederDLFileZip}"
532+
# The zip contains a folder named SlimeVR-Feeder-App-win64
533+
!insertmacro unzipFile "SlimeVR Feeder App" "${SVRFeederVersion}" "${SLIMETEMP}\${SVRFeederDLFileZip}" ""
516534

517535
DetailPrint "Copying SlimeVR Feeder App..."
518536
CopyFiles /SILENT "${SLIMETEMP}\SlimeVR-Feeder-App-win64\*" "$INSTDIR\Feeder-App"
@@ -523,13 +541,9 @@ SectionEnd
523541

524542
Section "Microsoft Visual C++ Redistributable" SEC_MSVCPP
525543
SetOutPath $INSTDIR
526-
DetailPrint "Downloading Microsoft Visual C++ Redistributable..."
527-
NScurl::http GET "https://aka.ms/vs/17/release/vc_redist.x64.exe" "${SLIMETEMP}\vc_redist.x64.exe" /CANCEL /RESUME /END
528-
Pop $0 ; Status text ("OK" for success)
529-
${If} $0 != "OK"
530-
Abort "Failed to download Microsoft Visual C++ Redistributable. Reason: $0."
531-
${EndIf}
532-
DetailPrint "Downloaded!"
544+
545+
!insertmacro dlFile "${MVCURLType}" "Microsoft Visual C++ Redistributable" "${MVCVersion}" "${MVCDLURL}" "${MVCDLFileZip}"
546+
533547
DetailPrint "Installing Microsoft Visual C++ Redistributable..."
534548
nsExec::ExecToLog '"${SLIMETEMP}\vc_redist.x64.exe" /install /passive /norestart' $0
535549
Pop $0 ; Status text ("OK" for success)

0 commit comments

Comments
 (0)