unsafe migration helper: Get => TryGet
This commit is contained in:
parent
71617b9620
commit
7b3c857042
@ -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)
|
||||
|
||||
@ -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<string>();
|
||||
return null;
|
||||
value = success ? val.Value<string>() : null;
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>only insert if not exists</summary>
|
||||
@ -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<string>();
|
||||
return null;
|
||||
value = success ? val.Value<string>() : null;
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>only insert if not exists</summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user