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 5 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/discordRPC/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"OBS:": "THIS IS A TEST VERSION ONLY FOR DELEVOPING PURPOSES",
"version": "0.1.0",
"version": "0.3.0",
ThiaudioTT marked this conversation as resolved.
Show resolved Hide resolved
"auto-update": false,
"date": "23-sep-2022"
}
69 changes: 63 additions & 6 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,67 @@
# 5 - Success message (or failed)
# 6 - ask the user delete the folder and exit

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

print("Verifying required files...")

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

batchFolderPath = os.path.join(os.path.abspath(os.curdir), "batch")

batchPath = os.path.join(batchFolderPath, "runRPC.bat")

# Testing if the batch folder exists, will raise an exception if it doesn't
os.listdir(batchFolderPath)

# Checking if runRPC.bat exists
batchNotFound = not os.path.exists(batchPath)

# If any files are needed within the /dist/ folder, add them here
requiredFiles = ("checkupdate.exe", "hoi4Presence.exe", "version.json")
ThiaudioTT marked this conversation as resolved.
Show resolved Hide resolved
filesNotFound = []

# Checking if the required files are in /dist/
with os.listdir(source) as distContents:
ThiaudioTT marked this conversation as resolved.
Show resolved Hide resolved
for file in requiredFiles:

if file not in distContents:

filesNotFound.append(file)

# If there is an item in filesNotFound or batchNotFound returns true
if batchNotFound or 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).endswith("batch'"):

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

elif str(e) == "filesNotFound":

if batchNotFound:
print(f"\nError: 'runRPC.bat' was not found in {batchFolderPath}\n\n")

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

else:

print(e)

print('\nExiting...')

time.sleep(10)
sys.exit()

# 1
documents = os.environ['USERPROFILE'] + "\\Documents\\Paradox Interactive\\Hearts of Iron IV"
Expand All @@ -44,7 +102,7 @@
print("Updating the runRPC.bat...\n")
if documents != os.environ['USERPROFILE'] + "\\Documents\\Paradox Interactive\\Hearts of Iron IV":
try:
batchPath = ".\\batch\\runRPC.bat"

with open(batchPath, 'r') as file:
lines = file.readlines()

Expand All @@ -69,7 +127,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,7 +169,7 @@
print("Moving runRPC.bat to the game folder...")
print(gameFolder)

file = Path(__file__).parent.resolve() / "batch/runRPC.bat"
file = os.path.join(os.path.abspath(os.curdir), "batch\\runRPC.bat")
shutil.copyfile(file, gameFolder + "\\runRPC.bat")
except Exception as e:
print(e)
Expand Down