@echo on
@setlocal
@set this=%~dp0
@set thisn=%~nx0
@set name=AddOnStudio
@set namel=AddOn Studio
@set version=2022
@set shelledition=Community
@set shellname=Visual Studio
@set shellver=17.10 LTSC
@set stubname=VisualStudioSetup%shelledition%
@set stubdl=https://files.fallenworlds.org/_as/_26SAR5/VisualStudioSetup_2022_Community_220315.exe
@set stubch=https://aka.ms/vs/17/release.LTSC.17.10/channel
@set stuwkl=Microsoft.VisualStudio.Workload.ManagedDesktop
@set stupth=%ProgramFiles%\Microsoft Visual Studio\2022\%shelledition%LTSC

@echo.
@REM echo %shellname% Community (stable version) installation for %namel% 2022
@echo.
@echo This will install %shellname% %version% %shelledition% LTSC for %name%
@echo.
@echo Current preferred version is %shellname% %version% %shellver% (Long Term Support Channel) 
@echo.
@echo Can uninstall any current %shellname% first, or install this along side an existing one.
@echo If use Pro or Enterpise and would rather use that, choose appropriate LTSC 17.10 here:
@echo    https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history
@echo.
@echo Click close or press Ctrl-C to abort.
@pause

@if not exist "%SystemRoot%\System32\curl.exe" GOTO NOTHASCURL
@if not exist %LOCALAPPDATA%\Temp goto NOTHASTEMP

@echo Download stub...
@if exist "%LOCALAPPDATA%\Temp\%stubname%.exe" goto HASSTUB
@curl.exe -o "%LOCALAPPDATA%\Temp\%stubname%.exe" %stubdl%
@echo %ERRORLEVEL%
@if "%ERRORLEVEL%" NEQ "0" goto NOTHASDL
:HASSTUB
@echo Has Stub...

@echo Check path...
@rem dont try to add workload if ltsc already installed, because will just land on workloads page even if already has, and look like not complete
@if exist "%stupth%" goto HASPATH
@set addstuwkl=--add %stuwkl%
@rem echo Not has path...
@goto HASPATHNO
:HASPATH
@echo Has path...
:HASPATHNO

@echo Install stub...
@rem echo "%LOCALAPPDATA%\Temp\%stubname%.exe" --installPath "%stupth%" --channelUri %stubch% --add %stuwkl%
@"%LOCALAPPDATA%\Temp\%stubname%.exe" --installPath "%stupth%" --channelUri %stubch% --add %stuwkl%
@rem "%LOCALAPPDATA%\Temp\%stubname%.exe" --channelUri %stubch% --add %stuwkl%
@rem "%LOCALAPPDATA%\Temp\%stubname%.exe" --installPath "%stupth%" --channelUri %stubch% %addstuwkl%

@GOTO :EOF

:NOTHASDL
@echo Error: Could not download installer stub.
@GOTO :EOF
:NOTHASCURL
:NOTHASTEMP
@echo Error: This script requires Windows 10 or higher.
@GOTO :EOF

