🐛 | Fixed username change feature.
Some checks are pending
Gitea Action Test / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
NikkeDoy 2024-12-12 03:14:15 +02:00
parent 97cb856212
commit a8287c29ce

View File

@ -1,6 +1,7 @@
import os 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" default_profile = "FinnWarsLauncher"
def check_directory_exists(directory_path): 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"): if not os.path.exists(default_profile_location + "/" + default_profile + "/GeneralOptions.con"):
print("GeneralOptions.con missing... Creating it!") print("GeneralOptions.con missing... Creating it!")
try: 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.write(f"game.setPlayerName \"{username}\"")
file.close()
except: except:
print("GeneralOptions.con could not be created... error, obviously.") print("GeneralOptions.con could not be created... error, obviously.")
else: else:
print("GeneralOptions.con found! Changing the name.") 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() lines = file.readlines()
if 0 < 2 <= len(lines):
lines[2] = "game.setPlayerName \"{username}\""
file.writelines(lines)
try: if 0 < 2 <= len(lines):
with open(default_profile_location + "/GeneralOptions.con") as file: lines[2] = "game.setPlayerName \"{username}\""
lines = file.readlines()
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): if 0 < 1 <= len(lines):
lines[1] = f"run Profiles/{default_profile}/GeneralOptions.con" lines[1] = f"run Profiles/{default_profile}/GeneralOptions.con"
file.writelines(lines)
except: with open(default_settings_location + "/GeneralOptions.con", "w") as file:
print(f"Couldn't set {default_profile} as default profile. Something is wrong.") file.writelines(lines)
file.close()
except:
print(f"Couldn't set {default_profile} as default profile. Something is wrong.")