Skip to content

Commit

Permalink
Merge pull request #30 from Wolfmyths/test-branch
Browse files Browse the repository at this point in the history
Adds uninstaller, fix a bug and adjust some things. Fix #3
  • Loading branch information
ThiaudioTT authored Aug 19, 2023
2 parents 105aeec + e49b13d commit 8eb06fd
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ src/build/
*.exe
__pycache__/
/dist/
/build/
/build/
hoi4-presence*/
*.zip
39 changes: 39 additions & 0 deletions build.spec
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,44 @@ setup_exe = EXE(
entitlements_file=None,
)

uninstall_a = Analysis(
['src/uninstall.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
uninstall_pyz = PYZ(uninstall_a.pure, uninstall_a.zipped_data, cipher=block_cipher)
uninstall_exe = EXE(
uninstall_pyz,
uninstall_a.scripts,
uninstall_a.binaries,
uninstall_a.zipfiles,
uninstall_a.datas,
[],
name='uninstall',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)

# script to bundle

print("Starting to bundle...")
Expand Down Expand Up @@ -171,5 +209,6 @@ with zipfile.ZipFile("hoi4-presence-v" + version + ".zip", "w") as zip:
zip.write("dist/discordRPC/version.json", "./discordRPC/dist/version.json")
# zip.write("README.txt", "./README.txt")
zip.write("dist/setup.exe", "./setup.exe")
zip.write("dist/uninstall.exe", "./uninstall.exe")

print("Done!")
2 changes: 1 addition & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@

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

Expand Down
81 changes: 81 additions & 0 deletions src/uninstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
import shutil
import time
import sys
import json

print("This script will uninstall the hoi4-presence in your game/save path\nPress enter to continue...")
input()

# Find save data
documents = os.environ['USERPROFILE'] + "\\Documents\\Paradox Interactive\\Hearts of Iron IV"
while True:
try:
if 'settings.txt' not in os.listdir(documents):
raise Exception(f"Could not find 'settings.txt' in '{documents}'")
else:
print('Documents directory found')
break
except Exception as e:
print(e)
errorType = 'documents path' if str(e).startswith('[WinError 3]') else "'settings.txt'"

documents = input(f"Can't find {errorType}, please enter the path manually: ")

# Revert settings.txt
try:
print("Writing save_as_binary=yes in settings.txt...")
with open(documents + "\\settings.txt", "r") as f:
settings = f.read()
settings = settings.replace('save_as_binary=no', 'save_as_binary=yes')
with open(documents + "\\settings.txt", "w") as f:
f.write(settings)
except Exception as e:
print(e)
print("Can't revert settings.txt\nExiting...")
time.sleep(3)
sys.exit()

# Find game directory
gameFolder = os.environ['PROGRAMFILES(X86)'] + "\\Steam\\steamapps\\common\\Hearts of Iron IV"
while True:
try:
if "hoi4.exe" not in os.listdir(gameFolder):
raise Exception(f"Could not find 'hoi4.exe' in '{gameFolder}'")
else:
print('Game directory found')
break
except Exception as e:
print(e)
errorType = "game folder path" if str(e).startswith('[WinError 3]') else "'hoi4.exe'"

gameFolder = input(f"Can't find {errorType}, please enter the path manually: ")

# Revert launcher-settings.json
try:
print("Changing launcher-settings.json...")
with open(gameFolder + "\\launcher-settings.json", "r") as f:
launcher = json.load(f)
launcher["exePath"] = "hoi4.exe"
with open(gameFolder + "\\launcher-settings.json", "w") as f:
json.dump(launcher, f, indent=4)
except Exception as e:
print(e)
print("Can't revert launcher-settings.json\nExiting...")
time.sleep(3)
sys.exit()

# Delete hoi4Presence and runRPC.bat
try:
print("Deleting rich presence")
shutil.rmtree(os.path.join(documents, "hoi4Presence"))
os.remove(os.path.join(gameFolder, "runRPC.bat"))
except Exception as e:
print(str(e))
print("Could not delete rich presence, exiting...")
time.sleep(3)
sys.exit()

print("Uninstalled!\nPress 'Enter' or close this window.")
time.sleep(4)
input()

0 comments on commit 8eb06fd

Please sign in to comment.