diff --git a/LibationLauncher/Program.cs b/LibationLauncher/Program.cs index fb36c1d7..a49cdbc6 100644 --- a/LibationLauncher/Program.cs +++ b/LibationLauncher/Program.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Serilog; -using Serilog.Events; namespace LibationLauncher { @@ -266,18 +265,21 @@ namespace LibationLauncher { { var settingsKey = "DownloadsInProgressEnum"; - UNSAFE_MigrationHelper.Settings_Update(settingsKey, translatePath(UNSAFE_MigrationHelper.Settings_Get(settingsKey))); + if (UNSAFE_MigrationHelper.Settings_TryGet(settingsKey, out var value)) + UNSAFE_MigrationHelper.Settings_Update(settingsKey, translatePath(value)); } { var settingsKey = "DecryptInProgressEnum"; - UNSAFE_MigrationHelper.Settings_Update(settingsKey, translatePath(UNSAFE_MigrationHelper.Settings_Get(settingsKey))); + if (UNSAFE_MigrationHelper.Settings_TryGet(settingsKey, out var value)) + UNSAFE_MigrationHelper.Settings_Update(settingsKey, translatePath(value)); } - UNSAFE_MigrationHelper.AppSettings_Update( - UNSAFE_MigrationHelper.LIBATION_FILES_KEY, - translatePath(UNSAFE_MigrationHelper.AppSettings_Get(UNSAFE_MigrationHelper.LIBATION_FILES_KEY)) - ); + { // appsettings.json + var appSettingsKey = UNSAFE_MigrationHelper.LIBATION_FILES_KEY; + if (UNSAFE_MigrationHelper.AppSettings_TryGet(appSettingsKey, out var value)) + UNSAFE_MigrationHelper.AppSettings_Update(appSettingsKey, translatePath(value)); + } } private static string translatePath(string path) diff --git a/LibationLauncher/UNSAFE_MigrationHelper.cs b/LibationLauncher/UNSAFE_MigrationHelper.cs index 1fd9f282..d4f830c7 100644 --- a/LibationLauncher/UNSAFE_MigrationHelper.cs +++ b/LibationLauncher/UNSAFE_MigrationHelper.cs @@ -16,16 +16,15 @@ namespace LibationLauncher public static bool AppSettingsJson_Exists => File.Exists(APPSETTINGS_JSON); - public static string AppSettings_Get(string key) + public static bool AppSettings_TryGet(string key, out string value) { bool success = false; JToken val = null; process_AppSettingsJson(jObj => success = jObj.TryGetValue(key, out val), false); - if (success) - return val.Value(); - return null; + value = success ? val.Value() : null; + return success; } /// only insert if not exists @@ -80,22 +79,21 @@ namespace LibationLauncher { get { - var value = AppSettings_Get(LIBATION_FILES_KEY); - return value is null ? null : Path.Combine(value, SETTINGS_JSON); + var success = AppSettings_TryGet(LIBATION_FILES_KEY, out var value); + return !success || value is null ? null : Path.Combine(value, SETTINGS_JSON); } } public static bool SettingsJson_Exists => SettingsJsonPath is not null && File.Exists(SettingsJsonPath); - public static string Settings_Get(string key) + public static bool Settings_TryGet(string key, out string value) { bool success = false; JToken val = null; process_SettingsJson(jObj => success = jObj.TryGetValue(key, out val), false); - if (success) - return val.Value(); - return null; + value = success ? val.Value() : null; + return success; } /// only insert if not exists