@@ -127,13 +127,13 @@ shift & goto :%~1
127127
128128
129129:: Sets the currentColor global for the given foreground/background colors
130- :: currentColor must be output to the terminal before outputing text in
130+ :: currentColor must be output to the terminal before outputting text in
131131:: order to generate a colored output.
132132::
133133:: string foreground color name. Optional if no background provided.
134134:: Defaults to "White"
135135:: string background color name. Optional. Defaults to Black.
136- :: string intense. Optional. If "true" then the insensity is turned up
136+ :: string intense. Optional. If "true" then the intensity is turned up
137137:setColor
138138
139139 REM If you want to get a little fancy then you can also try
@@ -343,7 +343,7 @@ shift & goto :%~1
343343 if errorlevel 16 (
344344 call :WriteLine " Failed" !color_error!
345345 else if errorlevel 8 (
346- call :WriteLine " Some files inot copied" !color_warn!
346+ call :WriteLine " Some files not copied" !color_warn!
347347 ) else (
348348 call :WriteLine " done" !color_success!
349349 )
@@ -369,7 +369,7 @@ shift & goto :%~1
369369 SetLocal EnableDelayedExpansion
370370
371371 REM Param 1: The URL where the download can be found.
372- REM eg "https://codeproject-ai.s3.ca-central-1.amazonaws .com/server/models/"
372+ REM eg "https://mycdn .com/server/models/"
373373 set assetStorageUrl = %1
374374 set assetStorageUrl = !assetStorageUrl:" =!
375375
@@ -382,7 +382,8 @@ shift & goto :%~1
382382 set downloadToDir = !downloadToDir:" =!
383383
384384 REM Param 4: The name of the folder within the downloads directory where
385- REM the contents should be extracted. eg. assets
385+ REM the contents should be extracted. eg. assets.
386+ REM NOTE: If this param is empty then no extraction will happen
386387 set dirToExtract = %4
387388 set dirToExtract = !dirToExtract:" =!
388389
@@ -393,22 +394,25 @@ shift & goto :%~1
393394 if " !message! " == " " set message = Downloading !fileToGet! ...
394395
395396 if /i " %verbosity% " neq " quiet" (
396- call :WriteLine " Downloading !fileToGet! from !assetStorageUrl! to !downloadToDir! \ !dirToExtract! " " !color_info! "
397+ call :WriteLine " Downloading !fileToGet! from !assetStorageUrl! to !downloadToDir! " " !color_info! "
397398 )
398399
399400 call :Write " !message! " " !color_primary! "
400401
401- set extension = !fileToGet:~-3 !
402- if /i " !extension! " NEQ " .gz" (
403- set extension = !fileToGet:~-4 !
404- if /i " !extension! " NEQ " .zip" (
405- call :WriteLine " Unknown and unsupported file type for file !fileToGet! " " !color_error! "
406- exit /b REM no point in carrying on
402+ REM If we're to extract this file then ensure it's an extractable file
403+ if " !dirToExtract! " neq " " (
404+ set extension = !fileToGet:~-3 !
405+ if /i " !extension! " NEQ " .gz" (
406+ set extension = !fileToGet:~-4 !
407+ if /i " !extension! " NEQ " .zip" (
408+ call :WriteLine " Unknown and unsupported file type for file !fileToGet! " " !color_error! "
409+ exit /b REM no point in carrying on
410+ )
407411 )
408412 )
409413
410414 if /i " %verbosity% " neq " quiet" (
411- call :WriteLine " Checking ' !downloadToDir! \ !fileToGet! ' " " !color_info! "
415+ call :WriteLine " Checking... " " !color_info! "
412416 )
413417
414418 if exist " !downloadToDir! \!fileToGet! " (
@@ -425,7 +429,7 @@ shift & goto :%~1
425429 REM Be careful with the quotes so we can handle paths with spaces
426430 powershell -command " Start-BitsTransfer -Source '!assetStorageUrl!!fileToGet! ' -Description !fileToGet! -Destination '!downloadToDir! \!fileToGet! '"
427431
428- REM If these fail, it could be becuase of hanging transfers
432+ REM If these fail, it could be because of hanging transfers
429433 if errorlevel 1 (
430434 powershell -Command " Get-BitsTransfer | Remove-BitsTransfer"
431435 powershell -command " Start-BitsTransfer -Source '!assetStorageUrl!!fileToGet! ' -Description !fileToGet! -Destination '!downloadToDir! \!fileToGet! '"
@@ -453,18 +457,19 @@ shift & goto :%~1
453457 call :WriteLine " Heading to !downloadToDir! " " !color_info! "
454458 )
455459
456- pushd " !downloadToDir! "
457- if not exist " !downloadToDir! \!dirToExtract! " mkdir " !downloadToDir! \!dirToExtract! "
460+ REM Extract the file if we've been given an extraction folder name
461+ if " !dirToExtract! " neq " " (
462+ pushd " !downloadToDir! "
463+ if not exist " !downloadToDir! \!dirToExtract! " mkdir " !downloadToDir! \!dirToExtract! "
458464
459- call :ExtractToDirectory " !fileToGet! " " !dirToExtract! "
460-
461- if errorlevel 1 (
465+ call :ExtractToDirectory " !fileToGet! " " !dirToExtract! "
466+ if errorlevel 1 (
467+ popd
468+ exit /b 1
469+ )
462470 popd
463- exit /b 1
464471 )
465472
466- popd
467-
468473 call :WriteLine " done." " !color_success! "
469474
470475 exit /b
@@ -518,6 +523,101 @@ shift & goto :%~1
518523
519524 exit /b
520525
526+ :EnsureVCRedistInstalled
527+ SetLocal EnableDelayedExpansion
528+
529+ set url_x64 = https://aka.ms/vs/17/release/
530+ set file_x64 = vc_redist.x64.exe
531+
532+ call :Write " Checking for VC++ Redist..." %color_info%
533+ reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\17.0\VC\Runtimes\x64" > nul 2 >& 1
534+ if %errorlevel% equ 0 (
535+ call :WriteLine " v17 Present." %color_success%
536+ exit /b
537+ )
538+ reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\16.0\VC\Runtimes\x64" > nul 2 >& 1
539+ if %errorlevel% equ 0 (
540+ call :WriteLine " v16 Present." %color_success%
541+ exit /b
542+ )
543+ reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\15.0\VC\Runtimes\x64" > nul 2 >& 1
544+ if %errorlevel% equ 0 (
545+ call :WriteLine " v15 Present." %color_success%
546+ exit /b
547+ )
548+ reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" > nul 2 >& 1
549+ if %errorlevel% equ 0 (
550+ call :WriteLine " v14 Present." %color_success%
551+ exit /b
552+ )
553+
554+ REM params: "https://cdn.com/assets" "file.zip" "\downloads\myModuleDir" "extract_dir" "Downloading files..."
555+ REM Empty "extract_dir" means file will not be unzipped (since it's not a zip)
556+ call :DownloadAndExtract " !url_x64! " " !file_x64! " " !downloadDirPath! \!platform! " " " " Downloading VC++ Redist files..."
557+
558+ if exist " !downloadDirPath! \!platform! \!file_x64! " (
559+ call :Write " Installing VC++ Redist..." %color_info%
560+ if /i " %verbosity% " == " quiet" (
561+ " !downloadDirPath! \!platform! \!file_x64! " /quiet /norestart
562+ ) else (
563+ " !downloadDirPath! \!platform! \!file_x64! " /norestart
564+ )
565+ call :WriteLine " Done." %color_info%
566+
567+ REM -- Cleanup: Delete the installer files after installation
568+ REM del /f /q "!downloadDirPath!\!platform!\!file_x64!"
569+ ) else (
570+ call :WriteLine " Unable to download VC redist installer" !color_error!
571+ )
572+
573+ exit /b
574+
575+
576+ :EnsureWinGetInstalled
577+ SetLocal EnableDelayedExpansion
578+
579+ where winget > NUL 2 > NUL
580+ if errorlevel 1 (
581+ call :Write " Installing WinGet..." %color_info%
582+
583+ set DoWingetInstall = true
584+
585+ if " !DoWingetInstall! " == " true" (
586+ set " archType = x64"
587+ if /i " !architecture! " == " arm64" set " archType = arm64"
588+
589+ REM https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox
590+ if /i " %verbosity% " == " quiet" (
591+ set progressType = silentlyContinue
592+ ) else (
593+ set progressType = Continue
594+ )
595+ powershell -command $progressPreference = '!progressType! '; ^
596+ Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle; ^
597+ Add-AppxPackage Microsoft.VCLibs.!archType! .14.00.Desktop.appx;
598+
599+ powershell -command $progressPreference = '!progressType! '; ^
600+ Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.!archType! .14.00.Desktop.appx -OutFile Microsoft.VCLibs.!archType! .14.00.Desktop.appx; ^
601+ Add-AppxPackage Microsoft.UI.Xaml.2.8.!archType! .appx;
602+
603+ powershell -command $progressPreference = '!progressType! '; ^
604+ Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.!archType! .appx -OutFile Microsoft.UI.Xaml.2.8.!archType! .appx; ^
605+ Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle;
606+
607+ call :WriteLine " Done." %color_info%
608+
609+ call :Write " Cleaning up..." %color_info%
610+ del Microsoft.VCLibs.!archType! .14.00.Desktop.appx
611+ del Microsoft.UI.Xaml.2.8.!archType! .appx
612+ del Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
613+ call :WriteLine " Done." %color_info%
614+ ) else (
615+ powershell -command " Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe"
616+ )
617+ )
618+
619+ exit /b
620+
521621
522622:SetupDotNet
523623 SetLocal EnableDelayedExpansion
@@ -640,45 +740,7 @@ shift & goto :%~1
640740 )
641741 ) else (
642742
643- where winget > NUL 2 > NUL
644- if errorlevel 1 (
645- call :Write " Installing WinGet..." %color_info%
646-
647- set DoWingetInstall = true
648- if " !DoWingetInstall! " == " true" (
649- set " archType = x64"
650- if /i " !architecture! " == " arm64" set " archType = arm64"
651-
652- REM https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox
653- if /i " %verbosity% " == " quiet" (
654- set progressType = silentlyContinue
655- ) else (
656- set progressType = Continue
657- )
658- powershell -command $progressPreference = '!progressType! '; ^
659- Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle; ^
660- Add-AppxPackage Microsoft.VCLibs.!archType! .14.00.Desktop.appx;
661-
662- powershell -command $progressPreference = '!progressType! '; ^
663- Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.!archType! .14.00.Desktop.appx -OutFile Microsoft.VCLibs.!archType! .14.00.Desktop.appx; ^
664- Add-AppxPackage Microsoft.UI.Xaml.2.8.!archType! .appx;
665-
666- powershell -command $progressPreference = '!progressType! '; ^
667- Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.!archType! .appx -OutFile Microsoft.UI.Xaml.2.8.!archType! .appx; ^
668- Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle;
669-
670- call :WriteLine " Done." %color_info%
671-
672- call :Write " Cleaning up..." %color_info%
673- del Microsoft.VCLibs.140.00.UWPDesktop.appx
674- del Microsoft.VCLibs.!archType! .14.00.Desktop.appx
675- del Microsoft.UI.Xaml.2.8.!archType! .appx
676- del Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
677- call :WriteLine " Done." %color_info%
678- ) else (
679- powershell -command " Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe"
680- )
681- )
743+ call :EnsureWinGetInstalled
682744
683745 if /i " !requestedType! " == " SDK" (
684746 winget install Microsoft.DotNet.SDK.!requestedNetMajorVersion!
@@ -720,7 +782,7 @@ shift & goto :%~1
720782 REM The path to the folder containing the base python installation
721783 set pythonRuntimeInstallPath = !runtimesDirPath! \bin\!os! \!pythonName!
722784
723- REM For debugging, or correcting, we can force redownloads . Be careful though.
785+ REM For debugging, or correcting, we can force re-downloads . Be careful though.
724786 if /i " %forceOverwrite% " == " true" (
725787
726788 REM Force Re-download
@@ -731,7 +793,7 @@ shift & goto :%~1
731793
732794 REM Force overwrite of python installation
733795 call :WriteLine " Cleaning Python directory to force re-install of Python" " !color_info! "
734- call :WriteLine " This will mean any previous PIP installs wwill be lost." " !color_warn! "
796+ call :WriteLine " This will mean any previous PIP installs will be lost." " !color_warn! "
735797 if exist " !pythonRuntimeInstallPath! " rmdir /s %rmdirFlags% " !pythonRuntimeInstallPath! "
736798 )
737799
@@ -802,7 +864,7 @@ shift & goto :%~1
802864 set searchDir = %~1
803865
804866 if /i " %verbosity% " neq " quiet" (
805- call :WriteLine " Searching for a suitable requirements.txts file in !searchDir! " " !color_info! "
867+ call :WriteLine " Searching for a suitable requirements.txt file in !searchDir! " " !color_info! "
806868 )
807869
808870 REM This is getting complicated. The order of priority for the requirements file is:
@@ -1296,7 +1358,7 @@ shift & goto :%~1
12961358
12971359:GetCudaVersion
12981360
1299- rem setlocal enabledelayedexpansion
1361+ REM SetLocal EnableDelayedExpansion
13001362
13011363 :: Use nvcc to find the CUDA version
13021364 where nvcc > nul 2 >& 1
@@ -1381,7 +1443,7 @@ shift & goto :%~1
13811443 )
13821444
13831445 REM Module settings files are loaded in this order. Each file will overwrite (but not delete)
1384- REM settings of the previous file. Becuase of this, we're going to search the files in REVERSE
1446+ REM settings of the previous file. Because of this, we're going to search the files in REVERSE
13851447 REM order until we find the first value based on the most specific to least specific file.
13861448 REM modulesettings.json
13871449 REM modulesettings.development.json
@@ -1448,9 +1510,9 @@ shift & goto :%~1
14481510
14491511
14501512REM Gets a value from the modulesettings.json file (any JSON file, really) based
1451- REM purely on the name of the propery . THIS METHOD DOES NOT TAKE INTO ACCOUNT THE
1513+ REM purely on the name of the property . THIS METHOD DOES NOT TAKE INTO ACCOUNT THE
14521514REM DEPTH OF A PROPERTY. If the property is at the root level or 10 levels down,
1453- REM it's all the same. The extraction is done purely by grep/sed, so is very niaive .
1515+ REM it's all the same. The extraction is done purely by grep/sed, so is very naive .
14541516:GetValueFromModuleSettings jsonFilePath moduleId property returnValue
14551517 set " moduleSettingValue = "
14561518 SetLocal EnableDelayedExpansion
@@ -1579,7 +1641,7 @@ REM it's all the same. The extraction is done purely by grep/sed, so is very nia
15791641
15801642 exit /b
15811643
1582- REM Gets the moduleID from a modulesettings.json file. See above function for commentss
1644+ REM Gets the moduleID from a modulesettings.json file. See above function for comments
15831645:GetModuleIdFromModuleSettingsFile jsonFilePath returnValue
15841646 set " moduleSettingValue = "
15851647 SetLocal EnableDelayedExpansion
@@ -1765,7 +1827,7 @@ REM Gets the moduleID from a modulesettings.json file. See above function for c
17651827
17661828REM Strips single line comments from a file and stores the cleaned contents in a new file
17671829:StripJSONComments
1768- setlocal enabledelayedexpansion
1830+ SetLocal EnableDelayedExpansion
17691831
17701832 set inputFilePath = %~1
17711833 set cleanFilePath = %~2
@@ -1904,7 +1966,7 @@ REM Call this, then test: if "%online%" == "true" echo 'online'
19041966 REM echo VERSION IS '%%a '
19051967 set version = %%a
19061968 )
1907- endlocal & set VCredistVersion = %version:v =%
1969+ EndLocal & set VCredistVersion = %version:v =%
19081970
19091971 exit /b
19101972
@@ -1913,7 +1975,7 @@ REM Get Windows Version
19131975:: Get the OS Name and version information
19141976:getWindowsOSName OSName
19151977
1916- REM setlocal enabledelayedexpansion
1978+ REM SetLocal EnableDelayedExpansion
19171979
19181980 REM Get the OS version information
19191981 for /f " tokens=4-6 delims=. " %%i in ('ver') do (
@@ -1965,7 +2027,7 @@ REM Thanks to https://stackoverflow.com/a/15809139/1128209
19652027:: Nodes are normally strictly numeric, without a 0 prefix. A letter suffix
19662028:: is treated as a separate node
19672029::
1968- setlocal enableDelayedExpansion
2030+ SetLocal EnableDelayedExpansion
19692031
19702032 set " v1 = %~1 "
19712033 set " v2 = %~2 "
@@ -2021,7 +2083,7 @@ REM Thanks to https://stackoverflow.com/a/15809139/1128209
20212083
20222084:timeSince startTime duration
20232085
2024- setlocal enableDelayedExpansion
2086+ SetLocal EnableDelayedExpansion
20252087
20262088 set " startTime = %~1 "
20272089
0 commit comments