DI: Fix migration, cleanup
This commit is contained in:
parent
c52341eb0d
commit
29aefee135
@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json.Serialization;
|
||||
using Dalamud.Logging;
|
||||
|
||||
namespace Pal.Client.Configuration
|
||||
{
|
||||
public class AccountConfigurationV7 : IAccountConfiguration
|
||||
public sealed class AccountConfigurationV7 : IAccountConfiguration
|
||||
{
|
||||
private const int DefaultEntropyLength = 16;
|
||||
|
||||
|
@ -7,13 +7,11 @@ using System.Text.Json;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Pal.Client.DependencyInjection;
|
||||
using Pal.Client.Scheduled;
|
||||
using NJson = Newtonsoft.Json;
|
||||
|
||||
namespace Pal.Client.Configuration
|
||||
{
|
||||
internal class ConfigurationManager
|
||||
internal sealed class ConfigurationManager
|
||||
{
|
||||
private readonly DalamudPluginInterface _pluginInterface;
|
||||
|
||||
@ -56,13 +54,13 @@ namespace Pal.Client.Configuration
|
||||
ConfigurationV1 configurationV1 =
|
||||
NJson.JsonConvert.DeserializeObject<ConfigurationV1>(
|
||||
File.ReadAllText(_pluginInterface.ConfigFile.FullName)) ?? new ConfigurationV1();
|
||||
configurationV1.Migrate();
|
||||
configurationV1.Save();
|
||||
configurationV1.Migrate(_pluginInterface);
|
||||
configurationV1.Save(_pluginInterface);
|
||||
|
||||
var v7 = MigrateToV7(configurationV1);
|
||||
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,
|
||||
Color = ImGui.ColorConvertFloat4ToU32(v1.TrapColor),
|
||||
OnlyVisibleAfterPomander = v1.OnlyVisibleTrapsAfterPomander,
|
||||
Fill = false
|
||||
},
|
||||
HoardCoffers = new MarkerConfiguration
|
||||
{
|
||||
Show = v1.ShowHoard,
|
||||
Color = ImGui.ColorConvertFloat4ToU32(v1.HoardColor),
|
||||
OnlyVisibleAfterPomander = v1.OnlyVisibleHoardAfterPomander,
|
||||
Fill = false
|
||||
},
|
||||
SilverCoffers = new MarkerConfiguration
|
||||
{
|
||||
Show = v1.ShowSilverCoffers,
|
||||
Color = ImGui.ColorConvertFloat4ToU32(v1.SilverCofferColor),
|
||||
OnlyVisibleAfterPomander = false,
|
||||
Fill = v1.FillSilverCoffers
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
using Dalamud.Logging;
|
||||
using ECommons.Schedulers;
|
||||
using Newtonsoft.Json;
|
||||
using Pal.Client.Scheduled;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Pal.Client.Extensions;
|
||||
using Dalamud.Plugin;
|
||||
|
||||
namespace Pal.Client.Configuration
|
||||
{
|
||||
[Obsolete]
|
||||
public class ConfigurationV1
|
||||
public sealed class ConfigurationV1
|
||||
{
|
||||
public int Version { get; set; } = 6;
|
||||
|
||||
@ -52,7 +50,7 @@ namespace Pal.Client.Configuration
|
||||
public string BetaKey { get; set; } = "";
|
||||
#endregion
|
||||
|
||||
public void Migrate()
|
||||
public void Migrate(DalamudPluginInterface pluginInterface)
|
||||
{
|
||||
if (Version == 1)
|
||||
{
|
||||
@ -65,7 +63,7 @@ namespace Pal.Client.Configuration
|
||||
AccountIds["https://pal.μ.tv"] = accountId;
|
||||
|
||||
Version = 2;
|
||||
Save();
|
||||
Save(pluginInterface);
|
||||
}
|
||||
|
||||
if (Version == 2)
|
||||
@ -77,13 +75,13 @@ namespace Pal.Client.Configuration
|
||||
Id = x.Value.ToString() // encryption happens in V7 migration at latest
|
||||
});
|
||||
Version = 3;
|
||||
Save();
|
||||
Save(pluginInterface);
|
||||
}
|
||||
|
||||
if (Version == 3)
|
||||
{
|
||||
Version = 4;
|
||||
Save();
|
||||
Save(pluginInterface);
|
||||
}
|
||||
|
||||
if (Version == 4)
|
||||
@ -127,7 +125,7 @@ namespace Pal.Client.Configuration
|
||||
*/
|
||||
|
||||
Version = 5;
|
||||
Save();
|
||||
Save(pluginInterface);
|
||||
}
|
||||
|
||||
if (Version == 5)
|
||||
@ -135,26 +133,26 @@ namespace Pal.Client.Configuration
|
||||
LocalState.UpdateAll();
|
||||
|
||||
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,
|
||||
TypeNameHandling = TypeNameHandling.Objects
|
||||
}));
|
||||
}
|
||||
|
||||
public class AccountInfo
|
||||
public sealed class AccountInfo
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public List<string> CachedRoles { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ImportHistoryEntry
|
||||
public sealed class ImportHistoryEntry
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? RemoteUrl { get; set; }
|
||||
|
@ -4,55 +4,56 @@ using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Pal.Client.Net;
|
||||
|
||||
namespace Pal.Client.Configuration;
|
||||
|
||||
public class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDirectory
|
||||
namespace Pal.Client.Configuration
|
||||
{
|
||||
public int Version { get; set; } = 7;
|
||||
|
||||
public bool FirstUse { get; set; } = true;
|
||||
public EMode Mode { get; set; }
|
||||
public string BetaKey { get; init; } = "";
|
||||
|
||||
public DeepDungeonConfiguration DeepDungeons { get; set; } = new();
|
||||
public RendererConfiguration Renderer { get; set; } = new();
|
||||
public List<AccountConfigurationV7> Accounts { get; set; } = new();
|
||||
|
||||
[JsonIgnore]
|
||||
[Obsolete]
|
||||
public List<ConfigurationV1.ImportHistoryEntry> ImportHistory { get; set; } = new();
|
||||
|
||||
public IAccountConfiguration CreateAccount(string server, Guid accountId)
|
||||
public sealed class ConfigurationV7 : IPalacePalConfiguration, IConfigurationInConfigDirectory
|
||||
{
|
||||
var account = new AccountConfigurationV7(server, accountId);
|
||||
Accounts.Add(account);
|
||||
return account;
|
||||
}
|
||||
public int Version { get; set; } = 7;
|
||||
|
||||
[Obsolete("for V1 import")]
|
||||
internal IAccountConfiguration CreateAccount(string server, string accountId)
|
||||
{
|
||||
var account = new AccountConfigurationV7(server, accountId);
|
||||
Accounts.Add(account);
|
||||
return account;
|
||||
}
|
||||
public bool FirstUse { get; set; } = true;
|
||||
public EMode Mode { get; set; }
|
||||
public string BetaKey { get; init; } = "";
|
||||
|
||||
public IAccountConfiguration? FindAccount(string server)
|
||||
{
|
||||
return Accounts.FirstOrDefault(a => a.Server == server && a.IsUsable);
|
||||
}
|
||||
public DeepDungeonConfiguration DeepDungeons { get; set; } = new();
|
||||
public RendererConfiguration Renderer { get; set; } = new();
|
||||
public List<AccountConfigurationV7> Accounts { get; set; } = new();
|
||||
|
||||
public void RemoveAccount(string server)
|
||||
{
|
||||
Accounts.RemoveAll(a => a.Server == server && a.IsUsable);
|
||||
}
|
||||
[JsonIgnore]
|
||||
[Obsolete]
|
||||
public List<ConfigurationV1.ImportHistoryEntry> ImportHistory { get; set; } = new();
|
||||
|
||||
public bool HasRoleOnCurrentServer(string role)
|
||||
{
|
||||
if (Mode != EMode.Online)
|
||||
return false;
|
||||
public IAccountConfiguration CreateAccount(string server, Guid accountId)
|
||||
{
|
||||
var account = new AccountConfigurationV7(server, accountId);
|
||||
Accounts.Add(account);
|
||||
return account;
|
||||
}
|
||||
|
||||
var account = FindAccount(RemoteApi.RemoteUrl);
|
||||
return account == null || account.CachedRoles.Contains(role);
|
||||
[Obsolete("for V1 import")]
|
||||
internal IAccountConfiguration CreateAccount(string server, string accountId)
|
||||
{
|
||||
var account = new AccountConfigurationV7(server, accountId);
|
||||
Accounts.Add(account);
|
||||
return account;
|
||||
}
|
||||
|
||||
public IAccountConfiguration? FindAccount(string server)
|
||||
{
|
||||
return Accounts.FirstOrDefault(a => a.Server == server && a.IsUsable);
|
||||
}
|
||||
|
||||
public void RemoveAccount(string server)
|
||||
{
|
||||
Accounts.RemoveAll(a => a.Server == server && a.IsUsable);
|
||||
}
|
||||
|
||||
public bool HasRoleOnCurrentServer(string role)
|
||||
{
|
||||
if (Mode != EMode.Online)
|
||||
return false;
|
||||
|
||||
var account = FindAccount(RemoteApi.RemoteUrl);
|
||||
return account == null || account.CachedRoles.Contains(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Pal.Client.DependencyInjection
|
||||
{
|
||||
internal class DebugState
|
||||
internal sealed class DebugState
|
||||
{
|
||||
public string? DebugMessage { get; set; }
|
||||
|
||||
|
@ -22,13 +22,14 @@ namespace Pal.Client.DependencyInjection
|
||||
/// <summary>
|
||||
/// DI-aware Plugin.
|
||||
/// </summary>
|
||||
internal sealed class DIPlugin : IDalamudPlugin
|
||||
// ReSharper disable once UnusedType.Global
|
||||
internal sealed class DependencyInjectionContext : IDalamudPlugin
|
||||
{
|
||||
private ServiceProvider? _serviceProvider;
|
||||
|
||||
public string Name => Localization.Palace_Pal;
|
||||
|
||||
public DIPlugin(DalamudPluginInterface pluginInterface,
|
||||
public DependencyInjectionContext(DalamudPluginInterface pluginInterface,
|
||||
ClientState clientState,
|
||||
GameGui gameGui,
|
||||
ChatGui chatGui,
|
||||
@ -51,7 +52,7 @@ namespace Pal.Client.DependencyInjection
|
||||
services.AddSingleton(condition);
|
||||
services.AddSingleton(commandManager);
|
||||
services.AddSingleton(dataManager);
|
||||
services.AddSingleton(new WindowSystem(typeof(DIPlugin).AssemblyQualifiedName));
|
||||
services.AddSingleton(new WindowSystem(typeof(DependencyInjectionContext).AssemblyQualifiedName));
|
||||
|
||||
// plugin-specific
|
||||
services.AddSingleton<Plugin>();
|
@ -18,7 +18,7 @@ using Pal.Client.Scheduled;
|
||||
|
||||
namespace Pal.Client.DependencyInjection
|
||||
{
|
||||
internal class FrameworkService : IDisposable
|
||||
internal sealed class FrameworkService : IDisposable
|
||||
{
|
||||
private readonly Framework _framework;
|
||||
private readonly ConfigurationManager _configurationManager;
|
||||
|
@ -10,7 +10,7 @@ using Pal.Client.DependencyInjection;
|
||||
|
||||
namespace Pal.Client
|
||||
{
|
||||
internal unsafe class Hooks : IDisposable
|
||||
internal sealed unsafe class Hooks : IDisposable
|
||||
{
|
||||
private readonly ObjectTable _objectTable;
|
||||
private readonly TerritoryState _territoryState;
|
||||
|
@ -12,7 +12,7 @@ namespace Pal.Client
|
||||
/// <summary>
|
||||
/// JSON for a single floor set (e.g. 51-60).
|
||||
/// </summary>
|
||||
internal class LocalState
|
||||
internal sealed class LocalState
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true };
|
||||
private const int CurrentVersion = 4;
|
||||
@ -146,7 +146,7 @@ namespace Pal.Client
|
||||
marker.Imports.RemoveAll(importIds.Contains);
|
||||
}
|
||||
|
||||
public class SaveFile
|
||||
public sealed class SaveFile
|
||||
{
|
||||
public int Version { get; set; }
|
||||
public HashSet<Marker> Markers { get; set; } = new();
|
||||
|
@ -9,7 +9,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Pal.Client
|
||||
{
|
||||
internal class Marker
|
||||
internal sealed class Marker
|
||||
{
|
||||
public EType Type { get; set; } = EType.Unknown;
|
||||
public Vector3 Position { get; set; }
|
||||
|
@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Pal.Client.Net
|
||||
{
|
||||
internal class GrpcLogger : ILogger
|
||||
internal sealed class GrpcLogger : ILogger
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
|
@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace Pal.Client.Net
|
||||
{
|
||||
internal class GrpcLoggerProvider : ILoggerProvider
|
||||
internal sealed class GrpcLoggerProvider : ILoggerProvider
|
||||
{
|
||||
public ILogger CreateLogger(string categoryName) => new GrpcLogger(categoryName);
|
||||
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Pal.Client.Net
|
||||
{
|
||||
internal class JwtClaims
|
||||
internal sealed class JwtClaims
|
||||
{
|
||||
[JsonPropertyName("nameid")]
|
||||
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)
|
||||
{
|
||||
@ -78,9 +78,9 @@ namespace Pal.Client.Net
|
||||
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)
|
||||
{
|
||||
|
@ -1,17 +1,11 @@
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin;
|
||||
using Pal.Client.Rendering;
|
||||
using Pal.Client.Scheduled;
|
||||
using Pal.Client.Windows;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Dalamud.Logging;
|
||||
using Pal.Client.Extensions;
|
||||
using Pal.Client.Properties;
|
||||
using ECommons;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
|
||||
namespace Pal.Client.Windows
|
||||
{
|
||||
internal class StatisticsWindow : Window, IDisposable, ILanguageChanged
|
||||
internal sealed class StatisticsWindow : Window, IDisposable, ILanguageChanged
|
||||
{
|
||||
private const string WindowId = "###PalacePalStats";
|
||||
private readonly WindowSystem _windowSystem;
|
||||
@ -112,7 +112,7 @@ namespace Pal.Client.Windows
|
||||
}
|
||||
}
|
||||
|
||||
private class TerritoryStatistics
|
||||
private sealed class TerritoryStatistics
|
||||
{
|
||||
public string TerritoryName { get; }
|
||||
public uint? TrapCount { get; set; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user