[O] ResetTouchAfterTrack -> ResetTouch, add press key to reset (#93)

* [O] ResetTouchAfterTrack -> ResetTouch, add press key to reset

* fix

* update

* fix: Remove not work

---------

Co-authored-by: Menci <mencici@msn.com>
This commit is contained in:
凌莞~(=^▽^=)
2024-11-30 05:29:30 +08:00
committed by GitHub
parent bed1b85319
commit d5a9c98ff9
12 changed files with 161 additions and 24 deletions

View File

@@ -12,7 +12,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
private readonly Dictionary<string, IConfigMigration> migrationMap =
new List<IConfigMigration>
{
new ConfigMigration_V1_0_V2_0()
new ConfigMigration_V1_0_V2_0(),
new ConfigMigration_V2_0_V2_1()
}.ToDictionary(m => m.FromVersion);
public string LatestVersion { get; }
@@ -39,10 +40,12 @@ public class ConfigMigrationManager : IConfigMigrationManager
config = migration.Migrate(config);
currentVersion = migration.ToVersion;
}
if (currentVersion != LatestVersion)
{
throw new ArgumentException($"Could not migrate the config from v{currentVersion} to v{LatestVersion}");
}
return config;
}
@@ -52,7 +55,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
{
return version;
}
// Assume v1.0 if not found
return "1.0";
}
}
}

View File

@@ -0,0 +1,44 @@
using AquaMai.Config.Interfaces;
using Tomlet.Models;
namespace AquaMai.Config.Migration;
public class ConfigMigration_V2_0_V2_1 : IConfigMigration
{
public string FromVersion => "2.0";
public string ToVersion => "2.1";
public IConfigView Migrate(IConfigView src)
{
var dst = src.Clone();
dst.SetValue("Version", ToVersion);
if (IsSectionEnabled(src, "Tweaks.ResetTouchAfterTrack"))
{
dst.Remove("Tweaks.ResetTouchAfterTrack");
dst.SetValue("Tweaks.ResetTouch.AfterTrack", true);
}
return dst;
}
public bool IsSectionEnabled(IConfigView src, string path)
{
if (src.TryGetValue(path, out object section))
{
if (section is bool enabled)
{
return enabled;
}
else if (section is TomlTable table)
{
if (Utility.TomlTryGetValueCaseInsensitive(table, "Disabled", out var disabled))
{
return !Utility.IsTrutyOrDefault(disabled);
}
return true;
}
}
return false;
}
}