This commit is contained in:
2022-06-08 20:45:25 +03:00
parent 51324f6dca
commit 1712205222
7 changed files with 30 additions and 74 deletions

View File

@@ -1,5 +1,4 @@
using System;
using PluginManager.Others;
using PluginManager.Others;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -31,8 +30,15 @@ namespace PluginManager
public static T? GetValue<T>(string key)
{
if (!appConfig.ApplicationVariables.ContainsKey(key)) return default;
JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
return element.Deserialize<T>();
try
{
JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
return element.Deserialize<T>();
}
catch
{
return (T)appConfig.ApplicationVariables[key];
}
}
public static bool SetValue<T>(string key, T value)
@@ -56,14 +62,14 @@ namespace PluginManager
public static async void SaveConfig()
{
string path = Functions.dataFolder + "var.dat";
string path = Functions.dataFolder + "config.json";
await Functions.SaveToJsonFile<AppConfig>(path, appConfig);
}
public static async Task LoadConfig()
{
string path = Functions.dataFolder + "var.dat";
string path = Functions.dataFolder + "config.json";
if (File.Exists(path))
{
appConfig = await Functions.ConvertFromJson<AppConfig>(path);