mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
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# ;)
This commit is contained in:
parent
1feec26d1a
commit
8da8f34896
6 changed files with 8 additions and 51 deletions
|
@ -1,12 +1,13 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Settings for exporting boxes
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
|
||||
public sealed record BoxExportSettings
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -10,9 +10,9 @@ public static class EncounterDate
|
|||
/// <summary>
|
||||
/// Time provider to use for date fetching.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a valid date for the Nintendo DS.
|
||||
|
@ -70,28 +70,3 @@ public static class EncounterDate
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default time provider that uses <see cref="DateTime.Now"/>.
|
||||
/// </summary>
|
||||
public sealed class DefaultTimeProvider : ITimeProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Singleton instance of the default time provider.
|
||||
/// </summary>
|
||||
public static readonly DefaultTimeProvider Instance = new();
|
||||
|
||||
/// <inheritdoc cref="DateTime.Now"/>
|
||||
public DateTime Now => DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for fetching the current time.
|
||||
/// </summary>
|
||||
public interface ITimeProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Fetches the current time.
|
||||
/// </summary>
|
||||
DateTime Now { get; }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using static System.Buffers.Binary.BinaryPrimitives;
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace PKHeX.WinForms;
|
|||
/// <summary>
|
||||
/// Drawing Configuration for painting and updating controls
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
|
||||
public sealed class DrawConfig : IDisposable
|
||||
{
|
||||
|
|
|
@ -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 @@ public sealed class PKHeXSettings
|
|||
}
|
||||
}
|
||||
|
||||
[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<string> 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.")]
|
||||
|
|
|
@ -752,9 +752,10 @@ public partial class SAV_Database : Form
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue