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

Adds uninstaller, fix a bug and adjust some things. Fix #3 #30

Merged
merged 4 commits into from
Aug 19, 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
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.")
Wolfmyths marked this conversation as resolved.
Show resolved Hide resolved
time.sleep(4)
input()