Skip to content

Instantly share code, notes, and snippets.

@donnaken15
Created June 13, 2024 22:49
Show Gist options
  • Save donnaken15/479df24f14b0cc7ef14e3812b782f562 to your computer and use it in GitHub Desktop.
Save donnaken15/479df24f14b0cc7ef14e3812b782f562 to your computer and use it in GitHub Desktop.
download and extract TronScript using a list of mirrors, and prompt upon error
@if (@CodeSection == @Batch) @then
@echo off
where /q curl || goto fail
where /q grep || goto fail
set ESC=[
for %%H in (
https://bmrf.org/repos/tron
https://mirror.meamod.com/tron
https://bodkov.com
) do ( call :try "%%H" && exit /b )
::https://www.oldergeeks.com/downloads/download.php?id=2202
::broken links, stupid fail websites
::https://tron.elevatehosting.co.uk
exit /b
:fail
echo %ESC%91mMissing dependencies. (grep and/or curl)%ESC%0m
exit /b 1
:try
setlocal EnableDelayedExpansion
set "HOST=%~1"
for /f "usebackq delims=" %%T in (
`curl -Lfs -m 10 !HOST! ^| grep -Eo "Tron(%%20| )v[A-Za-z0-9\. \(\)%%-]+(\)|%%29)\.exe\""`
) do (
for /f "usebackq delims=" %%S in (`cscript /nologo /e:JScript "%~f0" "%%T"`) do (
set "A=!HOST!/%%S"
)
)
if "!A!"=="" goto :fail
:retry[2]
echo %ESC%92mMirror: !HOST!%ESC%0m
set "target=tron.7z.exe"
echo curl -Lf -o "!target!" --progress-bar -- "!A!"
curl -Lf -o "!target!" --progress-bar -- "!A!" || goto fail2
:: PLEASE LET ME PIPE THIS TO 7ZA
::7za x "!target!" -bsp1 -o. -y tron
if not exist "!target!" goto fail2
:retry[1]
"!target!" x -o. -y tron\tron.bat tron\resources || goto fail2
del "!target!"
:retry[4]
endlocal
exit /b 0
:fail2
echo %ESC%91mERROR: Download could not be found, or the download failed to run.
echo Target URL: !A!
echo This could be because it was quarantined by Windows Defender Antivirus,
echo or the mirror's download link is broken. You can choose what to do here:%ESC%0m
choice -m "%ESC%96mX=Extract after restoring, R=Retry download, N=Next mirror, C=Cancel%ESC%0m" -c XRNC
goto :retry[%ERRORLEVEL%]
:fail
echo %ESC%91mMirror failed: !HOST!%ESC%0m
:retry[3]
endlocal
exit /b 1
endlocal
exit /b
exit /b
@end
// black magic from
// https://stackoverflow.com/questions/28221685/urldecode-in-batch-file
// and
// https://ss64.org/oldforum/viewtopic.php?id=1836
function encodeEntities(what) {
return what.replace(/[\s\<\>\#\+\{\}\|\\\^\~\[\]\'\;\/\?\:\@\=\&\$]/ig, function(m, $1) {
return "%"+m.charCodeAt(0).toString(16).toUpperCase();
});
}
WSH.Echo(encodeEntities(WSH.Arguments(0)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment