switch game database to support multiple hash types

This commit is contained in:
zeromus 2011-01-17 03:08:33 +00:00
parent 4bd164b6b2
commit 757d604784
4 changed files with 35 additions and 10 deletions

View File

@ -12,7 +12,12 @@ namespace BizHawk
public string Name; public string Name;
public string System; public string System;
public string MetaData; public string MetaData;
public int CRC32; public string hash;
public enum HashType
{
CRC32, MD5
}
public string[] GetOptions() public string[] GetOptions()
{ {
@ -24,7 +29,7 @@ namespace BizHawk
public static class Database public static class Database
{ {
private static Dictionary<int, GameInfo> db = new Dictionary<int, GameInfo>(); private static Dictionary<string, GameInfo> db = new Dictionary<string, GameInfo>();
public static void LoadDatabase(string path) public static void LoadDatabase(string path)
{ {
@ -41,11 +46,11 @@ namespace BizHawk
string[] items = line.Split('\t'); string[] items = line.Split('\t');
var Game = new GameInfo(); var Game = new GameInfo();
Game.CRC32 = Int32.Parse(items[0], NumberStyles.HexNumber); Game.hash = items[0];
Game.Name = items[2]; Game.Name = items[2];
Game.System = items[3]; Game.System = items[3];
Game.MetaData = items.Length >= 6 ? items[5] : null; Game.MetaData = items.Length >= 6 ? items[5] : null;
db[Game.CRC32] = Game; db[Game.hash] = Game;
} catch (Exception) } catch (Exception)
{ {
Console.WriteLine("Error parsing database entry: "+line); Console.WriteLine("Error parsing database entry: "+line);
@ -56,13 +61,17 @@ namespace BizHawk
public static GameInfo GetGameInfo(byte[] RomData, string fileName) public static GameInfo GetGameInfo(byte[] RomData, string fileName)
{ {
int crc = CRC32.Calculate(RomData); string hash = string.Format("{0:X8}", CRC32.Calculate(RomData));
if (db.ContainsKey(crc)) if (db.ContainsKey(hash))
return db[crc]; return db[hash];
hash = Util.BytesToHexString(System.Security.Cryptography.MD5.Create().ComputeHash(RomData));
if (db.ContainsKey(hash))
return db[hash];
// rom is not in database. make some best-guesses // rom is not in database. make some best-guesses
var Game = new GameInfo(); var Game = new GameInfo();
Game.CRC32 = crc; Game.hash = hash;
Game.MetaData = "NotInDatabase"; Game.MetaData = "NotInDatabase";
string ext = Path.GetExtension(fileName).ToUpperInvariant(); string ext = Path.GetExtension(fileName).ToUpperInvariant();

View File

@ -54,8 +54,8 @@ namespace BizHawk
// ============== Default Logger Action ============== // ============== Default Logger Action ==============
private static bool LogToConsole; private static bool LogToConsole = false;
private static bool LogToFile; private static bool LogToFile = false;
private static string LogFilename = "bizhawk.txt"; private static string LogFilename = "bizhawk.txt";
private static StreamWriter writer; private static StreamWriter writer;

View File

@ -235,5 +235,19 @@ namespace BizHawk
return j + 1; return j + 1;
return 0; return 0;
} }
/// <summary>
/// conerts bytes to an uppercase string of hex numbers in upper case without any spacing or anything
/// </summary>
public static string BytesToHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
sb.AppendFormat("{0:X2}", b);
return sb.ToString();
}
} }
} }

View File

@ -2257,3 +2257,5 @@ D5C782F2 V Bonk's Adventure (bad dump) PCE
3B13AF61 Battle Ace SGX 3B13AF61 Battle Ace SGX
B486A8ED Dai Makai Mura SGX B486A8ED Dai Makai Mura SGX
1F041166 Madoo Granzort SGX 1F041166 Madoo Granzort SGX
D4448D09BBFDE687C04F9E3310E023AB ti83_1.rom TI83