From a005767463ca47528f5b62816906eb873cb75198 Mon Sep 17 00:00:00 2001 From: goyuken Date: Fri, 27 Dec 2013 04:41:50 +0000 Subject: [PATCH] random cleanup --- BizHawk.Client.Common/RomLoader.cs | 22 +++---------------- BizHawk.Client.Common/config/Config.cs | 11 ++-------- BizHawk.Client.EmuHawk/MainForm.cs | 4 ++-- BizHawk.Common/Util.cs | 11 +++++----- BizHawk.Emulation.Common/Database/Database.cs | 4 ++-- .../Consoles/Atari/2600/Atari2600.Core.cs | 3 +-- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 3 +-- 7 files changed, 17 insertions(+), 41 deletions(-) diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 89c66d855e..040af8817b 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -28,23 +28,8 @@ namespace BizHawk.Client.Common { public class RomLoader { - #region Duplicate code to mainform, need to refactor! - - /* - object __SyncSettingsHack = null; - - object GetCoreSyncSettings() - where T : IEmulator - { - // if movie 2.0 was finished, this is where you'd decide whether to get a settings object - // from a config file or from the movie file - - // since all we have right now is movie 1.0, we get silly hacks instead - - return __SyncSettingsHack ?? Global.Config.GetCoreSyncSettings(); - } - */ - + // helper methods for the settings events + object GetCoreSettings() where T : IEmulator { @@ -63,7 +48,6 @@ namespace BizHawk.Client.Common return e.Settings; } - #endregion #region SNES specific stuff - clean up or move elsewhere private readonly Dictionary _snesPrepared = new Dictionary(); @@ -357,7 +341,7 @@ namespace BizHawk.Client.Common , game.System); } - game.FirmwareHash = Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(rom.RomData)); + game.FirmwareHash = Util.Hash_SHA1(rom.RomData); nextEmulator = new PCEngine(nextComm, game, disc, rom.RomData, GetCoreSettings()); break; } diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 6f5bdab3b3..7a2a7b0c7e 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -581,17 +581,10 @@ namespace BizHawk.Client.Common public bool SNESUseRingBuffer = true; public bool SNESAlwaysDoubleSize = false; - //N64 settings - - //TI 83 settings - //GB settings - //public bool GB_ForceDMG = false; - //public bool GB_GBACGB = false; - //public bool GB_MulticartCompat = false; - //public string GB_PaletteFile = ""; + // as this setting spans multiple cores and doesn't actually affect the behavior of any core, + // it hasn't been absorbed into the new system public bool GB_AsSGB = false; - //public GBColors.ColorType CGBColors = GBColors.ColorType.gambatte; //GIF Animator Settings public int GifAnimatorNumFrames; diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 33cfc1b712..afc4d65947 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2907,8 +2907,8 @@ namespace BizHawk.Client.EmuHawk Global.Emulator.CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n", loader.Game.Name, - Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(loader.Rom.RomData)), - Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(loader.Rom.RomData))); + Util.Hash_SHA1(loader.Rom.RomData), + Util.Hash_MD5(loader.Rom.RomData)); } if (Global.Emulator.BoardName != null) diff --git a/BizHawk.Common/Util.cs b/BizHawk.Common/Util.cs index 19b2f567de..7c9d2c756c 100644 --- a/BizHawk.Common/Util.cs +++ b/BizHawk.Common/Util.cs @@ -26,6 +26,11 @@ namespace BizHawk.Common } } + public static string Hash_MD5(byte[] data) + { + return Hash_MD5(data, 0, data.Length); + } + public static string Hash_SHA1(byte[] data, int offset, int len) { using (var sha1 = System.Security.Cryptography.SHA1.Create()) @@ -37,11 +42,7 @@ namespace BizHawk.Common public static string Hash_SHA1(byte[] data) { - using (var sha1 = System.Security.Cryptography.SHA1.Create()) - { - sha1.TransformFinalBlock(data, 0, data.Length); - return BytesToHexString(sha1.Hash); - } + return Hash_SHA1(data, 0, data.Length); } public static bool IsPowerOfTwo(int x) diff --git a/BizHawk.Emulation.Common/Database/Database.cs b/BizHawk.Emulation.Common/Database/Database.cs index b47c5bf059..521b0c8454 100644 --- a/BizHawk.Emulation.Common/Database/Database.cs +++ b/BizHawk.Emulation.Common/Database/Database.cs @@ -114,11 +114,11 @@ namespace BizHawk.Emulation.Common if (db.TryGetValue(hash, out cgi)) return new GameInfo(cgi); - hash = Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(RomData)); + hash = Util.Hash_MD5(RomData); if (db.TryGetValue(hash, out cgi)) return new GameInfo(cgi); - hash = Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(RomData)); + hash = Util.Hash_SHA1(RomData); if (db.TryGetValue(hash, out cgi)) return new GameInfo(cgi); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index bb812c61d8..2593d24f08 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -197,8 +197,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"", game.Name, - Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(rom)), - Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(rom)), + Util.Hash_SHA1(rom), Util.Hash_MD5(rom), mapper.GetType()); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 141ca8e634..c45ff9b36a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -95,8 +95,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n", game.Name, - Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(romdata)), - Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(romdata)) + Util.Hash_SHA1(romdata), Util.Hash_MD5(romdata) ); TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);