From 10d12693fe4301e9b070ee4bbfc7fad1b4a10f9e Mon Sep 17 00:00:00 2001 From: Thedogecraft Date: Fri, 5 Jan 2024 13:32:56 -0800 Subject: [PATCH] Update update.bat --- update.bat | 55 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/update.bat b/update.bat index 1f83cfe..0205e2c 100644 --- a/update.bat +++ b/update.bat @@ -1,43 +1,30 @@ @echo off -setlocal enabledelayedexpansion +setlocal -REM Replace with your GitHub repository information -set repo_owner=Parcoil -set repo_name=Sparkle +set ZIP_URL=https://github.com/Parcoil/Sparkle/releases/latest/download/win-unpacked.zip +set ZIP_FILE=%TEMP%\win-unpacked.zip +set EXTRACT_DIR=C:\Users\%USERNAME%\AppData\Local\Programs\sparkle -REM Get the latest release information from the GitHub API -for /f "usebackq tokens=2 delims=: " %%a in (`curl -s https://api.github.com/repos/%repo_owner%/%repo_name%/releases/latest ^| findstr "tag_name"`) do ( - set latest_release=%%a -) +rem Download the latest ZIP file +curl -L -o "%ZIP_FILE%" "%ZIP_URL%" -REM Check if the latest release is newer than the current installation -if not exist "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\version.txt" ( - set /a newer=1 -) else ( - for /f "usebackq delims=" %%i in ("C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\version.txt") do ( - set installed_version=%%i - if "!latest_release!" gtr "!installed_version!" ( - set /a newer=1 - ) else ( - set /a newer=0 - ) - ) +rem Check if the download was successful +if %ERRORLEVEL% NEQ 0 ( + echo Failed to download the ZIP file. + exit /b 1 ) -REM If a newer release is available, download and extract it -if !newer! equ 1 ( - echo Downloading and extracting the latest release... - curl -L -o "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\latest.zip" "https://github.com/%repo_owner%/%repo_name%/releases/latest/download/win-unpacked.zip" - if not errorlevel 1 ( - mkdir "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\temp" - tar -xf "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\latest.zip" -C "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\temp" - move /y "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\temp\*.*" "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\" - rmdir /s /q "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\temp" - echo !latest_release! > "C:\Users\%USERNAME%\AppData\Local\Programs\sparkle\version.txt" - echo Latest release has been downloaded and extracted. - ) else ( - echo Failed to download the latest release. - ) +rem Extract the ZIP file to the destination folder +if not exist "%EXTRACT_DIR%" ( + mkdir "%EXTRACT_DIR%" ) +tar -xf "%ZIP_FILE%" -C "%EXTRACT_DIR%" + +rem Clean up the temporary ZIP file +del /q "%ZIP_FILE%" + +echo Latest release has been downloaded and extracted. + +rem Add your existing batch script code here endlocal