diff --git a/Client/profile_save.py b/Client/profile_save.py index 689d0de..0f08b92 100644 --- a/Client/profile_save.py +++ b/Client/profile_save.py @@ -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) @@ -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: @@ -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") \ No newline at end of file