From 253b9cc87dd73ccf98aa667c898e036df016365c Mon Sep 17 00:00:00 2001 From: Me on Windows Date: Fri, 18 Jun 2021 16:35:12 +0000 Subject: [PATCH] Fall back to default configuration if there is no configuration to be loaded. --- QuickPlay/Configuration.cs | 16 +++++++++++++++- QuickPlay/MainActivity.cs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/QuickPlay/Configuration.cs b/QuickPlay/Configuration.cs index 610f528..01198f8 100644 --- a/QuickPlay/Configuration.cs +++ b/QuickPlay/Configuration.cs @@ -11,8 +11,18 @@ namespace QuickPlay sealed class AppConfiguration { // XXX: All the fields need to be checked in overriden Equals method - public readonly string playerConfigUrl; + // Also: sensible defaults should be provided in defaultConfiguration field + public string playerConfigUrl; + public static AppConfiguration loadConfiguration() + { + var cfg = loadSavedConfiguration(); + if (cfg == null) + { + cfg = defaultConfiguration; + } + return cfg; + } public static AppConfiguration loadSavedConfiguration() { throw new NotImplementedException(); @@ -28,6 +38,10 @@ namespace QuickPlay if (this != newConfig) throw new InvalidDataException("Saved configuration is different from the supplied one."); } + public static AppConfiguration defaultConfiguration = new AppConfiguration + { + playerConfigUrl = "file:///dev/null", + }; public PlayerConfiguration GetPlayerConfig() { // TODO: decide sensibly diff --git a/QuickPlay/MainActivity.cs b/QuickPlay/MainActivity.cs index 406d40d..9e2fd28 100644 --- a/QuickPlay/MainActivity.cs +++ b/QuickPlay/MainActivity.cs @@ -35,7 +35,7 @@ namespace QuickPlay // App initialization - appConfig = AppConfiguration.loadSavedConfiguration(); + appConfig = AppConfiguration.loadConfiguration(); currentPlayer = appConfig.GetPlayerConfig().GetPlayer(); // UI initialization