Update updator.bat

This commit is contained in:
Draqoken
2025-04-10 00:54:52 +03:00
parent 3a4378a512
commit 9f5dab490e

View File

@@ -1,15 +1,16 @@
@echo off
setlocal
:: --------- Define Paths ---------
set "LOG_FILE=%~dp0update.log"
set "GIT_PORTABLE=%~dp0gitportable\bin\git.exe"
set "MAIN_REPO_DIR=%~dp0" :: The current folder is the main repo
set "SCRIPTS_REPO_URL=http://nathantech.net:3000/CosmicRage/VIPMudCosmicRageScripts.git" :: The main repo URL for scripts
set "SCRIPTS_TEMP_DIR=%MAIN_REPO_DIR%\temp_scripts" :: Temporary directory for cloning scripts
set "SOUNDS_DIR=%MAIN_REPO_DIR%sounds"
set "SOUNDS_REPO_URL=https://nathantech.net:3000/CosmicRage/CosmicRageSounds.git"
set "REPO_SUBFOLDER=wav"
:: --------- Define Paths (without trailing backslashes) ---------
set "BASE_DIR=%~dp0"
set "BASE_DIR=%BASE_DIR:~0,-1%"
set "LOG_FILE=%BASE_DIR%\update.log"
set "GIT_PORTABLE=%BASE_DIR%\gitportable\bin\git.exe"
set "MAIN_REPO_DIR=%BASE_DIR%"
set "SCRIPTS_TEMP_DIR=%BASE_DIR%\temp_scripts"
set "SOUNDS_DIR=%BASE_DIR%\sounds"
set "REPO_SUBFOLDER=wav"
:: --------- Setup Log ---------
echo [%DATE% %TIME%] Starting update process... > "%LOG_FILE%"
@@ -26,12 +27,23 @@ if not exist "%GIT_PORTABLE%" (
exit /b
)
:: --------- Attempt to Pull from Main Repo or Clone if Failed ---------
echo [%DATE% %TIME%] Attempting to pull updates from the main repo... >> "%LOG_FILE%"
"%GIT_PORTABLE%" -C "%MAIN_REPO_DIR%" pull >> "%LOG_FILE%" 2>&1
if errorlevel 1 (
echo [%DATE% %TIME%] ERROR: Git pull failed. Cloning repo instead... >> "%LOG_FILE%"
goto clone_repo
) else (
echo [%DATE% %TIME%] Git pull successful or no updates found. >> "%LOG_FILE%"
goto pull_sounds
)
:clone_repo
:: --------- Clone the Main Repo into Temporary Directory ---------
if exist "%SCRIPTS_TEMP_DIR%" (
echo [%DATE% %TIME%] Deleting existing temporary scripts directory... >> "%LOG_FILE%"
rd /s /q "%SCRIPTS_TEMP_DIR%" >nul 2>&1
)
echo [%DATE% %TIME%] Cloning main repo into temporary directory... >> "%LOG_FILE%"
"%GIT_PORTABLE%" clone "%SCRIPTS_REPO_URL%" "%SCRIPTS_TEMP_DIR%" >> "%LOG_FILE%" 2>&1
if errorlevel 1 (
@@ -41,14 +53,25 @@ if errorlevel 1 (
exit /b
)
:: --------- Replace Files in the Main Directory ---------
echo [%DATE% %TIME%] Replacing files in the main directory... >> "%LOG_FILE%"
:: --------- Replace Files in the Main Directory (Safe Copy) ---------
echo [%DATE% %TIME%] Preparing to copy files... >> "%LOG_FILE%"
set "SRC_DIR=%~dp0temp_scripts"
set "DEST_DIR=%~dp0"
echo SRC_DIR: [%SRC_DIR%] >> "%LOG_FILE%"
echo DEST_DIR: [%DEST_DIR%] >> "%LOG_FILE%"
:: Use robocopy to copy all files and subdirectories from temp to main repo directory
robocopy "%SCRIPTS_TEMP_DIR%" "%MAIN_REPO_DIR%" /E /PURGE >> "%LOG_FILE%" 2>&1
if errorlevel 1 (
echo [%DATE% %TIME%] ERROR: Robocopy failed to copy files. >> "%LOG_FILE%"
echo ERROR: Robocopy failed to copy files. Check the log for details.
if not exist "%SRC_DIR%" (
echo [%DATE% %TIME%] ERROR: Source directory does not exist: %SRC_DIR% >> "%LOG_FILE%"
exit /b
)
if not exist "%DEST_DIR%" (
echo [%DATE% %TIME%] ERROR: Destination directory does not exist: %DEST_DIR% >> "%LOG_FILE%"
exit /b
)
robocopy "%SRC_DIR%" "%DEST_DIR%" /E /COPY:DAT /XO >> "%LOG_FILE%" 2>&1
if errorlevel 8 (
echo [%DATE% %TIME%] ERROR: Robocopy failed. Exit code: %errorlevel% >> "%LOG_FILE%"
pause
exit /b
)
@@ -56,6 +79,7 @@ if errorlevel 1 (
:: --------- Clean Up Temporary Directory ---------
rd /s /q "%SCRIPTS_TEMP_DIR%" >nul 2>&1
:pull_sounds
:: --------- Pull Updates for Sounds Repo ---------
if exist "%SOUNDS_DIR%" (
echo [%DATE% %TIME%] Pulling updates for the sounds repository... >> "%LOG_FILE%"
@@ -72,4 +96,4 @@ if exist "%SOUNDS_DIR%" (
:: --------- Final Logging ---------
echo [%DATE% %TIME%] Update process completed. >> "%LOG_FILE%"
pause
exit /b
exit /b