Remove unnecessary warning suppression

fixed dat .editorconfig in vs22
Catching general exceptions is okay because this program handles user modified data that can potentially be corrupt.
This commit is contained in:
Kurt
2021-12-27 12:09:15 -08:00
parent 5f7caf9ca2
commit cc8ac7a4f1
49 changed files with 2 additions and 128 deletions

View File

@@ -260,10 +260,8 @@ public static bool IsFilterMatch(IEnumerable<StringInstruction> 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<StringInstruction>
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<StringInstruction>
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);
}

View File

@@ -3,9 +3,7 @@
/// <summary>
/// <see cref="GameVersion"/> analogues used by Colosseum/XD instead of the main-series values.
/// </summary>
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
public enum GCVersion : byte
#pragma warning restore CA1027 // Mark enums with FlagsAttribute
{
None = 0,
FR = 1,

View File

@@ -4,7 +4,6 @@
/// Gender a <see cref="PKM"/> can have
/// </summary>
/// <remarks><see cref="Random"/> provided to function for Encounter template values</remarks>
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
public enum Gender : byte
{
Male = 0,

View File

@@ -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;

View File

@@ -6,7 +6,6 @@ namespace PKHeX.Core
/// Self-modifying RNG structure that implements xoroshiro128+
/// </summary>
/// <remarks>https://en.wikipedia.org/wiki/Xoroshiro128%2B</remarks>
[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;

View File

@@ -7,7 +7,6 @@ namespace PKHeX.Core
/// </summary>
/// <remarks>https://en.wikipedia.org/wiki/Xoroshiro128%2B</remarks>
/// <seealso cref="Xoroshiro128Plus"/>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unused")]
public ref struct Xoroshiro128Plus8b
{
private ulong s0, s1;

View File

@@ -59,9 +59,7 @@ public static IEnumerable<string> 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)
{

View File

@@ -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 <see cref="PKM"/> is obtained.
/// </remarks>
#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

View File

@@ -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;
}

View File

@@ -24,9 +24,7 @@ public abstract class SCBlockAccessor : ISaveBlockAccessor<SCBlock>
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<SCBlock> arr, uint key)

View File

@@ -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)
{

View File

@@ -101,9 +101,7 @@ public static List<string> 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);
}

View File

@@ -5,7 +5,6 @@ namespace PKHeX.Core
/// <summary>
/// Block type for a <see cref="SCBlock"/>.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1027:Mark enums with FlagsAttribute", Justification = "NOT FLAGS")]
public enum SCTypeCode : byte
{
None = 0,

View File

@@ -8,7 +8,6 @@ namespace PKHeX.Core
/// This implementation allows for yielding crypto bytes on demand.
/// </para>
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unused")]
public ref struct SCXorShift32
{
private int Counter;

View File

@@ -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)]

View File

@@ -4,7 +4,6 @@
/// Ball Capsule Seals used in Generation 4 save files.
/// </summary>
/// <remarks>80 bytes, one for each seal.</remarks>
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
public enum Seal4
{
HeartA,

View File

@@ -3,9 +3,7 @@
/// <summary>
/// Text File 263 in Black2/White2
/// </summary>
#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,

View File

@@ -1,6 +1,5 @@
namespace PKHeX.Core
{
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
public enum TrainerSprite6
{
Serena = 00,

View File

@@ -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;

View File

@@ -1,6 +1,5 @@
namespace PKHeX.Core
{
#pragma warning disable CA1027 // Mark enums with FlagsAttribute
public enum EventVarType
{
/// <summary>

View File

@@ -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()
{

View File

@@ -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()
{

View File

@@ -78,13 +78,12 @@ public List<int> 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<RecvData8b> 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<bool> 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()
{

View File

@@ -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()
{

View File

@@ -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()
{

View File

@@ -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;

View File

@@ -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[]
{

View File

@@ -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)

View File

@@ -76,10 +76,8 @@ private static void SetLocalization(Type t, IReadOnlyCollection<string> 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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)

View File

@@ -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); }
}

View File

@@ -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<Type> 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);

View File

@@ -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());

View File

@@ -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)

View File

@@ -46,9 +46,7 @@ public static PKHeXSettings GetSettings(string configPath)
var lines = File.ReadAllText(configPath);
return JsonConvert.DeserializeObject<PKHeXSettings>(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<string>();
[LocalizedDescription("Save File file-extensions (no period) that the program should also recognize.")]
public string[] OtherSaveFileExtensions { get; set; } = Array.Empty<string>();
#pragma warning restore CA1819 // Properties should not return arrays
}
[Serializable]

View File

@@ -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<SlotCache> LoadPKMSaves(string pkmdb, SaveFile SAV, IEnumerable<string> 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)

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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}");
}

View File

@@ -63,9 +63,7 @@ private static IEnumerable<string> 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}");
}

View File

@@ -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<string> 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);
}