mirror of
https://github.com/Flowseal/zapret-discord-youtube.git
synced 2025-04-10 15:25:39 -07:00
Enhancements
The user is now guaranteed to get the current version information without complications
This commit is contained in:
parent
642f6927ff
commit
7facdc039f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
version.txt
|
|
@ -1,88 +1,37 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
chcp 437 > nul
|
chcp 65001 > nul
|
||||||
|
:: 65001 - UTF-8
|
||||||
|
|
||||||
set "CURRENT_VERSION=1.6.3"
|
:: Set current version and URLs
|
||||||
set "GITHUB_URL=https://raw.githubusercontent.com/Flowseal/zapret-discord-youtube/refs/heads/main/.service/version.txt"
|
set "LOCAL_VERSION=1.6.3"
|
||||||
set "RELEASE_URL=https://github.com/Flowseal/zapret-discord-youtube/releases"
|
set "GITHUB_VERSION_URL=https://raw.githubusercontent.com/Flowseal/zapret-discord-youtube/main/.service/version.txt"
|
||||||
set "VERSION_FILE=version.txt"
|
set "GITHUB_RELEASE_URL=https://github.com/Flowseal/zapret-discord-youtube/releases/tag/"
|
||||||
set "SKIP_VERSION=null"
|
set "GITHUB_DOWNLOAD_URL=https://github.com/Flowseal/zapret-discord-youtube/releases/latest/download/zapret-discord-youtube-"
|
||||||
set "FILE_EXISTS=1"
|
|
||||||
|
|
||||||
for /f "delims=" %%A in ('powershell -command "[datetime]::Now.ToString('yyyy-MM-dd HH:mm:ss')"') do set CURRENT_TIMESTAMP=%%A
|
:: Get the latest version from GitHub
|
||||||
|
for /f "delims=" %%A in ('powershell -command "(Invoke-WebRequest -Uri \"%GITHUB_VERSION_URL%\" -Headers @{\"Cache-Control\"=\"no-cache\"} -TimeoutSec 5).Content.Trim()" 2^>nul') do set "GITHUB_VERSION=%%A"
|
||||||
|
|
||||||
:: If file version.txt exists
|
:: Error handling
|
||||||
if not exist %VERSION_FILE% (
|
if not defined GITHUB_VERSION (
|
||||||
set "FILE_EXISTS=0"
|
echo Error: Failed to fetch the latest version. Check your internet connection
|
||||||
echo time: %CURRENT_TIMESTAMP%> %VERSION_FILE%
|
|
||||||
echo ver: %CURRENT_VERSION%>> %VERSION_FILE%
|
|
||||||
)
|
)
|
||||||
|
|
||||||
:: Reading data from local version.txt
|
:: Version comparison
|
||||||
for /f "tokens=1,* delims=: " %%A in (%VERSION_FILE%) do (
|
if "%LOCAL_VERSION%"=="%GITHUB_VERSION%" (
|
||||||
if "%%A"=="time" set "LAST_CHECK=%%B"
|
echo Latest version installed: %LOCAL_VERSION%
|
||||||
if "%%A"=="ver" set "INSTALLED_VERSION=%%B"
|
|
||||||
if "%%A"=="skip" set "SKIP_VERSION=%%B"
|
|
||||||
)
|
|
||||||
|
|
||||||
:: If file was called from thirdparty script (with 'soft' argument that blocks checking for 12 hours)
|
|
||||||
if "%~1"=="soft" (
|
|
||||||
:: Converting dates to parts for calculation
|
|
||||||
for /f "tokens=1-6 delims=-: " %%A in ("%CURRENT_TIMESTAMP%") do (
|
|
||||||
set "CURRENT_MONTH=%%B"
|
|
||||||
set "CURRENT_DAY=%%C"
|
|
||||||
set "CURRENT_HOUR=%%D"
|
|
||||||
)
|
|
||||||
for /f "tokens=1-6 delims=-: " %%A in ("%LAST_CHECK%") do (
|
|
||||||
set "LAST_MONTH=%%B"
|
|
||||||
set "LAST_DAY=%%C"
|
|
||||||
set "LAST_HOUR=%%D"
|
|
||||||
)
|
|
||||||
|
|
||||||
set /a "time_diff_in_minutes = (CURRENT_MONTH - LAST_MONTH) * 43200 + (CURRENT_DAY - LAST_DAY) * 1440 + (CURRENT_HOUR - LAST_HOUR) * 60"
|
|
||||||
|
|
||||||
if !time_diff_in_minutes! LEQ 360 if !FILE_EXISTS!==1 (
|
|
||||||
echo Skipping the update check because it hasnt been 6 hours
|
|
||||||
goto :EOF
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Reading new version from github
|
|
||||||
set "NEW_VERSION="
|
|
||||||
for /f "delims=" %%A in ('powershell -command "(Invoke-WebRequest -Uri %GITHUB_URL% -Headers @{\"Cache-Control\"=\"no-cache\"} -TimeoutSec 5).Content" 2^>nul') do set "NEW_VERSION=%%A"
|
|
||||||
if not defined NEW_VERSION (
|
|
||||||
echo Error reading new version
|
|
||||||
goto :EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
:: Rewrite file
|
|
||||||
echo time: %CURRENT_TIMESTAMP%> %VERSION_FILE%
|
|
||||||
echo ver: %INSTALLED_VERSION%>> %VERSION_FILE%
|
|
||||||
echo skip: %SKIP_VERSION%>> %VERSION_FILE%
|
|
||||||
|
|
||||||
:: Comparing versions
|
|
||||||
if "%NEW_VERSION%"=="%INSTALLED_VERSION%" (
|
|
||||||
echo You are using the latest version %NEW_VERSION%.
|
|
||||||
goto :EOF
|
|
||||||
) else (
|
) else (
|
||||||
:: Check if version skipped
|
echo New version available: %GITHUB_VERSION%
|
||||||
if "%NEW_VERSION%"=="%SKIP_VERSION%" (
|
echo Release page: %GITHUB_RELEASE_URL%%GITHUB_VERSION%
|
||||||
echo Newer version %NEW_VERSION% skipped by user.
|
|
||||||
goto :EOF
|
set /p "CHOICE=Do you want to automatically download the new version? (y/n, default: y): "
|
||||||
) else (
|
|
||||||
echo New version found: %NEW_VERSION%.
|
if "!CHOICE!"=="" set "CHOICE=y"
|
||||||
echo Visit %RELEASE_URL% to download a new version
|
|
||||||
|
if /i "!CHOICE!"=="y" (
|
||||||
|
echo Opening the download page...
|
||||||
|
start "" "%GITHUB_DOWNLOAD_URL%%GITHUB_VERSION%.zip"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if not "%1"=="soft" pause
|
||||||
:: Skip check
|
endlocal
|
||||||
set /p "CHOICE=Skip this update? (y/n, default: n): " || set "CHOICE=n"
|
|
||||||
set "CHOICE=!CHOICE:~0,1!"
|
|
||||||
if /i "!CHOICE!"=="y" (
|
|
||||||
echo skip: %NEW_VERSION%>> %VERSION_FILE%
|
|
||||||
echo Update %NEW_VERSION% skipped.
|
|
||||||
) else (
|
|
||||||
start %RELEASE_URL%
|
|
||||||
)
|
|
||||||
|
|
||||||
endlocal
|
|
Loading…
Reference in New Issue
Block a user