From 4fd410ff3bc3bffecfea9de5a544ab0b9bed944c Mon Sep 17 00:00:00 2001
From: junior <46103377+juniorsgithub@users.noreply.github.com>
Date: Mon, 19 Oct 2020 15:02:52 +0200
Subject: [PATCH 1/4] add update script
---
scripts/update-nohats.cmd | 97 +++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
create mode 100644 scripts/update-nohats.cmd
diff --git a/scripts/update-nohats.cmd b/scripts/update-nohats.cmd
new file mode 100644
index 00000000..d0251ea1
--- /dev/null
+++ b/scripts/update-nohats.cmd
@@ -0,0 +1,97 @@
+:: NO HATS MOD UPDATE SCRIPT
+:: for https://github.com/Fedora31/no-hats-bgum
+
+:: Checks which VPKs you have installed,
+:: compares their last modified date with the latest github commit,
+:: and downloads ones that are out of date.
+
+:: made by junior
+:: ---------------------------------------------------
+
+@echo off
+setlocal
+setlocal EnableDelayedExpansion
+title No Hats Mod Update Script
+
+call :setESC
+
+echo %ESC%[7m No Hats Mod Update Script %ESC%[0m
+echo https://github.com/Fedora31/no-hats-bgum
+echo.
+
+:: Check curl.
+where /Q curl
+IF NOT %ERRORLEVEL% EQU 0 (
+ echo %ESC%[101;93m ERROR %ESC%[0m %ESC%[32mcurl%ESC%[0m not found
+ goto :exit
+)
+
+:: Check jq.
+where /Q jq
+IF %ERRORLEVEL% EQU 0 (
+ set jq=jq
+ call :main
+) else (
+ echo %ESC%[32mjq%ESC%[0m not found, a temporary copy will be downloaded...%ESC%[90m
+ curl -L "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-win64.exe" ^
+ -o "%TEMP%\jq.exe"
+ echo.
+ set "jq=%TEMP%\jq.exe"
+ call :main
+ del /q "%TEMP%\jq.exe"
+)
+
+goto :exit
+:: ----------------------------------------------------
+
+:setESC
+:: https://gist.github.com/mlocati/fdabcaeb8071d5c75a2d51712db24011
+for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
+ set ESC=%%b
+ exit /B 0
+)
+
+:main
+set files[0]=no_hats_bgum.vpk
+set files[1]=no_bugged_misc.vpk
+set files[2]=no_hats_creatorstf.vpk
+set files[3]=no_unusuals.vpk
+set files[4]=no_christmas_lights.vpk
+set files[5]=no_skins.vpk
+set files[6]=no_botkiller.vpk
+
+for /l %%i in (0,1,6) do (
+ echo %ESC%[0m%ESC%[7m !files[%%i]! %ESC%[0m
+ if exist !files[%%i]! (
+ call :update !files[%%i]!
+ ) else (
+ echo Not found.
+ )
+)
+exit /B 0
+
+:update
+:: Get last modified time.
+for /f "tokens=*" %%a in ('forfiles /M %~1 /C "cmd /c echo @fdate"') do set "LastModified=%%a"
+echo downloaded: %LastModified:~0,10%
+set "LastModified=%LastModified:~0,4%%LastModified:~5,2%%LastModified:~8,2%"
+
+:: Get last commit time.
+for /f "tokens=*" %%a in ('curl -s "https://api.github.com/repos/Fedora31/no-hats-bgum/commits?path=%~1" ^| "%jq%" -r ".[0].commit.committer.date"') do set "LastCommit=%%a"
+echo lastest version: %LastCommit:~0,10%
+set "LastCommit=%LastCommit:~0,4%%LastCommit:~5,2%%LastCommit:~8,2%"
+
+if %LastCommit% GTR %LastModified% (
+ echo Downloading...%ESC%[90m
+ curl "https://raw.githubusercontent.com/Fedora31/no-hats-bgum/master/%~1" -o %~1
+ echo %ESC%[0mDone.
+) else (
+ echo Up to date.
+)
+exit /B 0
+
+:exit
+echo.
+echo Press any key to exit...
+pause > nul
+exit /B 0
From 899d10e0bcd13384a245cc5d40a793060fb226f9 Mon Sep 17 00:00:00 2001
From: junior <46103377+juniorsgithub@users.noreply.github.com>
Date: Mon, 19 Oct 2020 15:18:35 +0200
Subject: [PATCH 2/4] add update script readme
---
.github/UPDATE_SCRIPT.md | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 .github/UPDATE_SCRIPT.md
diff --git a/.github/UPDATE_SCRIPT.md b/.github/UPDATE_SCRIPT.md
new file mode 100644
index 00000000..0d7910e9
--- /dev/null
+++ b/.github/UPDATE_SCRIPT.md
@@ -0,0 +1,12 @@
+# Update Script
+Checks which VPKs you have installed,
+compares their last modified date with the latest github commit,
+and downloads ones that are out of date.
+
+## How to
+1. [Download]() and save it to your `custom` folder next to the nohats VPKs.
+2. Run it after a new update comes.
+
+## Notes
+- Windows 10 only
+- It will fail if you have TF2 open
From b484663590fd2d106777471b1844b6b60b2d9967 Mon Sep 17 00:00:00 2001
From: junior <46103377+juniorsgithub@users.noreply.github.com>
Date: Mon, 19 Oct 2020 20:21:03 +0200
Subject: [PATCH 3/4] localization independent
---
scripts/update-nohats.cmd | 59 ++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 7 deletions(-)
diff --git a/scripts/update-nohats.cmd b/scripts/update-nohats.cmd
index d0251ea1..8a7ebb1a 100644
--- a/scripts/update-nohats.cmd
+++ b/scripts/update-nohats.cmd
@@ -1,3 +1,5 @@
+
+
+
+
+
+
+
From da65569f9a767e8be54680a253f1dfb4e8b9f586 Mon Sep 17 00:00:00 2001
From: junior <46103377+juniorsgithub@users.noreply.github.com>
Date: Tue, 20 Oct 2020 12:11:46 +0200
Subject: [PATCH 4/4] my tester fd up
---
scripts/update-nohats.cmd | 96 +++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 43 deletions(-)
diff --git a/scripts/update-nohats.cmd b/scripts/update-nohats.cmd
index 8a7ebb1a..f7623aa4 100644
--- a/scripts/update-nohats.cmd
+++ b/scripts/update-nohats.cmd
@@ -1,4 +1,4 @@
-
-
-
-
-
-
-
+:: ------------------------------------------------
+:: --- END OF BATCH --- */
+
+// START OF JSCRIPT
+
+if (WScript.Arguments.length == 1) {
+ getLastModifiedTime(WScript.Arguments(0));
+} else if (WScript.Arguments.length == 2) {
+ compareDates(WScript.Arguments(0), WScript.Arguments(1));
+} else {
+ WScript.Quit(0);
+}
+
+function compareDates(d1, d2) {
+ d1 = d1.substring(5, 10) + "-" + d1.substring(0, 4) + " " + d1.substring(11, 19)
+ d1 = Date.parse(d1)
+
+ d2 = d2.substring(5, 10) + "-" + d2.substring(0, 4) + " " + d2.substring(11, 19)
+ d2 = Date.parse(d2)
+
+ WScript.Quit(d2 > d1 ? 1 : 0)
+
+ function parse(string, start, end) {
+ return parseInt(
+ string.substring(start, end));
+ }
+}
+
+function getLastModifiedTime(file) {
+
+ d = new Date(
+ new ActiveXObject("Scripting.FileSystemObject")
+ .GetFile(WScript.Arguments(0))
+ .DateLastModified);
+ WScript.Echo(
+ d.getFullYear() + "-" +
+ pad(d.getMonth() + 1) + "-" +
+ pad(d.getDate()) + "T" +
+ pad(d.getHours()) + ":" +
+ pad(d.getMinutes()) + ":" +
+ pad(d.getSeconds()) + "Z"
+ );
+
+ function pad(i){
+ return i.toString().length == 1 ? ("0" + i) : i.toString()
+ }
+}