Skip to content

Commit

Permalink
Merge pull request #24 from Wolfmyths/main
Browse files Browse the repository at this point in the history
Verify if required files are in /dist/ and removed pathlib dependency
  • Loading branch information
ThiaudioTT authored Jul 8, 2023
2 parents aef333b + 8ae3d47 commit 2a4a14f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/batch/runRPC.bat → src/discordRPC/runRPC.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set "documentsPath=C:\Users\%USERNAME%\Documents\Paradox Interactive\Hearts of I
@REM This is file for executing the game and the presence, delete if you have uninstalled and change launcher-settings.json

echo "starting hoi4RPC..."
start "hoi4.exe" "./hoi4.exe"
start "hoi4.exe" ".\hoi4.exe"

@REM Start checkupdate
start "checkupdate.exe" "%documentsPath%\hoi4Presence\checkupdate.exe"
Expand Down
51 changes: 44 additions & 7 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import time
import sys
import json
from pathlib import Path
# TODO: remove pathlib dependency to compile in onefile.
# TODO: verify if all files are included in /dist/ folder. (like version.json)

print("This script will install the hoi4-presence in your game/save path\nPress enter to continue...")
input()
Expand All @@ -24,6 +21,48 @@
# 5 - Success message (or failed)
# 6 - ask the user delete the folder and exit

# Verifying if all required files are included in /dist/
try:

print("Verifying required files...")

source = os.path.join(os.path.abspath(os.curdir), "discordRPC\\dist")

# If any files are needed within the /dist/ folder, add them here
requiredFiles = ("checkupdate.exe", "hoi4Presence.exe", "version.json", "runRPC.bat")
filesNotFound = []

# Checking if the required files are in /dist/
for file in os.listdir(source):

if file not in requiredFiles:

filesNotFound.append(file)

# If there is an item in filesNotFound
if filesNotFound:
raise Exception("filesNotFound")

print("All required files are valid!")

except Exception as e:

if str(e).endswith("dist'"):

print(f"Error: Could not find 'dist' directory\n{source}")

elif str(e) == "filesNotFound":

print(f"\nError: The following files were not found in {source}:\n\n{', '.join(filesNotFound)}\n")

else:

print(f'Error: {e}')

print('\nExiting...')

time.sleep(10)
sys.exit()

# 1
documents = os.environ['USERPROFILE'] + "\\Documents\\Paradox Interactive\\Hearts of Iron IV"
Expand All @@ -44,7 +83,7 @@
print("Updating the runRPC.bat...\n")
if documents != os.environ['USERPROFILE'] + "\\Documents\\Paradox Interactive\\Hearts of Iron IV":
try:
batchPath = ".\\batch\\runRPC.bat"
batchPath = os.path.join(source, "runRPC.bat")
with open(batchPath, 'r') as file:
lines = file.readlines()

Expand All @@ -69,7 +108,6 @@
print(documents)
print(documents + "\\hoi4Presence")

source = Path(__file__).parent.resolve() / "discordRPC/dist"
shutil.copytree(source, documents + "\\hoi4Presence")
except Exception as e:
print(e)
Expand Down Expand Up @@ -112,8 +150,7 @@
print("Moving runRPC.bat to the game folder...")
print(gameFolder)

file = Path(__file__).parent.resolve() / "batch/runRPC.bat"
shutil.copyfile(file, gameFolder + "\\runRPC.bat")
shutil.copyfile(batchPath, gameFolder + "\\runRPC.bat")
except Exception as e:
print(e)
print("Can't move the runRPC.bat to the game folder\nExiting...")
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.1",
"version": "0.3.0",
"auto-update": false,
"date": "20-may-2023"
}

0 comments on commit 2a4a14f

Please sign in to comment.