From 8da8f34896e46bdea611409360bc04835a26e4e0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 23 Feb 2024 20:37:29 -0600 Subject: [PATCH] Use TimeProvider.System instead of manual impl Introduced in .NET 8; use it. Remove unnecessary [Serializable] tags (binary/XML serialization are not used), will eventually be obsoleted by c# ;) --- .../Slots/Exporting/BoxExportSettings.cs | 5 ++-- .../Encounters/Information/EncounterDate.cs | 29 ++----------------- .../Saves/Substructures/Gen8/BS/Contest8b.cs | 2 +- .../Controls/PKM Editor/DrawConfig.cs | 1 - PKHeX.WinForms/Properties/PKHeXSettings.cs | 19 ------------ PKHeX.WinForms/Subforms/SAV_Database.cs | 3 +- 6 files changed, 8 insertions(+), 51 deletions(-) diff --git a/PKHeX.Core/Editing/Saves/Slots/Exporting/BoxExportSettings.cs b/PKHeX.Core/Editing/Saves/Slots/Exporting/BoxExportSettings.cs index deb0037e3..a7ad3bbad 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Exporting/BoxExportSettings.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Exporting/BoxExportSettings.cs @@ -1,12 +1,13 @@ -using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace PKHeX.Core; /// /// Settings for exporting boxes /// -[Serializable] +[TypeConverter(typeof(ExpandableObjectConverter))] +[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] public sealed record BoxExportSettings { /// diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs index f0bce6b3a..70ba2cafa 100644 --- a/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs +++ b/PKHeX.Core/Legality/Encounters/Information/EncounterDate.cs @@ -10,9 +10,9 @@ public static class EncounterDate /// /// Time provider to use for date fetching. /// - public static ITimeProvider TimeProvider { get; set; } = DefaultTimeProvider.Instance; + public static TimeProvider TimeProvider { get; set; } = TimeProvider.System; - private static DateTime Now => TimeProvider.Now; + private static DateTime Now => TimeProvider.GetLocalNow().DateTime; /// /// Fetches a valid date for the Nintendo DS. @@ -70,28 +70,3 @@ public static bool IsValidDateSwitch(DateOnly date) return true; } } - -/// -/// Default time provider that uses . -/// -public sealed class DefaultTimeProvider : ITimeProvider -{ - /// - /// Singleton instance of the default time provider. - /// - public static readonly DefaultTimeProvider Instance = new(); - - /// - public DateTime Now => DateTime.Now; -} - -/// -/// Interface for fetching the current time. -/// -public interface ITimeProvider -{ - /// - /// Fetches the current time. - /// - DateTime Now { get; } -} diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/Contest8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/Contest8b.cs index 147d3de7a..e2274d773 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/Contest8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/Contest8b.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using static System.Buffers.Binary.BinaryPrimitives; diff --git a/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs b/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs index acda8877e..673cfdf4a 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs @@ -10,7 +10,6 @@ namespace PKHeX.WinForms; /// /// Drawing Configuration for painting and updating controls /// -[Serializable] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] public sealed class DrawConfig : IDisposable { diff --git a/PKHeX.WinForms/Properties/PKHeXSettings.cs b/PKHeX.WinForms/Properties/PKHeXSettings.cs index 75e073e05..6227803cd 100644 --- a/PKHeX.WinForms/Properties/PKHeXSettings.cs +++ b/PKHeX.WinForms/Properties/PKHeXSettings.cs @@ -16,7 +16,6 @@ namespace PKHeX.WinForms; [JsonSerializable(typeof(PKHeXSettings))] public sealed partial class PKHeXSettingsContext : JsonSerializerContext; -[Serializable] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] public sealed class PKHeXSettings { @@ -105,7 +104,6 @@ private static async void DumpConfigError(Exception x) } } -[Serializable] public sealed class BackupSettings { [LocalizedDescription("Automatic Backups of Save Files are copied to the backup folder when true.")] @@ -121,7 +119,6 @@ public sealed class BackupSettings public List OtherSaveFileExtensions { get; set; } = []; } -[Serializable] public sealed class StartupSettings : IStartupSettings { [Browsable(false)] @@ -197,7 +194,6 @@ public enum PluginLoadSetting UnsafeMerged, } -[Serializable] public sealed class LegalitySettings : IParseSettings { [LocalizedDescription("Checks player given Nicknames and Trainer Names for profanity. Bad words will be flagged using the 3DS console's regex lists.")] @@ -240,7 +236,6 @@ public sealed class LegalitySettings : IParseSettings public Severity CurrentHandlerMismatch { get; set; } = Severity.Invalid; } -[Serializable] public sealed class EntityConverterSettings { [LocalizedDescription("Allow PKM file conversion paths that are not possible via official methods. Individual properties will be copied sequentially.")] @@ -256,7 +251,6 @@ public sealed class EntityConverterSettings public GameVersion VirtualConsoleSourceGen2 { get; set; } = GameVersion.SI; } -[Serializable] public sealed class AdvancedSettings { [LocalizedDescription("Folder path that contains dump(s) of block hash-names. If a specific dump file does not exist, only names defined within the program's code will be loaded.")] @@ -272,7 +266,6 @@ public sealed class AdvancedSettings public string[] GetExclusionList8() => Array.ConvertAll(HideEvent8Contains.Split(',', StringSplitOptions.RemoveEmptyEntries), z => z.Trim()); } -[Serializable] public sealed class EntityDatabaseSettings { [LocalizedDescription("When loading content for the PKM Database, search within backup save files.")] @@ -298,7 +291,6 @@ public enum DatabaseSortMode SlotIdentity, } -[Serializable] public sealed class EntityEditorSettings { [LocalizedDescription("When changing the Hidden Power type, automatically maximize the IVs to ensure the highest Base Power result. Otherwise, keep the IVs as close as possible to the original.")] @@ -308,7 +300,6 @@ public sealed class EntityEditorSettings public bool ShowLegalBallsFirst { get; set; } = true; } -[Serializable] public sealed class EncounterDatabaseSettings { [LocalizedDescription("Skips searching if the user forgot to enter Species / Move(s) into the search criteria.")] @@ -324,14 +315,12 @@ public sealed class EncounterDatabaseSettings public bool UseTabsAsCriteriaAnySpecies { get; set; } = true; } -[Serializable] public sealed class MysteryGiftDatabaseSettings { [LocalizedDescription("Hides gifts if the currently loaded save file cannot (indirectly) receive them.")] public bool FilterUnavailableSpecies { get; set; } = true; } -[Serializable] public sealed class HoverSettings { [LocalizedDescription("Show PKM Slot Preview on Hover")] @@ -356,7 +345,6 @@ public sealed class HoverSettings public Point PreviewCursorShift { get; set; } = new(16, 8); } -[Serializable] public sealed class SoundSettings { [LocalizedDescription("Play Sound when loading a new Save File")] @@ -365,7 +353,6 @@ public sealed class SoundSettings public bool PlaySoundLegalityCheck { get; set; } = true; } -[Serializable] public sealed class SetImportSettings { [LocalizedDescription("Apply StatNature to Nature on Import")] @@ -374,7 +361,6 @@ public sealed class SetImportSettings public bool ApplyMarkings { get; set; } = true; } -[Serializable] public sealed class SlotWriteSettings { [LocalizedDescription("Automatically modify the Save File's Pokédex when injecting a PKM.")] @@ -390,7 +376,6 @@ public sealed class SlotWriteSettings public bool ModifyUnset { get; set; } = true; } -[Serializable] public sealed class DisplaySettings { [LocalizedDescription("Show Unicode gender symbol characters, or ASCII when disabled.")] @@ -409,7 +394,6 @@ public sealed class DisplaySettings public bool DisableScalingDpi { get; set; } } -[Serializable] public sealed class SpriteSettings : ISpriteSettings { [LocalizedDescription("Choice for which sprite building mode to use.")] @@ -455,7 +439,6 @@ public sealed class SpriteSettings : ISpriteSettings public byte ShowTeraOpacityStripe { get; set; } = 0xAF; // 0xFF opaque } -[Serializable] public sealed class PrivacySettings { [LocalizedDescription("Hide Save File Details in Program Title")] @@ -465,14 +448,12 @@ public sealed class PrivacySettings public bool HideSecretDetails { get; set; } } -[Serializable] public sealed class BulkAnalysisSettings : IBulkAnalysisSettings { [LocalizedDescription("Checks the save file data and Current Handler state to determine if the Pokémon's Current Handler does not match the expected value.")] public bool CheckActiveHandler { get; set; } = true; } -[Serializable] public sealed class SlotExportSettings { [LocalizedDescription("Settings to use for box exports.")] diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 1bcb75074..5395f2cf7 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -752,9 +752,10 @@ private void Menu_DeleteClones_Click(object sender, EventArgs e) private static DateTime GetRevisedTime(SlotCache arg) { + // This isn't displayed to the user, so just return the quickest -- Utc (not local time). var src = arg.Source; if (src is not SlotInfoFile f) - return DateTime.Now; + return DateTime.UtcNow; return File.GetLastWriteTimeUtc(f.Path); }