Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -k flag to curl #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 62 additions & 118 deletions CaptureInstaller.bat
Original file line number Diff line number Diff line change
@@ -1,131 +1,75 @@
@Echo Off
powershell -window hidden -command ""
Mode 80,3 & color 0A

Set NETdownloadLink=https://download.visualstudio.microsoft.com/download/pr/c6a74d6b-576c-4ab0-bf55-d46d45610730/f70d2252c9f452c2eb679b8041846466/windowsdesktop-runtime-5.0.1-win-x64.exe
Set CAPTUREdownloadlink=https://github.com/automuteus/amonguscapture/releases/latest/download/AmongUsCapture.zip
Set NET5HASH=a7f9fc194371e125de609c709b52b1ac
Set zipName=AmongUsCapture.zip
Set captureName=AmongUsCapture.exe


REM Color stuff -----
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
REM -----------
:: curl, tar, and VT100 sequences are only available in Windows 10 and later
@echo off
setlocal enabledelayedexpansion
cls

cmd /c "dotnet --list-runtimes" > "%TEMP%\desktopRuntimes.txt"
find "Microsoft.WindowsDesktop.App 5.0.1" %TEMP%\desktopRuntimes.txt && (
del "%TEMP%\desktopRuntimes.txt"
REM .Net Runtime Already installed
goto checkForCapture

) || (
del "%TEMP%\desktopRuntimes.txt"
REM .Runtime Not installed
goto checkSumNetRuntime
REM Constants
set "NET_download_link=https://download.visualstudio.microsoft.com/download/pr/c6a74d6b-576c-4ab0-bf55-d46d45610730/f70d2252c9f452c2eb679b8041846466/windowsdesktop-runtime-5.0.1-win-x64.exe"
set "CAPTURE_download_link=https://github.com/denverquane/amonguscapture/releases/latest/download/AmongUsCapture.zip"
set "NET_hash=ac1be00ce52296148a84ddbcd92c7a78b1c6e09cf65d23fb2859ef050c3ad87eacf70745deb1cea0c64832486eb0b3470219dcb80ed034419bf6673487f2bac6"
set "net_name=windowsdesktop-runtime-5.0.1-win-x64.exe"
set "zip_name=AmongUsCapture.zip"
set "capture_name=AmongUsCapture.exe"
for /f %%A in ('echo prompt $E ^| cmd') do set "ESC=%%A"

echo ----- Automute.us CaptureInstaller -----
echo [ ] Checking for Microsoft Desktop Runtime 5 Dependency

REM The version never went past 5.0.17 so we only have to search for "5.0"
(dotnet --list-runtimes | find "Microsoft.WindowsDesktop.App 5.0" >nul) && goto :checkForCapture

:installDesktopRuntime
curl -kL# "%NET_download_link%" -o "%net_name%"
echo %ESC%[3;1H%ESC%[2K
for /f "delims=" %%A in ('certutil -hashfile "%net_name%" sha512 ^| find /v "hash"') do (
if not "%%A"=="%NET_hash%" goto :installDesktopRuntime
)

REM ―――――― Check Sums
:checkSumNetRuntime
set "RECEIVED=" & for /F "skip=1 delims=" %%H in ('
2^> nul CertUtil -hashfile "%TEMP%\windowsdesktop-runtime-5.0.1-win-x64.exe" md5
') do if not defined RECEIVED set "RECEIVED=%%H"
if "%NET5HASH%"=="%RECEIVED%" (
REM Correct hash
goto launchNetRuntime
) else (
REM Wrong Hash
goto installNetRuntime
curl -kLs "https://raw.githubusercontent.com/automuteus/capture-install/main/resetvars.vbs" -o "%TEMP%\resetvars.vbs"
start "" "%TEMP%\%net_name%" /passive /install /norestart

:detectIfDoneInstall
(dotnet --list-runtimes | find "Microsoft.WindowsDesktop.App 5.0" >nul) || (
timeout /t 2 >nul
cscript /nologo "%TEMP%\resetvars.vbs"

REM Despite the name, this is actually a completely unrelated script that
REM simply resets the default system variables to the values that they had
REM when the command prompt was first started.
call "%TEMP%\CaptureInstaller.bat"
(tasklist | find "windowsdesktop-runtime-5." >nul) || (
echo %ESC%[2;2H%ESC%[31mFAIL%ESC%[0m
exit /b
)
goto :detectIfDoneInstall
)
REM ――――――――――――――――――

:installNetRuntime
cls
echo off
cls
@powershell -window normal -command ""
call :colorEcho 0A " ---Downloading .NET 5 Desktop Runtime Installer (dependency)---"
echo.
echo.
curl -# "%NETdownloadLink%" -o "%TEMP%\windowsdesktop-runtime-5.0.1-win-x64.exe"
@powershell -window hidden -command ""
goto checkSumNetRuntime

:launchNetRuntime
powershell -window hidden -command ""

@REM curl -LJs "https://raw.githubusercontent.com/automuteus/capture-install/main/resetvars.vbs" -o "%TEMP%\resetvars.vbs"
@REM curl isnt working for some reason, so instead I am using a powershell command that does the same thing
powershell -Command "Invoke-WebRequest https://raw.githubusercontent.com/automuteus/capture-install/main/resetvars.vbs -Outfile '%TEMP%\resetvars.vbs'"

start "" "%TEMP%\windowsdesktop-runtime-5.0.1-win-x64.exe" /passive /install /norestart
goto detectIfdoneInstall

:detectIfdoneInstall
cmd /c "dotnet --list-runtimes" > "%TEMP%\desktopRuntimes.txt"
find "Microsoft.WindowsDesktop.App 5.0.1" %TEMP%\desktopRuntimes.txt && (
REM .NET 5 is done installing
del "%TEMP%\desktopRuntimes.txt"
taskkill /im "windowsdesktop-runtime-5.0.1-win-x64.exe" /f
del "%TEMP%\windowsdesktop-runtime-5.0.1-win-x64.exe"
del "%TEMP%\resetvars.vbs"
goto checkForCapture
) || (
REM Repeat install check
del "%TEMP%\desktopRuntimes.txt"
Timeout 2
%TEMP%\resetvars.vbs
call "%TEMP%\CaptureInstaller.bat"
tasklist.exe | findstr "windowsdesktop-runtime-5." > nul
if errorlevel 1 (
goto EOF
)
goto detectIfdoneInstall
)
taskkill /f /im "%net_name%" 2>nul
del "%TEMP%\%net_name%" "%TEMP%\resetvars.vbs" "%TEMP%\CaptureInstaller.bat"

:checkForCapture
if EXIST "%captureName%" ( goto launchCapture )
if EXIST "%zipName%" ( goto unZip )
if not EXIST "%captureName%" ( goto installCapture )
echo %ESC%[2;2H%ESC%[32mPASS%ESC%[0m
if exist "%capture_name%" goto :launchCapture
if exist "%zip_name%" goto :unZip

:installCapture
cls
echo off
cls
@powershell -window normal -command ""
call :colorEcho 0A " ---Downloading AutoMuteUs Capture---"
echo.
echo.
curl -LJ# "%CAPTUREdownloadLink%" -o "%~dp0%zipName%"
goto :unZip
echo [ ] Downloading AutoMuteUs Capture
curl -kLO# "%CAPTURE_download_link%"
echo %ESC%[4;1H%ESC%[2K
if not exist "%zip_name%" (
echo %ESC%[2;2H%ESC%[31mFAIL%ESC%[0m
exit /b
)

:unZip
cls
echo off
cls
@powershell -window normal -command ""
call :colorEcho 0A " ---Inflating the Zip---"
echo.
Powershell -Command "Expand-Archive -ErrorAction Stop -Force '.\%zipName%' '.\'"
if errorlevel 1 (
goto installCapture
echo %ESC%[3;2H%ESC%[32mPASS%ESC%[0m
echo [ ] Extracting AutoMuteUs Capture
tar -xf "%zip_name%"
if not exist "%capture_name%" (
echo %ESC%[4;1H%ESC%[31mFAIL%ESC%[0m
exit /b
)
DEL ".\%zipName%"
goto launchCapture
echo %ESC%[4;2H%ESC%[32mPASS%ESC%[0m
del "%zip_name%

:launchCapture
start "%~dp0" "%captureName%"
del "%~f0"
goto EOF

REM Color Stuff ----
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
REM --------

:EOF
start "" "%capture_name%"