Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify if required files are in /dist/ and removed pathlib dependency #24

Merged
merged 7 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}