switch game database to support multiple hash types
This commit is contained in:
parent
4bd164b6b2
commit
757d604784
|
@ -12,7 +12,12 @@ namespace BizHawk
|
|||
public string Name;
|
||||
public string System;
|
||||
public string MetaData;
|
||||
public int CRC32;
|
||||
public string hash;
|
||||
|
||||
public enum HashType
|
||||
{
|
||||
CRC32, MD5
|
||||
}
|
||||
|
||||
public string[] GetOptions()
|
||||
{
|
||||
|
@ -24,7 +29,7 @@ namespace BizHawk
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -41,11 +46,11 @@ namespace BizHawk
|
|||
string[] items = line.Split('\t');
|
||||
|
||||
var Game = new GameInfo();
|
||||
Game.CRC32 = Int32.Parse(items[0], NumberStyles.HexNumber);
|
||||
Game.hash = items[0];
|
||||
Game.Name = items[2];
|
||||
Game.System = items[3];
|
||||
Game.MetaData = items.Length >= 6 ? items[5] : null;
|
||||
db[Game.CRC32] = Game;
|
||||
db[Game.hash] = Game;
|
||||
} catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Error parsing database entry: "+line);
|
||||
|
@ -56,13 +61,17 @@ namespace BizHawk
|
|||
|
||||
public static GameInfo GetGameInfo(byte[] RomData, string fileName)
|
||||
{
|
||||
int crc = CRC32.Calculate(RomData);
|
||||
if (db.ContainsKey(crc))
|
||||
return db[crc];
|
||||
string hash = string.Format("{0:X8}", CRC32.Calculate(RomData));
|
||||
if (db.ContainsKey(hash))
|
||||
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
|
||||
var Game = new GameInfo();
|
||||
Game.CRC32 = crc;
|
||||
Game.hash = hash;
|
||||
Game.MetaData = "NotInDatabase";
|
||||
|
||||
string ext = Path.GetExtension(fileName).ToUpperInvariant();
|
||||
|
|
|
@ -54,8 +54,8 @@ namespace BizHawk
|
|||
|
||||
// ============== Default Logger Action ==============
|
||||
|
||||
private static bool LogToConsole;
|
||||
private static bool LogToFile;
|
||||
private static bool LogToConsole = false;
|
||||
private static bool LogToFile = false;
|
||||
|
||||
private static string LogFilename = "bizhawk.txt";
|
||||
private static StreamWriter writer;
|
||||
|
|
|
@ -235,5 +235,19 @@ namespace BizHawk
|
|||
return j + 1;
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2257,3 +2257,5 @@ D5C782F2 V Bonk's Adventure (bad dump) PCE
|
|||
3B13AF61 Battle Ace SGX
|
||||
B486A8ED Dai Makai Mura SGX
|
||||
1F041166 Madoo Granzort SGX
|
||||
|
||||
D4448D09BBFDE687C04F9E3310E023AB ti83_1.rom TI83
|
||||
|
|
Loading…
Reference in New Issue