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;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Events;
|
|
||||||
|
|
||||||
namespace LibationLauncher
|
namespace LibationLauncher
|
||||||
{
|
{
|
||||||
@ -266,18 +265,21 @@ namespace LibationLauncher
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
var settingsKey = "DownloadsInProgressEnum";
|
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";
|
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(
|
{ // appsettings.json
|
||||||
UNSAFE_MigrationHelper.LIBATION_FILES_KEY,
|
var appSettingsKey = UNSAFE_MigrationHelper.LIBATION_FILES_KEY;
|
||||||
translatePath(UNSAFE_MigrationHelper.AppSettings_Get(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)
|
private static string translatePath(string path)
|
||||||
|
|||||||
@ -16,16 +16,15 @@ namespace LibationLauncher
|
|||||||
|
|
||||||
public static bool AppSettingsJson_Exists => File.Exists(APPSETTINGS_JSON);
|
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;
|
bool success = false;
|
||||||
JToken val = null;
|
JToken val = null;
|
||||||
|
|
||||||
process_AppSettingsJson(jObj => success = jObj.TryGetValue(key, out val), false);
|
process_AppSettingsJson(jObj => success = jObj.TryGetValue(key, out val), false);
|
||||||
|
|
||||||
if (success)
|
value = success ? val.Value<string>() : null;
|
||||||
return val.Value<string>();
|
return success;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>only insert if not exists</summary>
|
/// <summary>only insert if not exists</summary>
|
||||||
@ -80,22 +79,21 @@ namespace LibationLauncher
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var value = AppSettings_Get(LIBATION_FILES_KEY);
|
var success = AppSettings_TryGet(LIBATION_FILES_KEY, out var value);
|
||||||
return value is null ? null : Path.Combine(value, SETTINGS_JSON);
|
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 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;
|
bool success = false;
|
||||||
JToken val = null;
|
JToken val = null;
|
||||||
|
|
||||||
process_SettingsJson(jObj => success = jObj.TryGetValue(key, out val), false);
|
process_SettingsJson(jObj => success = jObj.TryGetValue(key, out val), false);
|
||||||
|
|
||||||
if (success)
|
value = success ? val.Value<string>() : null;
|
||||||
return val.Value<string>();
|
return success;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>only insert if not exists</summary>
|
/// <summary>only insert if not exists</summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user