From e663b8a968f5b36a39d732e0a82c66507b7791cf Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sat, 9 Dec 2017 16:49:42 +0000 Subject: [PATCH 1/2] 3.2 Prevent issues handling the script when the name includes spaces. + Formatting. --- updater.bat | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/updater.bat b/updater.bat index 90a4080..2569b9e 100644 --- a/updater.bat +++ b/updater.bat @@ -39,11 +39,10 @@ IF DEFINED _updateb ( REM The normal flow here goes from phase 1 to phase 2 and then phase 3. IF NOT "!_myname:~0,9!"=="[updated]" ( IF EXIST "[updated]!_myname!.bat" ( - REM Phase 3 - REM The new script, with the original name, should: - REM Delete the [updated]*.bat script - REM Begin the normal script routine. - REN [updated]!_myname!.bat [updated]!_myname!.bat.old + REM ## Phase 3 ##: The new script, with the original name, will: + REM * Delete the [updated]*.bat script + REM * Begin the normal routine + REN "[updated]!_myname!.bat" "[updated]!_myname!.bat.old" DEL /F "[updated]!_myname!.bat.old" ECHO Script updated^^! ECHO. @@ -52,11 +51,10 @@ IF DEFINED _updateb ( ECHO. GOTO begin ) - REM Phase 1 - REM -updatebatch will: - REM Download new batch and name it [updated]*.bat - REM Open that script in a new CMD window. - REM Exit + REM ## Phase 1 ## + REM * Download new batch and name it [updated]*.bat + REM * Start that script in a new CMD window + REM * Exit ECHO Updating script... ECHO. REM Uncomment the next line and comment the powershell call for testing. @@ -79,14 +77,13 @@ IF DEFINED _updateb ( ECHO. TIMEOUT 300 >nul ) ELSE ( - REM Phase 2 - REM The [updated]*.bat script will: - REM Copy itself overwriting the original batch. - REM Start that script in a new CMD instance. - REM Exit. + REM ## Phase 2 ##: The [updated]*.bat script will: + REM * Copy itself overwriting the original batch + REM * Start that script in a new CMD instance + REM * Exit IF EXIST !_myname:~9!.bat ( - REN !_myname:~9!.bat !_myname:~9!.bat.old - DEL /F !_myname:~9!.bat.old + REN "!_myname:~9!.bat" "!_myname:~9!.bat.old" + DEL /F "!_myname:~9!.bat.old" ) COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat" START CMD /C "!_myname:~9!.bat" !_myparams! From 77ca6af2d943a1af53ebce59219c7a57d7f19731 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sun, 10 Dec 2017 01:20:39 +0000 Subject: [PATCH 2/2] I said 3.2. I'm not me if I don't miss something. --- updater.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updater.bat b/updater.bat index 2569b9e..a90c22a 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1 +REM ## version: 3.2 SET _myname=%~n0 SET _myparams=%* @@ -81,7 +81,7 @@ IF DEFINED _updateb ( REM * Copy itself overwriting the original batch REM * Start that script in a new CMD instance REM * Exit - IF EXIST !_myname:~9!.bat ( + IF EXIST "!_myname:~9!.bat" ( REN "!_myname:~9!.bat" "!_myname:~9!.bat.old" DEL /F "!_myname:~9!.bat.old" )