Fixed some errors on SettingsDictionary
This commit is contained in:
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user