From f3a9a9d7c2f80ed7331af78c1615de5bb88094eb Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 18 Jan 2020 13:27:48 -0800 Subject: [PATCH] Misc nullable handling update for winforms Didn't enable it; there's some side effects from properties that used to be null in PKHeX.Core there's probably more, but just handling a few. Closes #2642 --- .../Controls/SAV Editor/BoxMenuStrip.cs | 4 ++-- .../Controls/SAV Editor/SAVEditor.cs | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs index 8870d3d36..3a4d81168 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxMenuStrip.cs @@ -135,10 +135,10 @@ public BoxManipulatorWF(SAVEditor editor) protected override bool CanManipulateRegion(int start, int end, string prompt, string fail) { - if (prompt != null && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes) + if (!string.IsNullOrEmpty(prompt) && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes) return false; bool canModify = base.CanManipulateRegion(start, end, prompt, fail); - if (!canModify && fail != null) + if (!canModify && !string.IsNullOrEmpty(fail)) WinFormsUtil.Alert(fail); return canModify; } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 2bf5a65db..82677b37c 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -265,8 +265,9 @@ private void ResetDaycare() else { L_SlotOccupied[i].Text = $"{i + 1}: ✘"; - if (pb.Image != null) - pb.Image = ImageUtil.ChangeOpacity(pb.Image, 0.6); + var current = pb.Image; + if (current != null) + pb.Image = ImageUtil.ChangeOpacity(current, 0.6); } } @@ -275,12 +276,13 @@ private void ResetDaycare() DayCare_HasEgg.Checked = egg == true; var seed = SAV.GetDaycareRNGSeed(SAV.DaycareIndex); - if (seed != null) + bool hasSeed = !string.IsNullOrEmpty(seed); + if (hasSeed) { TB_RNGSeed.MaxLength = SAV.DaycareSeedSize; TB_RNGSeed.Text = seed; } - L_DaycareSeed.Visible = TB_RNGSeed.Visible = seed != null; + L_DaycareSeed.Visible = TB_RNGSeed.Visible = hasSeed; } private PictureBox UpdateSlot(int relIndex) @@ -369,7 +371,7 @@ public void FinishBoxManipulation(string message, bool all, int count) { SetPKMBoxes(); UpdateBoxViewers(all); - if (message != null) + if (!string.IsNullOrWhiteSpace(message)) WinFormsUtil.Alert(message + $" ({count})"); else SystemSounds.Asterisk.Play(); @@ -848,7 +850,7 @@ public bool OpenPCBoxBin(byte[] input, out string c) public bool OpenBattleVideo(BattleVideo b, out string c) { - if (b == null || SAV.Generation != b.Generation) + if (SAV.Generation != b.Generation) { c = MsgSaveBoxImportVideoFailGeneration; return false; @@ -1142,9 +1144,10 @@ private void ToggleViewMisc(SaveFile sav) { case 6: case 7: - TB_GameSync.Enabled = sav.GameSyncID != null; + var gsid = sav.GameSyncID; + TB_GameSync.Enabled = !string.IsNullOrEmpty(gsid); TB_GameSync.MaxLength = sav.GameSyncIDSize; - TB_GameSync.Text = (sav.GameSyncID ?? 0.ToString()).PadLeft(sav.GameSyncIDSize, '0'); + TB_GameSync.Text = (string.IsNullOrEmpty(gsid) ? 0.ToString() : gsid).PadLeft(sav.GameSyncIDSize, '0'); break; } }