diff --git a/Pal.Client/Configuration/AccountConfigurationV7.cs b/Pal.Client/Configuration/AccountConfigurationV7.cs index 2d74075..4c65342 100644 --- a/Pal.Client/Configuration/AccountConfigurationV7.cs +++ b/Pal.Client/Configuration/AccountConfigurationV7.cs @@ -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; diff --git a/Pal.Client/Configuration/ConfigurationManager.cs b/Pal.Client/Configuration/ConfigurationManager.cs index 1dfdbd7..ac2b808 100644 --- a/Pal.Client/Configuration/ConfigurationManager.cs +++ b/Pal.Client/Configuration/ConfigurationManager.cs @@ -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( 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 } } diff --git a/Pal.Client/Configuration/ConfigurationV1.cs b/Pal.Client/Configuration/ConfigurationV1.cs index 7128f52..c824f33 100644 --- a/Pal.Client/Configuration/ConfigurationV1.cs +++ b/Pal.Client/Configuration/ConfigurationV1.cs @@ -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 CachedRoles { get; set; } = new(); } - public class ImportHistoryEntry + public sealed class ImportHistoryEntry { public Guid Id { get; set; } public string? RemoteUrl { get; set; } diff --git a/Pal.Client/Configuration/ConfigurationV7.cs b/Pal.Client/Configuration/ConfigurationV7.cs index 3fc1dbf..9c2012f 100644 --- a/Pal.Client/Configuration/ConfigurationV7.cs +++ b/Pal.Client/Configuration/ConfigurationV7.cs @@ -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 Accounts { get; set; } = new(); - - [JsonIgnore] - [Obsolete] - public List 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 Accounts { get; set; } = new(); - public void RemoveAccount(string server) - { - Accounts.RemoveAll(a => a.Server == server && a.IsUsable); - } + [JsonIgnore] + [Obsolete] + public List 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); + } } } diff --git a/Pal.Client/DependencyInjection/DebugState.cs b/Pal.Client/DependencyInjection/DebugState.cs index 0a632a3..1fe7624 100644 --- a/Pal.Client/DependencyInjection/DebugState.cs +++ b/Pal.Client/DependencyInjection/DebugState.cs @@ -2,7 +2,7 @@ namespace Pal.Client.DependencyInjection { - internal class DebugState + internal sealed class DebugState { public string? DebugMessage { get; set; } diff --git a/Pal.Client/DependencyInjection/DIPlugin.cs b/Pal.Client/DependencyInjection/DependencyInjectionContext.cs similarity index 93% rename from Pal.Client/DependencyInjection/DIPlugin.cs rename to Pal.Client/DependencyInjection/DependencyInjectionContext.cs index e77e056..62241e1 100644 --- a/Pal.Client/DependencyInjection/DIPlugin.cs +++ b/Pal.Client/DependencyInjection/DependencyInjectionContext.cs @@ -22,13 +22,14 @@ namespace Pal.Client.DependencyInjection /// /// DI-aware Plugin. /// - 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(); diff --git a/Pal.Client/DependencyInjection/FrameworkService.cs b/Pal.Client/DependencyInjection/FrameworkService.cs index f3adaee..aeb05df 100644 --- a/Pal.Client/DependencyInjection/FrameworkService.cs +++ b/Pal.Client/DependencyInjection/FrameworkService.cs @@ -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; diff --git a/Pal.Client/Hooks.cs b/Pal.Client/Hooks.cs index 4250075..dbdcb4f 100644 --- a/Pal.Client/Hooks.cs +++ b/Pal.Client/Hooks.cs @@ -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; diff --git a/Pal.Client/LocalState.cs b/Pal.Client/LocalState.cs index 4044768..8713da6 100644 --- a/Pal.Client/LocalState.cs +++ b/Pal.Client/LocalState.cs @@ -12,7 +12,7 @@ namespace Pal.Client /// /// JSON for a single floor set (e.g. 51-60). /// - 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 Markers { get; set; } = new(); diff --git a/Pal.Client/Marker.cs b/Pal.Client/Marker.cs index e20d0fe..e2e79b9 100644 --- a/Pal.Client/Marker.cs +++ b/Pal.Client/Marker.cs @@ -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; } diff --git a/Pal.Client/Net/GrpcLogger.cs b/Pal.Client/Net/GrpcLogger.cs index 9c12149..717063c 100644 --- a/Pal.Client/Net/GrpcLogger.cs +++ b/Pal.Client/Net/GrpcLogger.cs @@ -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; diff --git a/Pal.Client/Net/GrpcLoggerProvider.cs b/Pal.Client/Net/GrpcLoggerProvider.cs index bf702e5..f9db63f 100644 --- a/Pal.Client/Net/GrpcLoggerProvider.cs +++ b/Pal.Client/Net/GrpcLoggerProvider.cs @@ -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); diff --git a/Pal.Client/Net/JwtClaims.cs b/Pal.Client/Net/JwtClaims.cs index 3247bba..5d8704b 100644 --- a/Pal.Client/Net/JwtClaims.cs +++ b/Pal.Client/Net/JwtClaims.cs @@ -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> + internal sealed class JwtRoleConverter : JsonConverter> { public override List Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { @@ -78,9 +78,9 @@ namespace Pal.Client.Net public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) => throw new NotImplementedException(); } - public class JwtDateConverter : JsonConverter + public sealed class JwtDateConverter : JsonConverter { - 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) { diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index 8d1449b..2ee2e09 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -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; diff --git a/Pal.Client/Windows/StatisticsWindow.cs b/Pal.Client/Windows/StatisticsWindow.cs index 05f953a..90dfe5b 100644 --- a/Pal.Client/Windows/StatisticsWindow.cs +++ b/Pal.Client/Windows/StatisticsWindow.cs @@ -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; }