import os default_profile_location = "./Mods/bf1942/Settings/Profiles" default_profile = "FinnWarsLauncher" def check_directory_exists(directory_path): return os.path.isdir(directory_path) def change_username(username): if not os.path.exists(default_profile_location): print("Launcher is not installed correctly!") print("Please, move finnwarslauncher.exe to the same folder as bf1942.exe!!!") print("Thanks! :)") return if not os.path.exists(default_profile_location + "/" + default_profile): print("Profile not found... Creating \"FinnWarsLauncher\"-profile!") os.makedirs("./Mods/bf1942/Settings/Profiles/FinnWarsLauncher") 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: file.write(f"game.setPlayerName \"{username}\"") 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: 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 < 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.")