DI: Fix migration, cleanup

This commit is contained in:
Liza 2023-02-15 23:51:35 +01:00
parent c52341eb0d
commit 29aefee135
15 changed files with 83 additions and 89 deletions

View File

@ -1,13 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Dalamud.Logging; using Dalamud.Logging;
namespace Pal.Client.Configuration namespace Pal.Client.Configuration
{ {
public class AccountConfigurationV7 : IAccountConfiguration public sealed class AccountConfigurationV7 : IAccountConfiguration
{ {
private const int DefaultEntropyLength = 16; private const int DefaultEntropyLength = 16;

View File

@ -7,13 +7,11 @@ using System.Text.Json;
using Dalamud.Logging; using Dalamud.Logging;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using Pal.Client.DependencyInjection;
using Pal.Client.Scheduled;
using NJson = Newtonsoft.Json; using NJson = Newtonsoft.Json;
namespace Pal.Client.Configuration namespace Pal.Client.Configuration
{ {
internal class ConfigurationManager internal sealed class ConfigurationManager
{ {
private readonly DalamudPluginInterface _pluginInterface; private readonly DalamudPluginInterface _pluginInterface;
@ -56,13 +54,13 @@ namespace Pal.Client.Configuration
ConfigurationV1 configurationV1 = ConfigurationV1 configurationV1 =
NJson.JsonConvert.DeserializeObject<ConfigurationV1>( NJson.JsonConvert.DeserializeObject<ConfigurationV1>(
File.ReadAllText(_pluginInterface.ConfigFile.FullName)) ?? new ConfigurationV1(); File.ReadAllText(_pluginInterface.ConfigFile.FullName)) ?? new ConfigurationV1();
configurationV1.Migrate(); configurationV1.Migrate(_pluginInterface);
configurationV1.Save(); configurationV1.Save(_pluginInterface);
var v7 = MigrateToV7(configurationV1); var v7 = MigrateToV7(configurationV1);
Save(v7, queue: false); Save(v7, queue: false);
File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true); //File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true);
} }
} }
@ -81,18 +79,21 @@ namespace Pal.Client.Configuration
{ {
Show = v1.ShowTraps, Show = v1.ShowTraps,
Color = ImGui.ColorConvertFloat4ToU32(v1.TrapColor), Color = ImGui.ColorConvertFloat4ToU32(v1.TrapColor),
OnlyVisibleAfterPomander = v1.OnlyVisibleTrapsAfterPomander,
Fill = false Fill = false
}, },
HoardCoffers = new MarkerConfiguration HoardCoffers = new MarkerConfiguration
{ {
Show = v1.ShowHoard, Show = v1.ShowHoard,
Color = ImGui.ColorConvertFloat4ToU32(v1.HoardColor), Color = ImGui.ColorConvertFloat4ToU32(v1.HoardColor),
OnlyVisibleAfterPomander = v1.OnlyVisibleHoardAfterPomander,
Fill = false Fill = false
}, },
SilverCoffers = new MarkerConfiguration SilverCoffers = new MarkerConfiguration
{ {
Show = v1.ShowSilverCoffers, Show = v1.ShowSilverCoffers,
Color = ImGui.ColorConvertFloat4ToU32(v1.SilverCofferColor), Color = ImGui.ColorConvertFloat4ToU32(v1.SilverCofferColor),
OnlyVisibleAfterPomander = false,
Fill = v1.FillSilverCoffers Fill = v1.FillSilverCoffers
} }
} }

View File

@ -1,19 +1,17 @@
using Dalamud.Logging; using Dalamud.Logging;
using ECommons.Schedulers;
using Newtonsoft.Json; using Newtonsoft.Json;
using Pal.Client.Scheduled;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Pal.Client.Extensions; using Dalamud.Plugin;
namespace Pal.Client.Configuration namespace Pal.Client.Configuration
{ {
[Obsolete] [Obsolete]
public class ConfigurationV1 public sealed class ConfigurationV1
{ {
public int Version { get; set; } = 6; public int Version { get; set; } = 6;
@ -52,7 +50,7 @@ namespace Pal.Client.Configuration
public string BetaKey { get; set; } = ""; public string BetaKey { get; set; } = "";
#endregion #endregion
public void Migrate() public void Migrate(DalamudPluginInterface pluginInterface)
{ {
if (Version == 1) if (Version == 1)
{ {
@ -65,7 +63,7 @@ namespace Pal.Client.Configuration
AccountIds["https://pal.μ.tv"] = accountId; AccountIds["https://pal.μ.tv"] = accountId;
Version = 2; Version = 2;
Save(); Save(pluginInterface);
} }
if (Version == 2) if (Version == 2)
@ -77,13 +75,13 @@ namespace Pal.Client.Configuration
Id = x.Value.ToString() // encryption happens in V7 migration at latest Id = x.Value.ToString() // encryption happens in V7 migration at latest
}); });
Version = 3; Version = 3;
Save(); Save(pluginInterface);
} }
if (Version == 3) if (Version == 3)
{ {
Version = 4; Version = 4;
Save(); Save(pluginInterface);
} }
if (Version == 4) if (Version == 4)
@ -127,7 +125,7 @@ namespace Pal.Client.Configuration
*/ */
Version = 5; Version = 5;
Save(); Save(pluginInterface);
} }
if (Version == 5) if (Version == 5)
@ -135,26 +133,26 @@ namespace Pal.Client.Configuration
LocalState.UpdateAll(); LocalState.UpdateAll();
Version = 6; Version = 6;
Save(); Save(pluginInterface);
} }
} }
public void Save() public void Save(DalamudPluginInterface pluginInterface)
{ {
File.WriteAllText(Service.PluginInterface.ConfigFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings File.WriteAllText(pluginInterface.ConfigFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings
{ {
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
TypeNameHandling = TypeNameHandling.Objects TypeNameHandling = TypeNameHandling.Objects
})); }));
} }
public class AccountInfo public sealed class AccountInfo
{ {
public string? Id { get; set; } public string? Id { get; set; }
public List<string> CachedRoles { get; set; } = new(); public List<string> CachedRoles { get; set; } = new();
} }
public class ImportHistoryEntry public sealed class ImportHistoryEntry
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string? RemoteUrl { get; set; } public string? RemoteUrl { get; set; }

View File

@ -4,10 +4,10 @@ using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Pal.Client.Net; using Pal.Client.Net;
namespace Pal.Client.Configuration; namespace Pal.Client.Configuration
public class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDirectory
{ {
public sealed class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDirectory
{
public int Version { get; set; } = 7; public int Version { get; set; } = 7;
public bool FirstUse { get; set; } = true; public bool FirstUse { get; set; } = true;
@ -55,4 +55,5 @@ public class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDi
var account = FindAccount(RemoteApi.RemoteUrl); var account = FindAccount(RemoteApi.RemoteUrl);
return account == null || account.CachedRoles.Contains(role); return account == null || account.CachedRoles.Contains(role);
} }
}
} }

View File

@ -2,7 +2,7 @@
namespace Pal.Client.DependencyInjection namespace Pal.Client.DependencyInjection
{ {
internal class DebugState internal sealed class DebugState
{ {
public string? DebugMessage { get; set; } public string? DebugMessage { get; set; }

View File

@ -22,13 +22,14 @@ namespace Pal.Client.DependencyInjection
/// <summary> /// <summary>
/// DI-aware Plugin. /// DI-aware Plugin.
/// </summary> /// </summary>
internal sealed class DIPlugin : IDalamudPlugin // ReSharper disable once UnusedType.Global
internal sealed class DependencyInjectionContext : IDalamudPlugin
{ {
private ServiceProvider? _serviceProvider; private ServiceProvider? _serviceProvider;
public string Name => Localization.Palace_Pal; public string Name => Localization.Palace_Pal;
public DIPlugin(DalamudPluginInterface pluginInterface, public DependencyInjectionContext(DalamudPluginInterface pluginInterface,
ClientState clientState, ClientState clientState,
GameGui gameGui, GameGui gameGui,
ChatGui chatGui, ChatGui chatGui,
@ -51,7 +52,7 @@ namespace Pal.Client.DependencyInjection
services.AddSingleton(condition); services.AddSingleton(condition);
services.AddSingleton(commandManager); services.AddSingleton(commandManager);
services.AddSingleton(dataManager); services.AddSingleton(dataManager);
services.AddSingleton(new WindowSystem(typeof(DIPlugin).AssemblyQualifiedName)); services.AddSingleton(new WindowSystem(typeof(DependencyInjectionContext).AssemblyQualifiedName));
// plugin-specific // plugin-specific
services.AddSingleton<Plugin>(); services.AddSingleton<Plugin>();

View File

@ -18,7 +18,7 @@ using Pal.Client.Scheduled;
namespace Pal.Client.DependencyInjection namespace Pal.Client.DependencyInjection
{ {
internal class FrameworkService : IDisposable internal sealed class FrameworkService : IDisposable
{ {
private readonly Framework _framework; private readonly Framework _framework;
private readonly ConfigurationManager _configurationManager; private readonly ConfigurationManager _configurationManager;

View File

@ -10,7 +10,7 @@ using Pal.Client.DependencyInjection;
namespace Pal.Client namespace Pal.Client
{ {
internal unsafe class Hooks : IDisposable internal sealed unsafe class Hooks : IDisposable
{ {
private readonly ObjectTable _objectTable; private readonly ObjectTable _objectTable;
private readonly TerritoryState _territoryState; private readonly TerritoryState _territoryState;

View File

@ -12,7 +12,7 @@ namespace Pal.Client
/// <summary> /// <summary>
/// JSON for a single floor set (e.g. 51-60). /// JSON for a single floor set (e.g. 51-60).
/// </summary> /// </summary>
internal class LocalState internal sealed class LocalState
{ {
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true }; private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true };
private const int CurrentVersion = 4; private const int CurrentVersion = 4;
@ -146,7 +146,7 @@ namespace Pal.Client
marker.Imports.RemoveAll(importIds.Contains); marker.Imports.RemoveAll(importIds.Contains);
} }
public class SaveFile public sealed class SaveFile
{ {
public int Version { get; set; } public int Version { get; set; }
public HashSet<Marker> Markers { get; set; } = new(); public HashSet<Marker> Markers { get; set; } = new();

View File

@ -9,7 +9,7 @@ using System.Text.Json.Serialization;
namespace Pal.Client namespace Pal.Client
{ {
internal class Marker internal sealed class Marker
{ {
public EType Type { get; set; } = EType.Unknown; public EType Type { get; set; } = EType.Unknown;
public Vector3 Position { get; set; } public Vector3 Position { get; set; }

View File

@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
namespace Pal.Client.Net namespace Pal.Client.Net
{ {
internal class GrpcLogger : ILogger internal sealed class GrpcLogger : ILogger
{ {
private readonly string _name; private readonly string _name;

View File

@ -3,7 +3,7 @@ using System;
namespace Pal.Client.Net namespace Pal.Client.Net
{ {
internal class GrpcLoggerProvider : ILoggerProvider internal sealed class GrpcLoggerProvider : ILoggerProvider
{ {
public ILogger CreateLogger(string categoryName) => new GrpcLogger(categoryName); public ILogger CreateLogger(string categoryName) => new GrpcLogger(categoryName);

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Pal.Client.Net namespace Pal.Client.Net
{ {
internal class JwtClaims internal sealed class JwtClaims
{ {
[JsonPropertyName("nameid")] [JsonPropertyName("nameid")]
public Guid NameId { get; set; } public Guid NameId { get; set; }
@ -46,7 +46,7 @@ namespace Pal.Client.Net
} }
} }
internal class JwtRoleConverter : JsonConverter<List<string>> internal sealed class JwtRoleConverter : JsonConverter<List<string>>
{ {
public override List<string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override List<string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
@ -78,9 +78,9 @@ namespace Pal.Client.Net
public override void Write(Utf8JsonWriter writer, List<string> value, JsonSerializerOptions options) => throw new NotImplementedException(); public override void Write(Utf8JsonWriter writer, List<string> value, JsonSerializerOptions options) => throw new NotImplementedException();
} }
public class JwtDateConverter : JsonConverter<DateTimeOffset> public sealed class JwtDateConverter : JsonConverter<DateTimeOffset>
{ {
static readonly DateTimeOffset Zero = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); static readonly DateTimeOffset Zero = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {

View File

@ -1,17 +1,11 @@
using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Interface.Windowing;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Pal.Client.Rendering; using Pal.Client.Rendering;
using Pal.Client.Scheduled;
using Pal.Client.Windows; using Pal.Client.Windows;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Logging; using Dalamud.Logging;
using Pal.Client.Extensions;
using Pal.Client.Properties; using Pal.Client.Properties;
using ECommons; using ECommons;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

View File

@ -13,7 +13,7 @@ using System.Reflection;
namespace Pal.Client.Windows namespace Pal.Client.Windows
{ {
internal class StatisticsWindow : Window, IDisposable, ILanguageChanged internal sealed class StatisticsWindow : Window, IDisposable, ILanguageChanged
{ {
private const string WindowId = "###PalacePalStats"; private const string WindowId = "###PalacePalStats";
private readonly WindowSystem _windowSystem; private readonly WindowSystem _windowSystem;
@ -112,7 +112,7 @@ namespace Pal.Client.Windows
} }
} }
private class TerritoryStatistics private sealed class TerritoryStatistics
{ {
public string TerritoryName { get; } public string TerritoryName { get; }
public uint? TrapCount { get; set; } public uint? TrapCount { get; set; }