Skip to content

Commit 2e3bf46

Browse files
committed
Refactor downloads with dlFiles macro and update URLs
Introduced a reusable dlFiles macro for downloading and unzipping files, reducing code duplication in the installer script. Updated download URLs and version definitions to use 'latest' releases for SlimeVR Server, Driver, and Feeder App. Adjusted plugin directories and included the new macro in the installer.
1 parent db763be commit 2e3bf46

File tree

2 files changed

+51
-57
lines changed

2 files changed

+51
-57
lines changed

windows/web/dlmacro.nsh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; Macro: dlFiles
2+
; Downloads a file from a specified URL, saves it locally, and unzips it to a target directory.
3+
; 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
11+
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!"
19+
20+
DetailPrint "Unzipping ${name} ${version} to installation folder...."
21+
nsisunz::Unzip "${SLIMETEMP}\${local_file}" "${SLIMETEMP}\${local_dir}\"
22+
Pop $0
23+
DetailPrint "Unzipping finished with $0."
24+
25+
!macroend

windows/web/slimevr_web_installer.nsi

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
Unicode True
22

3+
!AddPluginDir /x86-unicode "plugins\NScurl\x86-unicode"
4+
!AddPluginDir /x86-ansi "plugins\NScurl\x86-ansi"
5+
!AddPluginDir /amd64-unicode "plugins\NScurl\amd64-unicode"
6+
!AddPluginDir /x86-unicode "plugins\AccessControl\x86-unicode"
7+
!AddPluginDir /x86-ansi "plugins\AccessControl\x86-ansi"
8+
!AddPluginDir /amd64-unicode "plugins\AccessControl\amd64-unicode"
9+
!AddPluginDir /x86-unicode "plugins\Nsisunz\x86-unicode"
10+
!AddPluginDir /x86-ansi "plugins\Nsisunz\x86-ansi"
11+
!AddPluginDir /x86-unicode "plugins\NsProcess\x86-unicode"
12+
!AddPluginDir /x86-ansi "plugins\NsProcess\x86-ansi"
13+
!AddPluginDir /amd64-unicode "plugins\NsProcess\amd64-unicode"
14+
315
!include x64.nsh ; For RunningX64 check
416
!include LogicLib.nsh ; For conditional operators
517
!include nsDialogs.nsh ; For custom pages
@@ -9,6 +21,7 @@ Unicode True
921
!include TextFunc.nsh ; For ConfigRead
1022
!include MUI2.nsh
1123
!include .\steamdetect.nsh
24+
!include .\dlmacro.nsh
1225

1326
!define SF_USELECTED 0
1427
!define MUI_ICON "run.ico"
@@ -24,17 +37,17 @@ Unicode True
2437
!define JREDownloadedFileZip "OpenJDK17U-jre_x64_windows_hotspot_17.0.15_6.zip"
2538
Var JREneedInstall
2639

27-
!define SVRServerVersion "1.20.0"
28-
!define SVRServerDownloadURL "https://github.com/SlimeVR/SlimeVR-Server/releases/download/v1.20.0/SlimeVR-Server-1.20.0.zip"
29-
!define SVRServerDownloadedFileZip "SlimeVR-Server-1.20.0.zip"
40+
!define SVRServerVersion "latest"
41+
!define SVRServerDownloadURL "https://github.com/SlimeVR/SlimeVR-Server/releases/latest/download/SlimeVR-win64.zip"
42+
!define SVRServerDownloadedFileZip "SlimeVR-Server-latest.zip"
3043

31-
!define SVRDriverVersion "0.2.2"
32-
!define SVRDriverDownloadURL "https://github.com/SlimeVR/SlimeVR-OpenVR-Driver/releases/download/v0.2.2/slimevr-openvr-driver-win64.zip"
44+
!define SVRDriverVersion "latest"
45+
!define SVRDriverDownloadURL "https://github.com/SlimeVR/SlimeVR-OpenVR-Driver/releases/latest/download/slimevr-openvr-driver-win64.zip"
3346
!define SVRDriverDownloadedFileZip "slimevr-openvr-driver-win64.zip"
3447

35-
!define SVRFeederVersion "0.2.11"
36-
!define SVRFeederDownloadURL "https://github.com/SlimeVR/SlimeVR-Feeder-App/releases/download/v0.2.11/SlimeVR-Feeder-App-win64.zip"
37-
!define SVRFeederDownloadedFileZip "SlimeVR-Feeder-0.2.11.zip"
48+
!define SVRFeederVersion "latest"
49+
!define SVRFeederDownloadURL "https://github.com/SlimeVR/SlimeVR-Feeder-App/releases/latest/download/SlimeVR-Feeder-App-win64.zip"
50+
!define SVRFeederDownloadedFileZip "SlimeVR-Feeder-App-latest.zip"
3851

3952
Var /GLOBAL SteamVRResult
4053
Var /GLOBAL SteamVRLabelID
@@ -410,17 +423,7 @@ Section "SlimeVR Server" SEC_SERVER
410423

411424
SetOutPath $INSTDIR
412425

413-
DetailPrint "Downloading SlimeVR Server..."
414-
NScurl::http GET "https://github.com/SlimeVR/SlimeVR-Server/releases/latest/download/SlimeVR-win64.zip" "${SLIMETEMP}\SlimeVR-win64.zip" /CANCEL /RESUME /END
415-
Pop $0 ; Status text ("OK" for success)
416-
${If} $0 != "OK"
417-
Abort "Failed to download SlimeVR Server. Reason: $0."
418-
${EndIf}
419-
DetailPrint "Downloaded!"
420-
421-
nsisunz::Unzip "${SLIMETEMP}\SlimeVR-win64.zip" "${SLIMETEMP}\SlimeVR\"
422-
Pop $0
423-
DetailPrint "Unzipping finished with $0."
426+
!insertmacro dlFiles "SlimeVR Server" "${SVRServerVersion}" "${SVRServerDownloadURL}" "${SVRServerDownloadedFileZip}" "SlimeVR"
424427

425428
${If} $SELECTED_INSTALLER_ACTION == "update"
426429
Delete "$INSTDIR\slimevr-ui.exe"
@@ -462,27 +465,15 @@ SectionEnd
462465
Section "Java JRE" SEC_JRE
463466
SectionIn RO
464467

465-
DetailPrint "Downloading Java JRE ${JREVersion}..."
466-
NScurl::http GET "${JREDownloadURL}" "${SLIMETEMP}\${JREDownloadedFileZip}" /CANCEL /RESUME /END
467-
468-
Pop $0 ; Status text ("OK" for success)
469-
${If} $0 != "OK"
470-
Abort "Failed to download Java JRE ${JREVersion}. Reason: $0."
471-
${EndIf}
472-
DetailPrint "Downloaded!"
468+
!insertmacro dlFiles "Java JRE" "${JREVersion}" "${JREDownloadURL}" "${JREDownloadedFileZip}" "OpenJDK"
473469

474470
# Make sure to delete all files on a update from jre, so if there is a new version no old files are left.
475471
IfFileExists "$INSTDIR\jre" 0 SEC_JRE_DIRNOTFOUND
476472
DetailPrint "Removing old Java JRE..."
477473
RMdir /r "$INSTDIR\jre"
478474
CreateDirectory "$INSTDIR\jre"
479475
SEC_JRE_DIRNOTFOUND:
480-
481-
DetailPrint "Unzipping Java JRE ${JREVersion} to installation folder...."
482-
nsisunz::Unzip "${SLIMETEMP}\${JREDownloadedFileZip}" "${SLIMETEMP}\OpenJDK\"
483-
Pop $0
484-
DetailPrint "Unzipping finished with $0."
485-
476+
# Todo: Make a better way to copy the jre folder, since the version number is in the folder name
486477
FindFirst $0 $1 "${SLIMETEMP}\OpenJDK\jdk-17.*-jre"
487478
loop:
488479
StrCmp $1 "" done
@@ -496,18 +487,7 @@ SectionEnd
496487
Section "SteamVR Driver" SEC_VRDRIVER
497488
SetOutPath $INSTDIR
498489

499-
DetailPrint "Downloading SteamVR Driver..."
500-
NScurl::http GET "https://github.com/SlimeVR/SlimeVR-OpenVR-Driver/releases/latest/download/slimevr-openvr-driver-win64.zip" "${SLIMETEMP}\slimevr-openvr-driver-win64.zip" /CANCEL /RESUME /END
501-
Pop $0 ; Status text ("OK" for success)
502-
${If} $0 != "OK"
503-
Abort "Failed to download SteamVR Driver. Reason: $0."
504-
${EndIf}
505-
DetailPrint "Downloaded!"
506-
507-
DetailPrint "Unpacking downloaded files..."
508-
nsisunz::Unzip "${SLIMETEMP}\slimevr-openvr-driver-win64.zip" "${SLIMETEMP}\slimevr-openvr-driver-win64\"
509-
Pop $0
510-
DetailPrint "Unzipping finished with $0."
490+
!insertmacro dlFiles "SteamVR Driver" "${SVRDriverVersion}" "${SVRDriverDownloadURL}" "${SVRDriverDownloadedFileZip}" "slimevr-openvr-driver-win64"
511491

512492
# Include SteamVR powershell script to register/unregister driver
513493
File "steamvr.ps1"
@@ -531,18 +511,7 @@ SectionEnd
531511
Section "SlimeVR Feeder App" SEC_FEEDER_APP
532512
SetOutPath $INSTDIR
533513

534-
DetailPrint "Downloading SlimeVR Feeder App..."
535-
NScurl::http GET "https://github.com/SlimeVR/SlimeVR-Feeder-App/releases/latest/download/SlimeVR-Feeder-App-win64.zip" "${SLIMETEMP}\SlimeVR-Feeder-App-win64.zip" /CANCEL /RESUME /END
536-
Pop $0 ; Status text ("OK" for success)
537-
${If} $0 != "OK"
538-
Abort "Failed to download SlimeVR Feeder App. Reason: $0."
539-
${EndIf}
540-
DetailPrint "Downloaded!"
541-
542-
DetailPrint "Unpacking downloaded files..."
543-
nsisunz::Unzip "${SLIMETEMP}\SlimeVR-Feeder-App-win64.zip" "${SLIMETEMP}"
544-
Pop $0
545-
DetailPrint "Unzipping finished with $0."
514+
!insertmacro dlFiles "SlimeVR Feeder App" "${SVRFeederVersion}" "${SVRFeederDownloadURL}" "${SVRFeederDownloadedFileZip}" ""
546515

547516
DetailPrint "Copying SlimeVR Feeder App..."
548517
CopyFiles /SILENT "${SLIMETEMP}\SlimeVR-Feeder-App-win64\*" "$INSTDIR\Feeder-App"

0 commit comments

Comments
 (0)