109 lines
4.0 KiB
Batchfile
109 lines
4.0 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
:: --------- 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"
|
|
set "SCRIPTS_REPO_URL=http://nathantech.net:3000/CosmicRage/VIPMudCosmicRageScripts.git"
|
|
set "SOUNDS_REPO_URL=https://nathantech.net:3000/CosmicRage/CosmicRageSounds.git"
|
|
|
|
:: --------- Setup Log ---------
|
|
echo [%DATE% %TIME%] Starting update process... > "%LOG_FILE%"
|
|
echo [%DATE% %TIME%] GitPortable: %GIT_PORTABLE% >> "%LOG_FILE%"
|
|
echo [%DATE% %TIME%] Main repository directory: %MAIN_REPO_DIR% >> "%LOG_FILE%"
|
|
echo [%DATE% %TIME%] Sounds directory: %SOUNDS_DIR% >> "%LOG_FILE%"
|
|
echo [%DATE% %TIME%] Temporary scripts directory: %SCRIPTS_TEMP_DIR% >> "%LOG_FILE%"
|
|
|
|
:: --------- Determine which Git to use ---------
|
|
set "GIT_CMD="
|
|
where git >nul 2>nul
|
|
if %errorlevel%==0 (
|
|
set "GIT_CMD=git"
|
|
echo [%DATE% %TIME%] Git found in PATH. >> "%LOG_FILE%"
|
|
) else if exist "%GIT_PORTABLE%" (
|
|
set "GIT_CMD=%GIT_PORTABLE%"
|
|
echo [%DATE% %TIME%] Git not found in PATH, using GitPortable. >> "%LOG_FILE%"
|
|
) else (
|
|
echo [%DATE% %TIME%] ERROR: Git not found in PATH or at %GIT_PORTABLE% >> "%LOG_FILE%"
|
|
echo ERROR: Git not found in PATH or at %GIT_PORTABLE%
|
|
pause
|
|
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_CMD% -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_CMD%" clone "%SCRIPTS_REPO_URL%" "%SCRIPTS_TEMP_DIR%" >> "%LOG_FILE%"
|
|
if errorlevel 1 (
|
|
echo [%DATE% %TIME%] ERROR: Git clone failed for main scripts repo. >> "%LOG_FILE%"
|
|
echo ERROR: Failed to clone the main scripts repo. Check network or GitPortable version.
|
|
pause
|
|
exit /b
|
|
)
|
|
|
|
:: --------- 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%"
|
|
|
|
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%" %~dp0 /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
|
|
)
|
|
|
|
:: --------- 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%"
|
|
"%GIT_CMD%" -C "%SOUNDS_DIR%" pull >> "%LOG_FILE%"
|
|
if errorlevel 1 (
|
|
echo [%DATE% %TIME%] ERROR: Failed to pull updates for the sounds repository. >> "%LOG_FILE%"
|
|
echo ERROR: Failed to pull updates for the sounds repository. Check the log for details.
|
|
)
|
|
) else (
|
|
echo [%DATE% %TIME%] ERROR: Sounds directory not found at %SOUNDS_DIR% >> "%LOG_FILE%"
|
|
echo ERROR: Sounds directory not found at %SOUNDS_DIR%.
|
|
)
|
|
|
|
:: --------- Final Logging ---------
|
|
echo [%DATE% %TIME%] Update process completed. >> "%LOG_FILE%"
|
|
pause
|
|
exit /b |