diff --git a/.gitignore b/.gitignore index 79f9c00..5cbd5b0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ src/build/ *.exe __pycache__/ /dist/ -/build/ \ No newline at end of file +/build/ +hoi4-presence*/ +*.zip \ No newline at end of file diff --git a/build.spec b/build.spec index 59abedd..66f3038 100644 --- a/build.spec +++ b/build.spec @@ -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...") @@ -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!") diff --git a/src/setup.py b/src/setup.py index 4d53a47..d4e9322 100644 --- a/src/setup.py +++ b/src/setup.py @@ -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() diff --git a/src/uninstall.py b/src/uninstall.py new file mode 100644 index 0000000..3013fc5 --- /dev/null +++ b/src/uninstall.py @@ -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()