summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/config.py
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-01-13 16:26:33 +0100
committerRobert Honz <exislow+github@gmail.com>2024-01-13 16:26:33 +0100
commitb59cba77c3769f193201b735341adc5aff05ac1a (patch)
tree2edd2f72bd0eb3745427eea5f40b841d4cbdd11f /tidal_dl_ng/config.py
parentdd8833add888412ff192d9a61466c8c16c3939e2 (diff)
downloadtidal-dl-ng-b59cba77c3769f193201b735341adc5aff05ac1a.tar.gz
♻️ Refactoring of download.py ongoing.
Diffstat (limited to 'tidal_dl_ng/config.py')
-rw-r--r--tidal_dl_ng/config.py16
1 files changed, 15 insertions, 1 deletions
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.