From b59cba77c3769f193201b735341adc5aff05ac1a Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Sat, 13 Jan 2024 16:26:33 +0100 Subject: ♻️ Refactoring of download.py ongoing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/config.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tidal_dl_ng/config.py') diff --git a/tidal_dl_ng/config.py b/tidal_dl_ng/config.py index 0906655..4432d3c 100644 --- a/tidal_dl_ng/config.py +++ b/tidal_dl_ng/config.py @@ -1,3 +1,5 @@ +import os +import shutil from collections.abc import Callable from json import JSONDecodeError from typing import Any @@ -34,7 +36,19 @@ class BaseConfig: self.data = self.cls_model.from_json(settings_json) result = True - except (JSONDecodeError, TypeError, FileNotFoundError): + except (JSONDecodeError, TypeError, FileNotFoundError, ValueError) as e: + if isinstance(e, ValueError): + path_bak = path + ".bak" + + # First check if a backup file already exists. If yes, remove it. + if os.path.exists(path_bak): + os.remove(path_bak) + + # Move the invalid config file to the backup location. + shutil.move(path, path_bak) + # TODO: Implement better global logger. + print(f"Something is wrong with your config. Maybe it is not compatible anymore due to a new app version. You can find a backup of your old config here: '{path_bak}'. A new default config was created.") + self.data = self.cls_model() # Call save in case of we need to update the saved config, due to changes in code. -- cgit v1.3.1