Skip to content

Commit

Permalink
Merge pull request #19 from TINF21CS1/directory-fix
Browse files Browse the repository at this point in the history
Directory fix
  • Loading branch information
HOOK-Hawkins authored Mar 18, 2024
2 parents fe86724 + 2137cdc commit 61760dc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Client/profile_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_profiles():
This method returns all the profiles from the file
:return: An array of all profiles
"""
Profile._check_folder()
if exists(path):
with open(path, 'r') as file:
data = json.load(file)
Expand All @@ -32,6 +33,7 @@ def get_profiles():

@staticmethod
def set_profiles(players: list, selected: int):
Profile._check_folder()
with open(path, 'w+') as file:
entry = []
for player in players:
Expand All @@ -43,6 +45,16 @@ def delete_all_profiles():
"""
This method deletes all profiles
"""
Profile._check_folder()
if exists(path):
with open(path, 'w') as file:
file.write("[]")

@staticmethod
def _check_folder():
dir = os.path.abspath('Client/Data/')
if not os.path.exists(os.path.abspath(dir)):
try:
os.makedirs(os.path.abspath(dir))
except OSError:
raise OSError(f"Creation of the directory {dir} failed")

0 comments on commit 61760dc

Please sign in to comment.