Fixed some errors on SettingsDictionary

This commit is contained in:
2024-03-03 15:07:06 +02:00
parent fd9cd49844
commit 0fccf706a1
3 changed files with 23 additions and 14 deletions

View File

@@ -32,15 +32,22 @@ public class Config
Directory.CreateDirectory("./Data/Logs");
AppSettings = new SettingsDictionary<string, string>("./Data/Resources/config.json");
bool response = await AppSettings.LoadFromFile();
if (!response)
throw new Exception("Invalid config file");
AppSettings["LogFolder"] = "./Data/Logs";
AppSettings["PluginFolder"] = "./Data/Plugins";
AppSettings["ArchiveFolder"] = "./Data/Archives";
AppSettings["PluginDatabase"] = "./Data/Resources/plugins.json";
ArchiveManager.Initialize();
if (!File.Exists(AppSettings["PluginDatabase"]))
{
List<PluginInfo> plugins = new();
@@ -49,15 +56,15 @@ public class Config
Logger = new Logger(false, true, AppSettings["LogFolder"] + $"/{DateTime.Today.ToShortDateString().Replace("/", "")}.log");
_isLoaded = true;
PluginsManager = new PluginsManager("releases");
await PluginsManager.UninstallMarkedPlugins();
await PluginsManager.CheckForUpdates();
_isLoaded = true;
Logger.Log("Config initialized", typeof(Config));
}

View File

@@ -13,11 +13,6 @@ public class SettingsDictionary<TKey, TValue>: IDictionary<TKey, TValue>
public SettingsDictionary(string? file)
{
_file = file;
if (!LoadFromFile())
{
_dictionary = new Dictionary<TKey, TValue>();
SaveToFile();
}
}
public async Task SaveToFile()
@@ -26,7 +21,7 @@ public class SettingsDictionary<TKey, TValue>: IDictionary<TKey, TValue>
await JsonManager.SaveToJsonFile(_file, _dictionary);
}
private bool LoadFromFile()
public async Task<bool> LoadFromFile()
{
if (!string.IsNullOrEmpty(_file))
try
@@ -42,7 +37,9 @@ public class SettingsDictionary<TKey, TValue>: IDictionary<TKey, TValue>
}
else
File.WriteAllText(_file, "{}");
_dictionary = JsonManager.ConvertFromJson<IDictionary<TKey, TValue>>(_file).Result;
_dictionary = await JsonManager.ConvertFromJson<IDictionary<TKey, TValue>>(_file);
return true;
}
catch