diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index 7d0907ee5..339233d55 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -260,10 +260,8 @@ public static bool IsFilterMatch(IEnumerable filters, object if (pi.IsValueEqual(obj, cmd.PropertyValue) == cmd.Evaluator) continue; } -#pragma warning disable CA1031 // Do not catch general exception types // User provided inputs can mismatch the type's required value format, and fail to be compared. catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); Debug.WriteLine(e.Message); @@ -307,10 +305,8 @@ internal static ModifyResult TryModifyPKM(PKM pk, IEnumerable if (!IsFilterMatch(cmd, info, pi)) return ModifyResult.Filtered; } -#pragma warning disable CA1031 // Do not catch general exception types // Swallow any error because this can be malformed user input. catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue); return ModifyResult.Error; @@ -326,10 +322,8 @@ internal static ModifyResult TryModifyPKM(PKM pk, IEnumerable if (tmp != ModifyResult.Modified) result = tmp; } -#pragma warning disable CA1031 // Do not catch general exception types // Swallow any error because this can be malformed user input. catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine(MsgBEModifyFail + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue); } diff --git a/PKHeX.Core/Game/Enums/GCVersion.cs b/PKHeX.Core/Game/Enums/GCVersion.cs index 916dd74a7..36d8abb12 100644 --- a/PKHeX.Core/Game/Enums/GCVersion.cs +++ b/PKHeX.Core/Game/Enums/GCVersion.cs @@ -3,9 +3,7 @@ /// /// analogues used by Colosseum/XD instead of the main-series values. /// -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum GCVersion : byte -#pragma warning restore CA1027 // Mark enums with FlagsAttribute { None = 0, FR = 1, diff --git a/PKHeX.Core/Game/Enums/Gender.cs b/PKHeX.Core/Game/Enums/Gender.cs index 0bd8a8690..ff3e7c1c2 100644 --- a/PKHeX.Core/Game/Enums/Gender.cs +++ b/PKHeX.Core/Game/Enums/Gender.cs @@ -4,7 +4,6 @@ /// Gender a can have /// /// provided to function for Encounter template values -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum Gender : byte { Male = 0, diff --git a/PKHeX.Core/Legality/LegalityAnalysis.cs b/PKHeX.Core/Legality/LegalityAnalysis.cs index 218d9ceab..34ccc727f 100644 --- a/PKHeX.Core/Legality/LegalityAnalysis.cs +++ b/PKHeX.Core/Legality/LegalityAnalysis.cs @@ -111,9 +111,7 @@ public LegalityAnalysis(PKM pk, PersonalInfo pi, SlotOrigin source = SlotOrigin. } #if SUPPRESS // We want to swallow any error from malformed input data from the user. The Valid state is all that we really need. -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { System.Diagnostics.Debug.WriteLine(e.Message); Valid = false; diff --git a/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus.cs b/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus.cs index 93f84b57d..7d202b02a 100644 --- a/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus.cs +++ b/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus.cs @@ -6,7 +6,6 @@ namespace PKHeX.Core /// Self-modifying RNG structure that implements xoroshiro128+ /// /// https://en.wikipedia.org/wiki/Xoroshiro128%2B - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unused")] public ref struct Xoroshiro128Plus { public const ulong XOROSHIRO_CONST = 0x82A2B175229D6A5B; diff --git a/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus8b.cs b/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus8b.cs index 794e44510..e81665bc3 100644 --- a/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus8b.cs +++ b/PKHeX.Core/Legality/RNG/Algorithms/Xoroshiro128Plus8b.cs @@ -7,7 +7,6 @@ namespace PKHeX.Core /// /// https://en.wikipedia.org/wiki/Xoroshiro128%2B /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unused")] public ref struct Xoroshiro128Plus8b { private ulong s0, s1; diff --git a/PKHeX.Core/MysteryGifts/MysteryUtil.cs b/PKHeX.Core/MysteryGifts/MysteryUtil.cs index 6afee307e..29b174bac 100644 --- a/PKHeX.Core/MysteryGifts/MysteryUtil.cs +++ b/PKHeX.Core/MysteryGifts/MysteryUtil.cs @@ -59,9 +59,7 @@ public static IEnumerable GetDescription(this MysteryGift gift, IBasicSt { AddLinesPKM(gift, strings, result); } -#pragma warning disable CA1031 // Do not catch general exception types catch { result.Add(MsgMysteryGiftParseFail); } -#pragma warning restore CA1031 // Do not catch general exception types } else switch (gift) { diff --git a/PKHeX.Core/PKM/Shared/GroundTileType.cs b/PKHeX.Core/PKM/Shared/GroundTileType.cs index 415d029fb..b5a952941 100644 --- a/PKHeX.Core/PKM/Shared/GroundTileType.cs +++ b/PKHeX.Core/PKM/Shared/GroundTileType.cs @@ -9,7 +9,6 @@ namespace PKHeX.Core /// Used in Generation 4 games, this value is set depending on what type of overworld tile the player is standing on when the is obtained. /// #pragma warning disable RCS1234 // Duplicate enum value. -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum GroundTileType : byte { None = 00, // No animation for the tile @@ -43,7 +42,6 @@ public enum GroundTileType : byte Distortion = 23, Max_Pt = 24, // Unspecific, catch-all for Pt undefined tiles. } -#pragma warning restore CA1027 // Mark enums with FlagsAttribute #pragma warning restore RCS1234 // Duplicate enum value. public static class GroundTileTypeExtensions diff --git a/PKHeX.Core/PKM/Util/QRMessageUtil.cs b/PKHeX.Core/PKM/Util/QRMessageUtil.cs index 1c2536f58..2fdeb190b 100644 --- a/PKHeX.Core/PKM/Util/QRMessageUtil.cs +++ b/PKHeX.Core/PKM/Util/QRMessageUtil.cs @@ -94,9 +94,7 @@ public static string GetMessageBase64(byte[] data, string server) url = url[(payloadBegin + 1)..]; // Trim URL to right after # return Convert.FromBase64String(url); } -#pragma warning disable CA1031 // Do not catch general exception types catch -#pragma warning restore CA1031 // Do not catch general exception types { return null; } diff --git a/PKHeX.Core/Saves/Access/SCBlockAccessor.cs b/PKHeX.Core/Saves/Access/SCBlockAccessor.cs index 9c1aac552..9797a2bf4 100644 --- a/PKHeX.Core/Saves/Access/SCBlockAccessor.cs +++ b/PKHeX.Core/Saves/Access/SCBlockAccessor.cs @@ -24,9 +24,7 @@ public abstract class SCBlockAccessor : ISaveBlockAccessor public SCBlock GetBlockSafe(uint key) { try { return GetBlock(key); } -#pragma warning disable CA1031 // Do not catch general exception types catch (KeyNotFoundException) { return new SCBlock(0, SCTypeCode.None); } -#pragma warning restore CA1031 // Do not catch general exception types } private static SCBlock BinarySearch(IReadOnlyList arr, uint key) diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs index c69070e23..8967cecfa 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs @@ -153,10 +153,8 @@ public T Value } // ReSharper disable once UnusedMember.Local -#pragma warning disable CA1822 // do not make this static, we want it to show up in a property grid as a readonly value [Description("Type of Value this Block stores")] public string ValueType => typeof(T).Name; -#pragma warning restore CA1822 public WrappedValueView(SCBlock block, object currentValue) { diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockUtil.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockUtil.cs index 8a8a99be6..5560e7371 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockUtil.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockUtil.cs @@ -101,9 +101,7 @@ public static List ImportBlocksFromFolder(string path, SAV8SWSH sav) var data = File.ReadAllBytes(f); block.ChangeData(data); } -#pragma warning disable CA1031 // Do not catch general exception types catch -#pragma warning restore CA1031 // Do not catch general exception types { failed.Add(fn); } diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCTypeCode.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCTypeCode.cs index ae80d37e7..38ad9e359 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCTypeCode.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCTypeCode.cs @@ -5,7 +5,6 @@ namespace PKHeX.Core /// /// Block type for a . /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1027:Mark enums with FlagsAttribute", Justification = "NOT FLAGS")] public enum SCTypeCode : byte { None = 0, diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCXorShift32.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCXorShift32.cs index 269e4b812..f7e2601c7 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCXorShift32.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCXorShift32.cs @@ -8,7 +8,6 @@ namespace PKHeX.Core /// This implementation allows for yielding crypto bytes on demand. /// /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unused")] public ref struct SCXorShift32 { private int Counter; diff --git a/PKHeX.Core/Saves/Substructures/Gen3/DecorationInventory3.cs b/PKHeX.Core/Saves/Substructures/Gen3/DecorationInventory3.cs index e7c0efbf1..6328aff8c 100644 --- a/PKHeX.Core/Saves/Substructures/Gen3/DecorationInventory3.cs +++ b/PKHeX.Core/Saves/Substructures/Gen3/DecorationInventory3.cs @@ -1,6 +1,5 @@ using System.Runtime.InteropServices; -#pragma warning disable CA1815 // Override equals and operator equals on value types namespace PKHeX.Core { [StructLayout(LayoutKind.Sequential)] diff --git a/PKHeX.Core/Saves/Substructures/Gen4/Seal4.cs b/PKHeX.Core/Saves/Substructures/Gen4/Seal4.cs index 60e77e560..8a9b3c6e9 100644 --- a/PKHeX.Core/Saves/Substructures/Gen4/Seal4.cs +++ b/PKHeX.Core/Saves/Substructures/Gen4/Seal4.cs @@ -4,7 +4,6 @@ /// Ball Capsule Seals used in Generation 4 save files. /// /// 80 bytes, one for each seal. -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum Seal4 { HeartA, diff --git a/PKHeX.Core/Saves/Substructures/Gen5/PassPower5.cs b/PKHeX.Core/Saves/Substructures/Gen5/PassPower5.cs index f6dc6dc9a..01cdaca4d 100644 --- a/PKHeX.Core/Saves/Substructures/Gen5/PassPower5.cs +++ b/PKHeX.Core/Saves/Substructures/Gen5/PassPower5.cs @@ -3,9 +3,7 @@ /// /// Text File 263 in Black2/White2 /// -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum PassPower5 -#pragma warning restore CA1027 // Mark enums with FlagsAttribute { Encounter_Plus1 = 0, Encounter_Plus2 = 1, diff --git a/PKHeX.Core/Saves/Substructures/Gen6/TrainerSprite6.cs b/PKHeX.Core/Saves/Substructures/Gen6/TrainerSprite6.cs index 347b814e1..b1f3b5361 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/TrainerSprite6.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/TrainerSprite6.cs @@ -1,6 +1,5 @@ namespace PKHeX.Core { -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum TrainerSprite6 { Serena = 00, diff --git a/PKHeX.Core/Saves/Substructures/Gen7/BattleTree7.cs b/PKHeX.Core/Saves/Substructures/Gen7/BattleTree7.cs index 5df5f02a0..dd4c62d05 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/BattleTree7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/BattleTree7.cs @@ -3,7 +3,6 @@ namespace PKHeX.Core { -#pragma warning disable CA1819 // Properties should not return arrays public sealed class BattleTree7 : SaveBlock { public BattleTree7(SAV7SM sav, int offset) : base(sav) => Offset = offset; diff --git a/PKHeX.Core/Saves/Substructures/Gen7/EventVarType.cs b/PKHeX.Core/Saves/Substructures/Gen7/EventVarType.cs index 134b41af6..3d03f3748 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/EventVarType.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/EventVarType.cs @@ -1,6 +1,5 @@ namespace PKHeX.Core { -#pragma warning disable CA1027 // Mark enums with FlagsAttribute public enum EventVarType { /// diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/EncounterSave8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/EncounterSave8b.cs index 2b06e3d85..5d73c45ce 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/EncounterSave8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/EncounterSave8b.cs @@ -77,13 +77,11 @@ public byte HoneyTreeNo set => Data[Offset + OFS_HoneyTree + 0x08] = value; } -#pragma warning disable CA1819 // Properties should not return arrays public HoneyTree8b[] HoneyTrees { get => GetTrees(); set => SetTrees(value); } -#pragma warning restore CA1819 // Properties should not return arrays private HoneyTree8b[] GetTrees() { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/FieldObjectSave8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/FieldObjectSave8b.cs index 6823233a1..9381a4dbb 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/FieldObjectSave8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/FieldObjectSave8b.cs @@ -15,13 +15,11 @@ public sealed class FieldObjectSave8b : SaveBlock public FieldObjectSave8b(SAV8BS sav, int offset) : base(sav) => Offset = offset; -#pragma warning disable CA1819 // Properties should not return arrays public FieldObject8b[] AllObjects { get => GetObjects(); set => SetObjects(value); } -#pragma warning restore CA1819 // Properties should not return arrays private FieldObject8b[] GetObjects() { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/MysteryBlock8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/MysteryBlock8b.cs index 019b9bd16..4d7dd6f05 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/MysteryBlock8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/MysteryBlock8b.cs @@ -78,13 +78,12 @@ public List ReceivedFlagIndexes() } #region Received Array -#pragma warning disable CA1819 // Properties should not return arrays public RecvData8b[] Received { get => GetReceived(); set => SetReceived(value); } -#pragma warning restore CA1819 // Properties should not return arrays + private RecvData8b[] GetReceived() { var result = new RecvData8b[RecvDataMax]; @@ -102,13 +101,12 @@ private void SetReceived(IReadOnlyList value) #endregion #region Flag Array -#pragma warning disable CA1819 // Properties should not return arrays public bool[] ReceivedFlags { get => GetFlags(); set => SetFlags(value); } -#pragma warning restore CA1819 // Properties should not return arrays + private bool[] GetFlags() { var result = new bool[FlagSize]; @@ -126,13 +124,11 @@ private void SetFlags(IReadOnlyList value) #endregion #region OneDay Array -#pragma warning disable CA1819 // Properties should not return arrays public OneDay8b[] OneDay { get => GetOneDay(); set => SetOneDay(value); } -#pragma warning restore CA1819 // Properties should not return arrays private OneDay8b[] GetOneDay() { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/RandomGroup8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/RandomGroup8b.cs index 12637f639..0bc6f7450 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/RandomGroup8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/RandomGroup8b.cs @@ -15,13 +15,11 @@ public sealed class RandomGroup8b : SaveBlock public RandomGroup8b(SAV8BS sav, int offset) : base(sav) => Offset = offset; -#pragma warning disable CA1819 // Properties should not return arrays public RandomSeed8b[] Seeds { get => GetSeeds(); set => SetSeeds(value); } -#pragma warning restore CA1819 // Properties should not return arrays private RandomSeed8b[] GetSeeds() { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/SealDeco8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/SealDeco8b.cs index 7975bf86c..ae733237c 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/SealDeco8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/SealDeco8b.cs @@ -21,13 +21,11 @@ public sealed class SealBallDecoData8b : SaveBlock public byte CapsuleCount { get => Data[Offset]; set => Data[Offset] = value; } -#pragma warning disable CA1819 // Properties should not return arrays public SealCapsule8b[] Capsules { get => GetCapsules(); set => SetCapsules(value); } -#pragma warning restore CA1819 // Properties should not return arrays private SealCapsule8b[] GetCapsules() { @@ -65,13 +63,11 @@ public SealCapsule8b(byte[] data, int offset) public uint EncryptionConstant { get => BitConverter.ToUInt32(Data, Offset + 4); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 4); } public uint Unknown { get => BitConverter.ToUInt32(Data, Offset + 8); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 8); } -#pragma warning disable CA1819 // Properties should not return arrays public AffixSealData8b[] Seals { get => GetSeals(); set => SetSeals(value); } -#pragma warning restore CA1819 // Properties should not return arrays private AffixSealData8b[] GetSeals() { diff --git a/PKHeX.Core/Saves/Util/BoxUtil.cs b/PKHeX.Core/Saves/Util/BoxUtil.cs index 85ecb6dc1..749637bd4 100644 --- a/PKHeX.Core/Saves/Util/BoxUtil.cs +++ b/PKHeX.Core/Saves/Util/BoxUtil.cs @@ -228,9 +228,7 @@ public static string[] GetBoxNames(SaveFile sav) for (int i = 0; i < count; i++) { try { result[i] = sav.GetBoxName(i); } -#pragma warning disable CA1031 // Do not catch general exception types catch { result[i] = $"Box {i + 1}"; } -#pragma warning restore CA1031 // Do not catch general exception types } return result; diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index 4f7f37039..f5479790c 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -786,9 +786,7 @@ public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumera result = files.Where(f => IsSizeValid(FileUtil.GetFileSize(f))); return true; } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { result = new[] { diff --git a/PKHeX.Core/Util/FileUtil.cs b/PKHeX.Core/Util/FileUtil.cs index 0679ca1c9..25a8d2877 100644 --- a/PKHeX.Core/Util/FileUtil.cs +++ b/PKHeX.Core/Util/FileUtil.cs @@ -29,10 +29,8 @@ public static class FileUtil var ext = Path.GetExtension(path); return GetSupportedFile(data, ext, reference); } -#pragma warning disable CA1031 // Do not catch general exception types // User input data can be fuzzed; if anything blows up, just fail safely. catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine(MessageStrings.MsgFileInUse); Debug.WriteLine(e.Message); @@ -71,9 +69,7 @@ public static class FileUtil public static bool IsFileLocked(string path) { try { return (File.GetAttributes(path) & FileAttributes.ReadOnly) != 0; } -#pragma warning disable CA1031 // Do not catch general exception types catch { return true; } -#pragma warning restore CA1031 // Do not catch general exception types } public static int GetFileSize(string path) @@ -85,9 +81,7 @@ public static int GetFileSize(string path) return -1; return (int)size; } -#pragma warning disable CA1031 // Do not catch general exception types catch { return -1; } // Bad File / Locked -#pragma warning restore CA1031 // Do not catch general exception types } private static bool TryGetGP1(byte[] data, [NotNullWhen(true)] out GP1? gp1) diff --git a/PKHeX.Core/Util/Localization/LocalizationUtil.cs b/PKHeX.Core/Util/Localization/LocalizationUtil.cs index 5c67e8c97..97c9fee26 100644 --- a/PKHeX.Core/Util/Localization/LocalizationUtil.cs +++ b/PKHeX.Core/Util/Localization/LocalizationUtil.cs @@ -76,10 +76,8 @@ private static void SetLocalization(Type t, IReadOnlyCollection lines) { ReflectUtil.SetValue(t, prop, value); } -#pragma warning disable CA1031 // Do not catch general exception types // Malformed translation files, log catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Property not present: {prop} || Value written: {value}"); Debug.WriteLine(e.Message); diff --git a/PKHeX.Core/Util/NetUtil.cs b/PKHeX.Core/Util/NetUtil.cs index 555284231..bf440aa75 100644 --- a/PKHeX.Core/Util/NetUtil.cs +++ b/PKHeX.Core/Util/NetUtil.cs @@ -18,10 +18,8 @@ public static class NetUtil using var reader = new StreamReader(stream); return reader.ReadToEnd(); } -#pragma warning disable CA1031 // Do not catch general exception types // No internet? catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine(e.Message); return null; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index 079f1c84d..983b671bb 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -187,10 +187,8 @@ private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external) var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData; external = TryMakeDragDropPKM(pb, data, newfile); } -#pragma warning disable CA1031 // Do not catch general exception types // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. catch (Exception x) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Drag && Drop Error", x); external = false; diff --git a/PKHeX.WinForms/Controls/Slots/CryPlayer.cs b/PKHeX.WinForms/Controls/Slots/CryPlayer.cs index 8cd9e59b9..50c0c44f5 100644 --- a/PKHeX.WinForms/Controls/Slots/CryPlayer.cs +++ b/PKHeX.WinForms/Controls/Slots/CryPlayer.cs @@ -21,9 +21,7 @@ public void PlayCry(ISpeciesForm pk, int format) Sounds.SoundLocation = path; try { Sounds.Play(); } -#pragma warning disable CA1031 // Do not catch general exception types catch { Debug.WriteLine("Failed to play sound."); } -#pragma warning restore CA1031 // Do not catch general exception types } public void Stop() @@ -32,9 +30,7 @@ public void Stop() return; try { Sounds.Stop(); } -#pragma warning disable CA1031 // Do not catch general exception types catch { Debug.WriteLine("Failed to stop sound."); } -#pragma warning restore CA1031 // Do not catch general exception types } private static string GetCryPath(ISpeciesForm pk, string cryFolder, int format) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 9575653bf..a9e04fee0 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -184,9 +184,7 @@ private void FormLoadCheckForUpdates() Version? latestVersion; // User might not be connected to the internet or with a flaky connection. try { latestVersion = UpdateUtil.GetLatestPKHeXVersion(); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Exception while checking for latest version: {ex}"); return; @@ -519,9 +517,7 @@ private void OpenFromPath(string path) return; } byte[] input; try { input = File.ReadAllBytes(path); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { WinFormsUtil.Error(MsgFileInUse + path, e); return; } -#pragma warning restore CA1031 // Do not catch general exception types string ext = fi.Extension; #if DEBUG @@ -1109,10 +1105,8 @@ private void Dragout_MouseDown(object sender, MouseEventArgs e) C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon()); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } -#pragma warning disable CA1031 // Do not catch general exception types // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. catch (Exception x) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Drag && Drop Error", x); } C_SAV.M.Drag.ResetCursor(this); File.Delete(newfile); @@ -1182,9 +1176,7 @@ private void ClickSaveFileName(object sender, EventArgs e) if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgFileLoadSaveDetectReload, path) == DialogResult.Yes) LoadFile(sav, path); // load save } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(ex.Message); // `path` contains the error message } @@ -1200,10 +1192,8 @@ private static void PromptBackup() Directory.CreateDirectory(BackupPath); WinFormsUtil.Alert(MsgBackupSuccess, string.Format(MsgBackupDelete, BackupPath)); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) // Maybe they put their exe in a folder that we can't create files/folders to. -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error($"{MsgBackupUnable} @ {BackupPath}", ex); } } diff --git a/PKHeX.WinForms/MainWindow/PluginLoader.cs b/PKHeX.WinForms/MainWindow/PluginLoader.cs index 0c540a78f..f899fc49b 100644 --- a/PKHeX.WinForms/MainWindow/PluginLoader.cs +++ b/PKHeX.WinForms/MainWindow/PluginLoader.cs @@ -24,9 +24,7 @@ public static class PluginLoader { T? activate; try { activate = (T?)Activator.CreateInstance(t); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { System.Diagnostics.Debug.WriteLine($"Unable to load plugin [{t.Name}]: {t.FullName}"); System.Diagnostics.Debug.WriteLine(ex.Message); @@ -71,10 +69,8 @@ private static IEnumerable GetPluginTypes(Assembly z, Type pluginType) var types = z.GetTypes(); return types.Where(type => IsTypePlugin(type, pluginType)); } -#pragma warning disable CA1031 // Do not catch general exception types // User plugins can be out of date, with mismatching API surfaces. catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { System.Diagnostics.Debug.WriteLine($"Unable to load plugin [{pluginType.Name}]: {z.FullName}"); System.Diagnostics.Debug.WriteLine(ex.Message); diff --git a/PKHeX.WinForms/Misc/ErrorWindow.cs b/PKHeX.WinForms/Misc/ErrorWindow.cs index 42cedda92..da6a42dfd 100644 --- a/PKHeX.WinForms/Misc/ErrorWindow.cs +++ b/PKHeX.WinForms/Misc/ErrorWindow.cs @@ -82,9 +82,7 @@ private void UpdateExceptionDetailsMessage() details.AppendLine(); } } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { details.AppendLine("An error occurred while listing the Loaded Assemblies:"); details.AppendLine(ex.ToString()); diff --git a/PKHeX.WinForms/Misc/QR.cs b/PKHeX.WinForms/Misc/QR.cs index 98da41e51..bf653d1f5 100644 --- a/PKHeX.WinForms/Misc/QR.cs +++ b/PKHeX.WinForms/Misc/QR.cs @@ -76,10 +76,8 @@ private void PB_QR_Click(object sender, EventArgs e) if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgQRClipboardImage)) return; try { Clipboard.SetImage(PB_QR.Image); } -#pragma warning disable CA1031 // Do not catch general exception types // Clipboard can be locked periodically, just notify on failure. catch { WinFormsUtil.Alert(MsgQRClipboardFail); } -#pragma warning restore CA1031 // Do not catch general exception types } private void UpdateBoxSlotCopies(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Properties/PKHeXSettings.cs b/PKHeX.WinForms/Properties/PKHeXSettings.cs index 1c20b2a28..f5321cf34 100644 --- a/PKHeX.WinForms/Properties/PKHeXSettings.cs +++ b/PKHeX.WinForms/Properties/PKHeXSettings.cs @@ -46,9 +46,7 @@ public static PKHeXSettings GetSettings(string configPath) var lines = File.ReadAllText(configPath); return JsonConvert.DeserializeObject(lines) ?? new PKHeXSettings(); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception x) -#pragma warning restore CA1031 // Do not catch general exception types { DumpConfigError(x); return new PKHeXSettings(); @@ -68,9 +66,7 @@ public static void SaveSettings(string configPath, PKHeXSettings cfg) var text = JsonConvert.SerializeObject(cfg, settings); File.WriteAllText(configPath, text); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception x) -#pragma warning restore CA1031 // Do not catch general exception types { DumpConfigError(x); } @@ -82,9 +78,7 @@ private static void DumpConfigError(Exception x) { File.WriteAllLines("config error.txt", new[] { x.ToString() }); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine(x); // ??? } @@ -100,13 +94,11 @@ public sealed class BackupSettings [LocalizedDescription("Tracks if the \"Create Backup\" prompt has been issued to the user.")] public bool BAKPrompt { get; set; } -#pragma warning disable CA1819 // Properties should not return arrays [LocalizedDescription("List of extra locations to look for Save Files.")] public string[] OtherBackupPaths { get; set; } = Array.Empty(); [LocalizedDescription("Save File file-extensions (no period) that the program should also recognize.")] public string[] OtherSaveFileExtensions { get; set; } = Array.Empty(); -#pragma warning restore CA1819 // Properties should not return arrays } [Serializable] diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index edf13f677..b6fb59a1f 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -335,9 +335,7 @@ private void LoadDatabase() while (!IsHandleCreated) { } BeginInvoke(new MethodInvoker(() => SetResults(RawDB))); } -#pragma warning disable CA1031 // Do not catch general exception types catch { /* Window Closed? */ } -#pragma warning restore CA1031 // Do not catch general exception types } private static List LoadPKMSaves(string pkmdb, SaveFile SAV, IEnumerable otherPaths, bool otherDeep) @@ -651,9 +649,7 @@ private void Menu_DeleteClones_Click(object sender, EventArgs e) continue; try { File.Delete(path); ++deleted; } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { WinFormsUtil.Error(MsgDBDeleteCloneFail + Environment.NewLine + ex.Message + Environment.NewLine + path); } -#pragma warning restore CA1031 // Do not catch general exception types } if (deleted == 0) diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index b02957135..804180e21 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -236,9 +236,7 @@ private void LoadDatabase() PopulateComboBoxes(); })); } -#pragma warning disable CA1031 // Do not catch general exception types catch { /* Window Closed? */ } -#pragma warning restore CA1031 // Do not catch general exception types } // IO Usage diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs index 7dbd04964..3907814c9 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs @@ -278,9 +278,7 @@ private void SetFlagsFromFileName(string inpFileName) return; // 24*20*4(ARGB)=1920 Bitmap bmp; try { bmp = (Bitmap)Image.FromFile(inpFileName); } -#pragma warning disable CA1031 // Do not catch general exception types catch { return; } -#pragma warning restore CA1031 // Do not catch general exception types if (bmp.Width != 24 || bmp.Height != 20) return; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs index 77639e6b9..a4de3b850 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs @@ -45,9 +45,7 @@ private void B_ImportPNG_Click(object sender, EventArgs e) bg = CGearImage.GetCGearBackground(img); PB_Background.Image = CGearImage.GetBitmap(bg); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(ex.Message); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs index 6ae4fe10f..3f08c2e30 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs @@ -100,9 +100,7 @@ private void DropClick(object sender, DataGridViewCellEventArgs e) ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; comboBox.DroppedDown = true; } -#pragma warning disable CA1031 // Do not catch general exception types catch { System.Diagnostics.Debug.WriteLine("Failed to modify item."); } -#pragma warning restore CA1031 // Do not catch general exception types } private bool loading = true; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs index 92a20a363..0c5d58bf2 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs @@ -150,9 +150,7 @@ private void GetTextBoxes() NUD_Y.Value = (decimal)sit.Y; } // If we can't accurately represent the coordinates, don't allow them to be changed. -#pragma warning disable CA1031 // Do not catch general exception types catch { GB_Map.Enabled = false; } -#pragma warning restore CA1031 // Do not catch general exception types } // Load BP and PokeMiles diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index 599b1abc4..dc71c96e3 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -131,10 +131,8 @@ private void GetTextBoxes() NUD_Y.Value = (decimal)SAV.Situation.Y; NUD_R.Value = (decimal)SAV.Situation.R; } -#pragma warning disable CA1031 // Do not catch general exception types // Sometimes the coordinates aren't really decimal/float coordinates? catch { GB_Map.Enabled = false; } -#pragma warning restore CA1031 // Do not catch general exception types // Load Play Time MT_Hours.Text = SAV.PlayedHours.ToString(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index da2e24055..b9fad8599 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -91,9 +91,7 @@ private void ViewGiftData(DataMysteryGift g) mg = g; } // Some user input mystery gifts can have out-of-bounds values. Just swallow any exception. -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e); RTB.Clear(); @@ -422,9 +420,7 @@ private void BoxSlot_MouseDown(object? sender, MouseEventArgs e) DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), 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. -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception x) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Drag & Drop Error", x); } File.Delete(newfile); wc_slot = -1; diff --git a/PKHeX.WinForms/Subforms/SettingsEditor.cs b/PKHeX.WinForms/Subforms/SettingsEditor.cs index 208063be9..914cfed71 100644 --- a/PKHeX.WinForms/Subforms/SettingsEditor.cs +++ b/PKHeX.WinForms/Subforms/SettingsEditor.cs @@ -71,9 +71,7 @@ private static void DeleteSettings() System.Diagnostics.Process.Start(Application.ExecutablePath); Environment.Exit(0); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Failed to delete settings.", ex.Message); } diff --git a/PKHeX.WinForms/Util/FontUtil.cs b/PKHeX.WinForms/Util/FontUtil.cs index fcb807210..6480fa5e2 100644 --- a/PKHeX.WinForms/Util/FontUtil.cs +++ b/PKHeX.WinForms/Util/FontUtil.cs @@ -26,9 +26,7 @@ static FontUtil() { Debug.WriteLine($"Unable to read font file: {ex.Message}"); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Unable to add in-game font: {ex.Message}"); } diff --git a/PKHeX.WinForms/Util/WinFormsTranslator.cs b/PKHeX.WinForms/Util/WinFormsTranslator.cs index 697e4fb4b..9811f17da 100644 --- a/PKHeX.WinForms/Util/WinFormsTranslator.cs +++ b/PKHeX.WinForms/Util/WinFormsTranslator.cs @@ -63,9 +63,7 @@ private static IEnumerable GetTranslationFile(string lang) if (File.Exists(externalLangPath)) { try { return File.ReadAllLines(externalLangPath); } -#pragma warning disable CA1031 // Do not catch general exception types catch { /* In use? Just return the internal resource. */ } -#pragma warning restore CA1031 // Do not catch general exception types } if (Util.IsStringListCached(file, out var result)) @@ -178,10 +176,8 @@ public static void LoadAllForms(params string[] banlist) { var _ = (Form?)System.Activator.CreateInstance(t, new object[argCount]); } -#pragma warning disable CA1031 // Do not catch general exception types // This is a debug utility method, will always be logging. Shouldn't ever fail. catch -#pragma warning restore CA1031 // Do not catch general exception types { Debug.Write($"Failed to create a new form {t}"); } diff --git a/PKHeX.WinForms/Util/WinFormsUtil.cs b/PKHeX.WinForms/Util/WinFormsUtil.cs index f267d4900..5823971e8 100644 --- a/PKHeX.WinForms/Util/WinFormsUtil.cs +++ b/PKHeX.WinForms/Util/WinFormsUtil.cs @@ -141,10 +141,8 @@ internal static bool SetClipboardText(string text) { Error(MsgClipboardFailWrite, x); } -#pragma warning disable CA1031 // Do not catch general exception types // Clipboard might be locked sometimes catch -#pragma warning restore CA1031 // Do not catch general exception types { Error(MsgClipboardFailWrite); } @@ -282,9 +280,7 @@ public static bool OpenSAVPKMDialog(IEnumerable extensions, out string? { sav = SaveFinder.FindMostRecentSaveFile(); } -#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types { Error(ex.Message); }