diff --git a/PKHeX.WinForms/Settings/EntityEditorSettings.cs b/PKHeX.Core/Editing/Program/Settings/EntityEditorSettings.cs similarity index 100% rename from PKHeX.WinForms/Settings/EntityEditorSettings.cs rename to PKHeX.Core/Editing/Program/Settings/EntityEditorSettings.cs diff --git a/PKHeX.Core/Legality/Moves/Breeding/EggSource.cs b/PKHeX.Core/Legality/Moves/Breeding/EggSource.cs index ba5fed495..5247dac17 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/EggSource.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/EggSource.cs @@ -1,4 +1,3 @@ -using System; using static PKHeX.Core.LearnMethod; namespace PKHeX.Core; diff --git a/PKHeX.Core/PKM/Strings/StringConverter1.cs b/PKHeX.Core/PKM/Strings/StringConverter1.cs index faa782f25..7d068f766 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter1.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter1.cs @@ -16,9 +16,10 @@ public static class StringConverter1 public const char Terminator = '\0'; public const char TradeOT = '*'; - public static bool GetIsJapanese(ReadOnlySpan str) => AllJapanese(str); - - private static bool AllJapanese(ReadOnlySpan str) + /// + /// Quick check if the input string is entirely Japanese characters. + /// + public static bool GetIsJapanese(ReadOnlySpan str) { foreach (var x in str) { @@ -202,6 +203,7 @@ private static bool TryGetUserFriendlyRemap(in ReadOnlySpan dict, char c, #region Gen 1 Character Tables + // Share all to Gen2's tables. internal const char NUL = Terminator; internal const char TOT = TradeOT; internal const char LPK = '{'; // Pk @@ -210,9 +212,9 @@ private static bool TryGetUserFriendlyRemap(in ReadOnlySpan dict, char c, internal const char LPO = '@'; // Po internal const char LKE = '#'; // Ke internal const char LEA = '%'; // é for Box/Mail - public const char DOT = '․'; // . for MR.MIME (U+2024, not U+002E) + internal const char DOT = '․'; // . for MR.MIME (U+2024, not U+002E) internal const char SPF = ' '; // Full-width space (U+3000) - public const char SPH = ' '; // Half-width space + internal const char SPH = ' '; // Half-width space public static ReadOnlySpan TableEN => [ diff --git a/PKHeX.Core/PKM/Strings/StringConverter2.cs b/PKHeX.Core/PKM/Strings/StringConverter2.cs index e2ae0f0c3..869227559 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter2.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter2.cs @@ -18,18 +18,7 @@ public static class StringConverter2 public const char TradeOT = StringConverter1.TradeOT; public const char LineBreak = '⏎'; // Mail - public static bool GetIsJapanese(ReadOnlySpan str) => AllJapanese(str); - - private static bool AllJapanese(ReadOnlySpan str) - { - foreach (var x in str) - { - if (!IsJapanese(x)) - return false; - } - return true; - static bool IsJapanese(char c) => c is >= '\u3000' and <= '\u30FC'; - } + public static bool GetIsJapanese(ReadOnlySpan str) => StringConverter1.GetIsJapanese(str); public static bool GetIsEnglish(ReadOnlySpan str) => !GetIsJapanese(str); public static bool GetIsJapanese(ReadOnlySpan raw) => AllCharsInTable(raw, TableJP); diff --git a/PKHeX.Core/PKM/Strings/StringConverter4GC.cs b/PKHeX.Core/PKM/Strings/StringConverter4GC.cs index 30e5bc4ac..751dec1ab 100644 --- a/PKHeX.Core/PKM/Strings/StringConverter4GC.cs +++ b/PKHeX.Core/PKM/Strings/StringConverter4GC.cs @@ -204,7 +204,7 @@ public static int LoadStringUnicodeBR(ReadOnlySpan data, Span result return ctr; } - /// + /// public static int SetStringUnicodeBR(ReadOnlySpan value, Span destBuffer, int maxLength = -1, StringConverterOption option = StringConverterOption.ClearZero) { if (maxLength < 0) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 685559048..54cf07ece 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -121,14 +121,7 @@ private void LoadBlankSaveFile(GameVersion version) if (!version.IsValidSavedVersion()) version = Latest.Version; var current = C_SAV?.SAV; - var lang = BlankSaveFile.GetSafeLanguage(current); - var tr = BlankSaveFile.GetSafeTrainerName(current, lang); - var sav = BlankSaveFile.Get(version, tr, lang); - if (sav.Version == GameVersion.Invalid) // will fail to load - { - version = Latest.Version; - sav = BlankSaveFile.Get(version, tr, lang); - } + var sav = BlankSaveFile.Get(version, current); OpenSAV(sav, string.Empty); C_SAV!.SAV.State.Edited = false; // Prevents form close warning from showing until changes are made } @@ -425,7 +418,7 @@ private void MainMenuFolder(object sender, EventArgs e) } // Misc Options - private void ClickShowdownImportPKM(object sender, EventArgs e) + private void ClickShowdownImportPKM(object? sender, EventArgs e) { if (!Clipboard.ContainsText()) { WinFormsUtil.Alert(MsgClipboardFailRead); return; } @@ -1146,42 +1139,49 @@ private void Main_DragDrop(object? sender, DragEventArgs? e) // ReSharper disable once AsyncVoidMethod private async void Dragout_MouseDown(object sender, MouseEventArgs e) { - if (e.Button != MouseButtons.Left) - return; - - if (ModifierKeys is Keys.Alt or Keys.Shift) - { - ClickQR(sender, e); - return; - } - - if (!PKME_Tabs.EditsComplete) - return; - - // Gather data - var pk = PreparePKM(); - var encrypt = ModifierKeys == Keys.Control; - var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData; - - // Create Temp File to Drag - var newfile = FileUtil.GetPKMTempFileName(pk, encrypt); try { - await File.WriteAllBytesAsync(newfile, data).ConfigureAwait(true); + if (e.Button != MouseButtons.Left) + return; - var pb = (PictureBox)sender; - if (pb.Image is Bitmap img) - C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon()); + if (ModifierKeys is Keys.Alt or Keys.Shift) + { + ClickQR(sender, e); + return; + } - DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy); + if (!PKME_Tabs.EditsComplete) + return; + + // Gather data + var pk = PreparePKM(); + var encrypt = ModifierKeys == Keys.Control; + var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData; + + // Create Temp File to Drag + var newfile = FileUtil.GetPKMTempFileName(pk, encrypt); + try + { + await File.WriteAllBytesAsync(newfile, data).ConfigureAwait(true); + + var pb = (PictureBox)sender; + if (pb.Image is Bitmap img) + C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon()); + + DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy); + } + // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. + catch (Exception x) + { WinFormsUtil.Error("Drag && Drop Error", x); } + finally + { + C_SAV.M.Drag.ResetCursor(this); + await DeleteAsync(newfile, 20_000).ConfigureAwait(false); + } } - // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. - catch (Exception x) - { WinFormsUtil.Error("Drag && Drop Error", x); } - finally + catch { - C_SAV.M.Drag.ResetCursor(this); - await DeleteAsync(newfile, 20_000).ConfigureAwait(false); + // Ignore. } } diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index b612b0ecf..f3afe1343 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -613,26 +613,33 @@ static ushort GetU16(ListControl cb) // ReSharper disable once AsyncVoidMethod private async void B_Search_Click(object sender, EventArgs e) { - B_Search.Enabled = false; - var search = SearchDatabase(); - - bool legalSearch = Menu_SearchLegal.Checked ^ Menu_SearchIllegal.Checked; - bool wordFilter = ParseSettings.Settings.WordFilter.CheckWordFilter; - if (wordFilter && legalSearch && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBSearchLegalityWordfilter) == DialogResult.No) - ParseSettings.Settings.WordFilter.CheckWordFilter = false; - var results = await Task.Run(() => search.ToList()).ConfigureAwait(true); - ParseSettings.Settings.WordFilter.CheckWordFilter = wordFilter; - - if (results.Count == 0) + try { - if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked && !Menu_SearchBackups.Checked) - WinFormsUtil.Alert(MsgDBSearchFail, MsgDBSearchNone); - else - WinFormsUtil.Alert(MsgDBSearchNone); + B_Search.Enabled = false; + var search = SearchDatabase(); + + bool legalSearch = Menu_SearchLegal.Checked ^ Menu_SearchIllegal.Checked; + bool wordFilter = ParseSettings.Settings.WordFilter.CheckWordFilter; + if (wordFilter && legalSearch && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBSearchLegalityWordfilter) == DialogResult.No) + ParseSettings.Settings.WordFilter.CheckWordFilter = false; + var results = await Task.Run(() => search.ToList()).ConfigureAwait(true); + ParseSettings.Settings.WordFilter.CheckWordFilter = wordFilter; + + if (results.Count == 0) + { + if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked && !Menu_SearchBackups.Checked) + WinFormsUtil.Alert(MsgDBSearchFail, MsgDBSearchNone); + else + WinFormsUtil.Alert(MsgDBSearchNone); + } + SetResults(results); // updates Count Label as well. + System.Media.SystemSounds.Asterisk.Play(); + B_Search.Enabled = true; + } + catch + { + // Ignore. } - SetResults(results); // updates Count Label as well. - System.Media.SystemSounds.Asterisk.Play(); - B_Search.Enabled = true; } private void UpdateScroll(object sender, ScrollEventArgs e) diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index 923c745f1..1a82db556 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -412,31 +412,38 @@ static ushort GetU16(ListControl cb) // ReSharper disable once AsyncVoidMethod private async void B_Search_Click(object sender, EventArgs e) { - B_Search.Enabled = false; - EncounterMovesetGenerator.PriorityList = GetTypes(); - - var token = TokenSource.Token; - var search = SearchDatabase(token); - if (token.IsCancellationRequested) + try { - EncounterMovesetGenerator.ResetFilters(); - return; - } + B_Search.Enabled = false; + EncounterMovesetGenerator.PriorityList = GetTypes(); - var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true); - if (token.IsCancellationRequested) + var token = TokenSource.Token; + var search = SearchDatabase(token); + if (token.IsCancellationRequested) + { + EncounterMovesetGenerator.ResetFilters(); + return; + } + + var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true); + if (token.IsCancellationRequested) + { + EncounterMovesetGenerator.ResetFilters(); + return; + } + + if (results.Count == 0) + WinFormsUtil.Alert(MsgDBSearchNone); + + SetResults(results); // updates Count Label as well. + System.Media.SystemSounds.Asterisk.Play(); + B_Search.Enabled = true; + EncounterMovesetGenerator.ResetFilters(); + } + catch { - EncounterMovesetGenerator.ResetFilters(); - return; + // Ignore. } - - if (results.Count == 0) - WinFormsUtil.Alert(MsgDBSearchNone); - - SetResults(results); // updates Count Label as well. - System.Media.SystemSounds.Asterisk.Play(); - B_Search.Enabled = true; - EncounterMovesetGenerator.ResetFilters(); } private void UpdateScroll(object sender, ScrollEventArgs e) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_BattlePass.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_BattlePass.cs index 093c79f1f..2b6b724c5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_BattlePass.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_BattlePass.cs @@ -31,15 +31,15 @@ public partial class SAV_BattlePass : Form private readonly string[] Skin = WinFormsTranslator.GetEnumTranslation(Main.CurrentLanguage); private readonly string[] PictureTypes = WinFormsTranslator.GetEnumTranslation(Main.CurrentLanguage); private readonly string[] PassDesigns = GameLanguage.GetStrings("pass_design", Main.CurrentLanguage); - private readonly string[] TrainerTitles1 = GameLanguage.GetStrings($"trainer_title", Main.CurrentLanguage); - private readonly string[] TrainerTitles2 = GameLanguage.GetStrings($"trainer_title_npc", Main.CurrentLanguage); + private readonly string[] TrainerTitles1 = GameLanguage.GetStrings("trainer_title", Main.CurrentLanguage); + private readonly string[] TrainerTitles2 = GameLanguage.GetStrings("trainer_title_npc", Main.CurrentLanguage); private readonly IReadOnlyList Languages = GameInfo.LanguageDataSource(3); private readonly IReadOnlyList EmptyCBList = [new ComboItem(string.Empty, 0)]; private const string NPC = "NPC"; private string None => CharacterStyles[0]; - private bool loading = true; + private bool loading; public SAV_BattlePass(SAV4BR sav, IPKMView view, int index = 0) { @@ -323,7 +323,7 @@ private void LoadBattlePassList() string type = WinFormsTranslator.TranslateEnum(SAV.BattlePasses.GetPassType(i), Main.CurrentLanguage); BattlePass pass = GetBattlePassReference(i); string name = pass.Name; - if ((!pass.Rental && !pass.Issued) || string.IsNullOrWhiteSpace(name)) + if (pass is { Rental: false, Issued: false } || string.IsNullOrWhiteSpace(name)) name = None; LB_Passes.Items.Add($"{i + 1:00} {type}/{name}"); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index cfa291207..230bcf4e1 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -470,40 +470,47 @@ private void ImportQRToView(string url) // ReSharper disable once AsyncVoidMethod private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e) { - if (sender is null) - return; - switch (ModifierKeys) - { - case Keys.Control: ClickView(sender, e); return; - case Keys.Shift: ClickSet(sender, e); return; - case Keys.Alt: ClickDelete(sender, e); return; - } - var pb = sender as PictureBox; - if (pb?.Image is null) - return; - - if (e.Button != MouseButtons.Left || e.Clicks != 1) - return; - - int index = pba.IndexOf(pb); - var gift = Album[index]; - if (gift.IsEmpty) - return; - - // Create Temp File to Drag - wc_slot = index; - Cursor.Current = Cursors.Hand; - string newfile = Path.Combine(Path.GetTempPath(), PathUtil.CleanFileName(gift.FileName)); try { - File.WriteAllBytes(newfile, gift.Write()); - DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy | DragDropEffects.Move); + if (sender is null) + return; + switch (ModifierKeys) + { + case Keys.Control: ClickView(sender, e); return; + case Keys.Shift: ClickSet(sender, e); return; + case Keys.Alt: ClickDelete(sender, e); return; + } + var pb = sender as PictureBox; + if (pb?.Image is null) + return; + + if (e.Button != MouseButtons.Left || e.Clicks != 1) + return; + + int index = pba.IndexOf(pb); + var gift = Album[index]; + if (gift.IsEmpty) + return; + + // Create Temp File to Drag + wc_slot = index; + Cursor.Current = Cursors.Hand; + string newfile = Path.Combine(Path.GetTempPath(), PathUtil.CleanFileName(gift.FileName)); + try + { + File.WriteAllBytes(newfile, gift.Write()); + DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy | DragDropEffects.Move); + } + // Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message. + catch (Exception x) + { WinFormsUtil.Error("Drag & Drop Error", x); } + wc_slot = -1; + await DeleteAsync(newfile, 20_000).ConfigureAwait(false); + } + catch + { + // Ignore. } - // Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message. - catch (Exception x) - { WinFormsUtil.Error("Drag & Drop Error", x); } - wc_slot = -1; - await DeleteAsync(newfile, 20_000).ConfigureAwait(false); } private static async Task DeleteAsync(string path, int delay) diff --git a/PKHeX.WinForms/Util/WinFormsTranslator.cs b/PKHeX.WinForms/Util/WinFormsTranslator.cs index bf1a6f56c..f721c9a44 100644 --- a/PKHeX.WinForms/Util/WinFormsTranslator.cs +++ b/PKHeX.WinForms/Util/WinFormsTranslator.cs @@ -154,7 +154,7 @@ private static IEnumerable GetTranslatableControls(Control f) if (z is ListControl or TextBoxBase or LinkLabel or NumericUpDown or ContainerControl) break; // undesirable to modify, ignore - if (z is DataGridView dgv && dgv.ColumnHeadersVisible) + if (z is DataGridView { ColumnHeadersVisible: true } dgv) { foreach (DataGridViewColumn col in dgv.Columns) { diff --git a/Tests/PKHeX.Core.Tests/General/LocalizationTests.cs b/Tests/PKHeX.Core.Tests/General/LocalizationTests.cs index bc8baab12..26ebd8792 100644 --- a/Tests/PKHeX.Core.Tests/General/LocalizationTests.cs +++ b/Tests/PKHeX.Core.Tests/General/LocalizationTests.cs @@ -5,14 +5,14 @@ namespace PKHeX.Core.Tests; public static class LocalizationTests { [Fact] - public static void EncounterDisplay() => EncounterDisplayLocalization.Cache.GetAll(); + public static void EncounterDisplay() => _ = EncounterDisplayLocalization.Cache.GetAll(); [Fact] - public static void MoveSource() => MoveSourceLocalization.Cache.GetAll(); + public static void MoveSource() => _ = MoveSourceLocalization.Cache.GetAll(); [Fact] - public static void LegalityCheck() => LegalityCheckLocalization.Cache.GetAll(); + public static void LegalityCheck() => _ = LegalityCheckLocalization.Cache.GetAll(); [Fact] - public static void General() => GeneralLocalization.Cache.GetAll(); + public static void General() => _ = GeneralLocalization.Cache.GetAll(); } diff --git a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs index 8dbe5421f..6031c4691 100644 --- a/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/LegalityTests.cs @@ -134,8 +134,6 @@ private static void VerifyAll(string folder, string subFolder, bool isValid, boo ParseSettings.Settings.Tradeback.AllowGen1Tradeback = dn.Contains("1 Tradeback"); var pk = EntityFormat.GetFromBytes(data, prefer); pk.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded"); - if (pk is null) - continue; var legality = new LegalityAnalysis(pk); if (legality.Valid == isValid) {