From fb9c18c151ea5da6deb3d9c192e81651a5bb8ade Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Mon, 18 Jul 2016 20:36:52 -0700 Subject: [PATCH] Tweak casting I'm a little too averse for extra lines of code :) Regarding remaining discussion on #136 Resharper gives suggestion to null check Path.GetFileNameWithoutExtension and Path.GetExtension, so it won't hurt. Just because it's set up to work properly now doesn't mean someone modifying it / operating systems years from now will supply the correct arguments. --- MainWindow/Main.cs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/MainWindow/Main.cs b/MainWindow/Main.cs index 8c4a85053..fa48ba3c8 100644 --- a/MainWindow/Main.cs +++ b/MainWindow/Main.cs @@ -2705,12 +2705,16 @@ private void updateU64(object sender, EventArgs e) // Currently saved Value ulong oldval = 0; - if (tb == TB_GameSync) - oldval = ((SAV6) SAV).GameSyncID; - else if (tb == TB_Secure1) - oldval = ((SAV6) SAV).Secure1; - else if (tb == TB_Secure2) - oldval = ((SAV6) SAV).Secure2; + if (SAV.Generation == 6) + { + SAV6 sav6 = (SAV6) SAV; + if (tb == TB_GameSync) + oldval = sav6.GameSyncID; + else if (tb == TB_Secure1) + oldval = sav6.Secure1; + else if (tb == TB_Secure2) + oldval = sav6.Secure2; + } string filterText = Util.getOnlyHex(tb.Text); @@ -2724,14 +2728,17 @@ private void updateU64(object sender, EventArgs e) // Write final value back to the save ulong newval = Convert.ToUInt64(filterText, 16); - if (newval != oldval) + if (newval == oldval) return; + + if (SAV.Generation == 6) { + SAV6 sav6 = (SAV6) SAV; if (tb == TB_GameSync) - ((SAV6) SAV).GameSyncID = newval; + sav6.GameSyncID = newval; else if (tb == TB_Secure1) - ((SAV6) SAV).Secure1 = newval; + sav6.Secure1 = newval; else if (tb == TB_Secure2) - ((SAV6) SAV).Secure2 = newval; + sav6.Secure2 = newval; SAV.Edited = true; } }