Skip to content

Commit

Permalink
Update update.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
Thedogecraft authored Jan 5, 2024
1 parent 3606ccd commit 10d1269
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions update.bat
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 10d1269

Please sign in to comment.