More fixes to the new config. Module loader reworked

This commit is contained in:
2024-08-06 22:47:59 +03:00
parent 27e25a9166
commit 18a059af0e
51 changed files with 390 additions and 301 deletions

View File

@@ -22,7 +22,7 @@ public class InternalActionManager
if (this.Actions.ContainsKey(action.ActionName))
{
// This should never happen. If it does, log it and return
Application.CurrentApplication.Logger.Log($"Action {action.ActionName} already exists", this, LogType.Error);
Application.Logger.Log($"Action {action.ActionName} already exists", this, LogType.Error);
return;
}
@@ -50,7 +50,7 @@ public class InternalActionManager
{
if (!Actions.ContainsKey(actionName))
{
Application.CurrentApplication.Logger.Log($"Action {actionName} not found", this, LogType.Error);
Application.Logger.Log($"Action {actionName} not found", this, LogType.Error);
return false;
}
@@ -58,7 +58,7 @@ public class InternalActionManager
{
if (Actions[actionName].RunType == InternalActionRunType.OnStartup)
{
Application.CurrentApplication.Logger.Log($"Action {actionName} is not executable", this, LogType.Error);
Application.Logger.Log($"Action {actionName} is not executable", this, LogType.Error);
return false;
}
@@ -67,7 +67,7 @@ public class InternalActionManager
}
catch (Exception e)
{
Application.CurrentApplication.Logger.Log(e.Message, type: LogType.Error, Sender: this);
Application.Logger.Log(e.Message, type: LogType.Error, sender: this);
return false;
}
}

View File

@@ -105,7 +105,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error); // Write the error to a file
Application.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error); // Write the error to a file
await Task.Delay(100);
return await ReadFromPakAsync(fileName, archFile);
}
@@ -141,7 +141,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
Application.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
}
currentZipFile++;
@@ -176,7 +176,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
Application.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
}
await Task.Delay(10);

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -35,14 +37,14 @@ public class CustomSettingsDictionary : CustomSettingsDictionaryBase<string, obj
public override List<T> GetList<T>(string key, List<T> defaultValue)
{
List<T> result = base.GetList(key, defaultValue);
if (_EnableAutoAddOnGetWithDefault && defaultValue.All(result.Contains))
List<T> value = base.GetList(key, defaultValue);
if (_EnableAutoAddOnGetWithDefault && value.All(defaultValue.Contains))
{
Add(key,defaultValue);
Add(key, defaultValue);
}
return result;
return value;
}
public override async Task LoadFromFile()
@@ -71,11 +73,21 @@ public class CustomSettingsDictionary : CustomSettingsDictionaryBase<string, obj
else if (kvp.Value is JArray nestedJArray)
{
dict[kvp.Key] = nestedJArray.ToObject<List<object>>();
}
else
{
dict[kvp.Key] = kvp.Value;
if (kvp.Value.Type == JTokenType.Integer)
dict[kvp.Key] = kvp.Value.Value<int>();
else if (kvp.Value.Type == JTokenType.Float)
dict[kvp.Key] = kvp.Value.Value<float>();
else if (kvp.Value.Type == JTokenType.Boolean)
dict[kvp.Key] = kvp.Value.Value<bool>();
else if (kvp.Value.Type == JTokenType.String)
dict[kvp.Key] = kvp.Value.Value<string>();
else if (kvp.Value.Type == JTokenType.Date)
dict[kvp.Key] = kvp.Value.Value<DateTime>();
else
dict[kvp.Key] = kvp.Value;
}
}

View File

@@ -56,6 +56,27 @@ public abstract class CustomSettingsDictionaryBase<TKey,TValue> : ICustomSetting
return default;
}
public virtual IDictionary<TSubKey, TSubValue> GetDictionary<TSubKey, TSubValue>(TKey key)
{
if (_InternalDictionary.TryGetValue(key, out var value))
{
if (value is not IDictionary)
{
throw new Exception("The value is not a dictionary");
}
var dictionary = new Dictionary<TSubKey, TSubValue>();
foreach (DictionaryEntry item in (IDictionary)value)
{
dictionary.Add((TSubKey)Convert.ChangeType(item.Key, typeof(TSubKey)), (TSubValue)Convert.ChangeType(item.Value, typeof(TSubValue)));
}
return dictionary;
}
return new Dictionary<TSubKey, TSubValue>();
}
public virtual List<T> GetList<T>(TKey key, List<T> defaultValue)
{
@@ -67,9 +88,9 @@ public abstract class CustomSettingsDictionaryBase<TKey,TValue> : ICustomSetting
}
var list = new List<T>();
foreach (var item in (IList)value)
foreach (object? item in (IList)value)
{
list.Add(ConvertValue<T>(item));
list.Add((T)Convert.ChangeType(item, typeof(T)));
}
return list;
@@ -141,20 +162,4 @@ public abstract class CustomSettingsDictionaryBase<TKey,TValue> : ICustomSetting
public abstract Task SaveToFile();
public abstract Task LoadFromFile();
protected virtual T? ConvertValue<T>(object value)
{
if (typeof(T) == typeof(ulong) && value is long longValue)
{
return (T)(object)Convert.ToUInt64(longValue);
}
if (typeof(T).IsEnum && value is string stringValue)
{
return (T)Enum.Parse(typeof(T), stringValue);
}
return (T)Convert.ChangeType(value, typeof(T));
}
}