From a8287c29ce7b395f32836117cf61132525f60ead Mon Sep 17 00:00:00 2001 From: NikkeDoy Date: Thu, 12 Dec 2024 03:14:15 +0200 Subject: [PATCH] :bug: | Fixed username change feature. --- ProfileManager.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/ProfileManager.py b/ProfileManager.py index 4905957..4c1352d 100644 --- a/ProfileManager.py +++ b/ProfileManager.py @@ -1,6 +1,7 @@ import os -default_profile_location = "./Mods/bf1942/Settings/Profiles" +default_settings_location = "./Mods/bf1942/Settings" +default_profile_location = default_settings_location + "/Profiles" default_profile = "FinnWarsLauncher" def check_directory_exists(directory_path): @@ -20,23 +21,42 @@ def change_username(username): if not os.path.exists(default_profile_location + "/" + default_profile + "/GeneralOptions.con"): print("GeneralOptions.con missing... Creating it!") try: - with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con") as file: + with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con", "w") as file: file.write(f"game.setPlayerName \"{username}\"") + file.close() except: print("GeneralOptions.con could not be created... error, obviously.") else: print("GeneralOptions.con found! Changing the name.") - with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con") as file: + with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con", "r") as file: lines = file.readlines() - if 0 < 2 <= len(lines): - lines[2] = "game.setPlayerName \"{username}\"" - file.writelines(lines) - try: - with open(default_profile_location + "/GeneralOptions.con") as file: - lines = file.readlines() + if 0 < 2 <= len(lines): + lines[2] = "game.setPlayerName \"{username}\"" + + with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con", "w") as file: + file.writelines(lines) + file.close() + + if not os.path.exists(default_settings_location + "/GeneralOptions.con"): + print("GeneralOptions.con from Profiles is missing... Creating it!") + try: + with open(default_settings_location + "/GeneralOptions.con", "w") as file: + file.write("rem ** NikkeDoy **\n") + file.write(f"run Profiles/{default_profile}/GeneralOptions.con") + file.close() + except: + print("GeneralOptions.con could not be created... error, obviously.") + else: + try: + with open(default_settings_location + "/GeneralOptions.con", "r") as file: + lines = file.readlines() + if 0 < 1 <= len(lines): lines[1] = f"run Profiles/{default_profile}/GeneralOptions.con" - file.writelines(lines) - except: - print(f"Couldn't set {default_profile} as default profile. Something is wrong.") + + with open(default_settings_location + "/GeneralOptions.con", "w") as file: + file.writelines(lines) + file.close() + except: + print(f"Couldn't set {default_profile} as default profile. Something is wrong.")