diff --git a/app/settings.py b/app/settings.py index 74819bdf..c430cad5 100644 --- a/app/settings.py +++ b/app/settings.py @@ -39,8 +39,6 @@ class Defaults(Enum): def get_settings(): - os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) - if not os.path.isfile(CONFIG_FILE) or os.stat(CONFIG_FILE).st_size == 0: write_settings(get_default_settings()) @@ -77,6 +75,7 @@ def get_default_transcoding_presets(): def write_settings(config): + os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) with open(CONFIG_FILE, "w") as config_file: json.dump(config, config_file, indent=" ") @@ -125,6 +124,10 @@ class SettingsException(Exception): pass +class SettingsReadException(SettingsException): + pass + + class PlayStreamsMode(IntEnum): """ Behavior mode when opening streams. """ BUILT_IN = 0 @@ -137,7 +140,10 @@ class Settings: __VERSION = 1 def __init__(self, ext_settings=None): - settings = ext_settings or get_settings() + try: + settings = ext_settings or get_settings() + except PermissionError as e: + raise SettingsReadException(e) if self.__VERSION > settings.get("version", 0): raise SettingsException("Outdated version of the settings format!") diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 61183829..212e9f60 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -16,7 +16,7 @@ from app.eparser.ecommons import CAS, Flag, BouquetService from app.eparser.enigma.bouquets import BqServiceType from app.eparser.iptv import export_to_m3u from app.eparser.neutrino.bouquets import BqType -from app.settings import SettingsType, Settings, SettingsException, PlayStreamsMode +from app.settings import SettingsType, Settings, SettingsException, PlayStreamsMode, SettingsReadException from app.tools.media import Player, Recorder, HttpPlayer from app.ui.epg_dialog import EpgDialog from app.ui.transmitter import LinksTransmitter @@ -2715,6 +2715,9 @@ class Application(Gtk.Application): def start_app(): try: Settings.get_instance() + except SettingsReadException as e: + msg = "{}\n {}".format(get_message("Error reading or writing program settings!"), e) + show_dialog(DialogType.INFO, transient=Gtk.Dialog(), text=msg) except SettingsException as e: msg = "{} \n{}".format(e, get_message("All setting were reset. Restart the program!")) show_dialog(DialogType.INFO, transient=Gtk.Dialog(), text=msg)