From 234157ab042a9a7a82c80185f1fcd422367b7424 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Fri, 10 Oct 2025 13:37:59 -0500 Subject: [PATCH] Test 2 --- GameUpdate.bat | 6 +- GameUpdate_linux.sh | 8 +-- .../patch-config.txt | 2 +- patch.bat => gameupdate/patch.bat | 58 +++++++++++-------- patch.sh => gameupdate/patch.sh | 54 +++++++++-------- 5 files changed, 70 insertions(+), 58 deletions(-) rename patch-config.txt => gameupdate/patch-config.txt (77%) rename patch.bat => gameupdate/patch.bat (52%) rename patch.sh => gameupdate/patch.sh (59%) diff --git a/GameUpdate.bat b/GameUpdate.bat index 76f5a6e..ab6b767 100644 --- a/GameUpdate.bat +++ b/GameUpdate.bat @@ -2,13 +2,13 @@ setlocal REM Copy GAMEUPDATE.bat to a new file -copy patch.bat patch2.bat +copy "gameupdate\patch.bat" "gameupdate\patch2.bat" REM Run the new file -call patch2.bat +call "gameupdate\patch2.bat" REM Delete the new file -del patch2.bat +del "gameupdate\patch2.bat" endlocal @echo on \ No newline at end of file diff --git a/GameUpdate_linux.sh b/GameUpdate_linux.sh index a2f617e..732096a 100644 --- a/GameUpdate_linux.sh +++ b/GameUpdate_linux.sh @@ -3,11 +3,11 @@ # Enable error handling set -e -# Copy patch.bat to a new file -cp patch.sh patch2.sh +# Copy patch.sh to a new file in gameupdate +cp "gameupdate/patch.sh" "gameupdate/patch2.sh" # Run the new file -bash patch2.sh +bash "gameupdate/patch2.sh" # Delete the new file -rm patch2.sh +rm "gameupdate/patch2.sh" diff --git a/patch-config.txt b/gameupdate/patch-config.txt similarity index 77% rename from patch-config.txt rename to gameupdate/patch-config.txt index b0dcf74..41d77e9 100644 --- a/patch-config.txt +++ b/gameupdate/patch-config.txt @@ -1,3 +1,3 @@ username=dazed-translations repo=exorcist-evangeline -branch=main \ No newline at end of file +branch=main diff --git a/patch.bat b/gameupdate/patch.bat similarity index 52% rename from patch.bat rename to gameupdate/patch.bat index 54f3c12..2613a89 100644 --- a/patch.bat +++ b/gameupdate/patch.bat @@ -1,6 +1,14 @@ @echo off setlocal EnableExtensions EnableDelayedExpansion +REM Determine important paths +set "SCRIPT_DIR=%~dp0" +set "ROOT_DIR=%CD%" +set "CONFIG_FILE=%SCRIPT_DIR%patch-config.txt" + +echo Using root directory: "%ROOT_DIR%" +echo Using config: "%CONFIG_FILE%" + echo Checking for pwsh... set _my_shell=pwsh @@ -27,15 +35,15 @@ if !errorlevel! neq 0 ( echo Using !_my_shell! for script execution. -REM Check if patch-config.txt exists -if not exist patch-config.txt ( - echo "Config file (patch-config.txt) not found! Assuming no patching needed." +REM Check if patch-config.txt exists in gameupdate folder +if not exist "%CONFIG_FILE%" ( + echo "Config file (gameupdate\patch-config.txt) not found! Assuming no patching needed." pause exit /b ) REM Read configuration from file -for /f "tokens=1,2 delims==" %%a in (patch-config.txt) do ( +for /f "usebackq tokens=1,2 delims==" %%a in ("%CONFIG_FILE%") do ( if "%%a"=="username" set "username=%%b" if "%%a"=="repo" set "repo=%%b" if "%%a"=="branch" set "branch=%%b" @@ -43,20 +51,20 @@ for /f "tokens=1,2 delims==" %%a in (patch-config.txt) do ( REM Get the latest hash echo "Getting latest commit SHA hash" -!_my_shell! -Command "(Invoke-RestMethod -Uri 'https://gitgud.io/api/v4/projects/%username%%%2F%repo%/repository/branches/%branch%').commit.id" > latest_patch_sha.txt +!_my_shell! -Command "(Invoke-RestMethod -Uri 'https://gitgud.io/api/v4/projects/%username%%%2F%repo%/repository/branches/%branch%').commit.id" > "%ROOT_DIR%\latest_patch_sha.txt" REM Read the latest SHA from the file -set /p latest_patch_sha= previous_patch_sha.txt +del "%ROOT_DIR%\repo.zip" +rmdir /s /q "%ROOT_DIR%\%repo%-%branch%" +del "%ROOT_DIR%\latest_patch_sha.txt" +REM Store latest SHA for next check in root +echo %latest_patch_sha% > "%ROOT_DIR%\previous_patch_sha.txt" endlocal pause exit /b diff --git a/patch.sh b/gameupdate/patch.sh similarity index 59% rename from patch.sh rename to gameupdate/patch.sh index 4898cdd..ea5c22f 100644 --- a/patch.sh +++ b/gameupdate/patch.sh @@ -1,5 +1,11 @@ #!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(pwd)" +CONFIG_FILE="$SCRIPT_DIR/patch-config.txt" + check_dependency() { if ! command -v "$1" > /dev/null 2>&1; then echo "Error: '$1' is not installed. Please install it using 'pkg install $1'." @@ -12,8 +18,6 @@ check_dependency jq check_dependency unzip check_dependency curl -CONFIG_FILE="patch-config.txt" - # Check if CONFIG_FILE exists if [ ! -f "$CONFIG_FILE" ]; then echo "Config file '$CONFIG_FILE' not found! Assuming no patching needed." @@ -24,63 +28,63 @@ fi sed -i 's/\r$//' "$CONFIG_FILE" # Debug information -echo "Current directory: $(pwd)" -echo "Config file path: $(pwd)/$CONFIG_FILE" +echo "Root directory: $ROOT_DIR" +echo "Config file path: $CONFIG_FILE" # Read configuration from file -. "$(pwd)/$CONFIG_FILE" +. "$CONFIG_FILE" # Get the latest hash echo "Getting latest commit SHA hash" latest_patch_sha=$(curl -s "https://gitgud.io/api/v4/projects/$username%2F$repo/repository/branches/$branch" | jq -r '.commit.id') download_extract() { - # Download zip file + # Download zip file into root echo "Downloading latest patch..." - curl -sL "https://gitgud.io/$username/$repo/-/archive/$branch/$repo-$branch.zip" -o repo.zip + curl -sL "https://gitgud.io/$username/$repo/-/archive/$branch/$repo-$branch.zip" -o "$ROOT_DIR/repo.zip" if [ $? -ne 0 ]; then echo "Download failed!" - rm -f repo.zip - rm -rf "$repo-$branch" + rm -f "$ROOT_DIR/repo.zip" + rm -rf "$ROOT_DIR/$repo-$branch" return 1 fi - # Extract contents, overwriting conflicts + # Extract contents, overwriting conflicts into root echo "Extracting..." - unzip -qo repo.zip + unzip -qo "$ROOT_DIR/repo.zip" -d "$ROOT_DIR" if [ $? -ne 0 ]; then echo "Extraction failed!" - rm -f repo.zip - rm -rf "$repo-$branch" + rm -f "$ROOT_DIR/repo.zip" + rm -rf "$ROOT_DIR/$repo-$branch" return 1 fi echo "Applying patch..." - cp -r "$repo-$branch/"* . + cp -r "$ROOT_DIR/$repo-$branch/"* "$ROOT_DIR/" if [ $? -ne 0 ]; then echo "Patch application failed!" - rm -f repo.zip - rm -rf "$repo-$branch" + rm -f "$ROOT_DIR/repo.zip" + rm -rf "$ROOT_DIR/$repo-$branch" return 1 fi echo "Cleaning up..." - rm repo.zip - rm -rf "$repo-$branch" - rm -f latest_patch_sha.txt + rm -f "$ROOT_DIR/repo.zip" + rm -rf "$ROOT_DIR/$repo-$branch" + rm -f "$ROOT_DIR/latest_patch_sha.txt" - # Store latest SHA for next check - echo "$latest_patch_sha" > previous_patch_sha.txt + # Store latest SHA for next check in root + echo "$latest_patch_sha" > "$ROOT_DIR/previous_patch_sha.txt" } -# Check if previous_patch_sha.txt exists -if [ ! -f previous_patch_sha.txt ]; then +# Check if previous_patch_sha.txt exists in root +if [ ! -f "$ROOT_DIR/previous_patch_sha.txt" ]; then echo "Previous SHA hash not found!" echo "Assuming first time patching..." download_extract else # Read the stored SHA from previous check - previous_patch_sha=$(cat previous_patch_sha.txt) + previous_patch_sha=$(cat "$ROOT_DIR/previous_patch_sha.txt") # Compare trimmed SHAs if [ "$latest_patch_sha" != "$previous_patch_sha" ]; then @@ -89,4 +93,4 @@ else else echo "Patch is up to date." fi -fi \ No newline at end of file +fi