public static void SaveDatabaseEntry(string path, CompactGameInfo gameInfo) { var sb = new StringBuilder(); sb .Append("sha1:") // TODO: how do we know it is sha1? .Append(gameInfo.Hash) .Append('\t'); switch (gameInfo.Status) { case RomStatus.BadDump: sb.Append("B"); break; case RomStatus.TranslatedRom: sb.Append("T"); break; case RomStatus.Overdump: sb.Append("O"); break; case RomStatus.BIOS: sb.Append("I"); break; case RomStatus.Homebrew: sb.Append("D"); break; case RomStatus.Hack: sb.Append("H"); break; case RomStatus.Unknown: sb.Append("U"); break; } sb .Append('\t') .Append(gameInfo.Name) .Append('\t') .Append(gameInfo.System) .Append('\t') .Append(gameInfo.MetaData) .Append(Environment.NewLine); try { File.AppendAllText(path, sb.ToString()); } catch (Exception ex) { string blah = ex.ToString(); } }
internal GameInfo(CompactGameInfo cgi) { Name = cgi.Name; System = cgi.System; Hash = cgi.Hash; Region = cgi.Region; Status = cgi.Status; NotInDatabase = false; ParseOptionsDictionary(cgi.MetaData); }
public static void SaveDatabaseEntry(string path, CompactGameInfo gameInfo) { var sb = new StringBuilder(); sb .Append("sha1:") // TODO: how do we know it is sha1? .Append(gameInfo.Hash) .Append('\t'); sb.Append(gameInfo.Status switch { RomStatus.BadDump => "B", RomStatus.TranslatedRom => "T", RomStatus.Overdump => "O", RomStatus.Bios => "I", RomStatus.Homebrew => "D", RomStatus.Hack => "H", RomStatus.NotInDatabase => "U", RomStatus.Unknown => "U", _ => "" });
public static void LoadDatabase(string path) { using (var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while (reader.EndOfStream == false) { var line = reader.ReadLine() ?? string.Empty; try { if (line.StartsWith(";")) { continue; // comment } if (line.StartsWith("#")) { LoadDatabase_Escape(line, Path.GetDirectoryName(path)); continue; } if (line.Trim().Length == 0) { continue; } var items = line.Split('\t'); var game = new CompactGameInfo { Hash = RemoveHashType(items[0].ToUpper()) }; // remove a hash type identifier. well don't really need them for indexing (theyre just there for human purposes) switch (items[1].Trim()) { case "B": game.Status = RomStatus.BadDump; break; case "V": game.Status = RomStatus.BadDump; break; case "T": game.Status = RomStatus.TranslatedRom; break; case "O": game.Status = RomStatus.Overdump; break; case "I": game.Status = RomStatus.BIOS; break; case "D": game.Status = RomStatus.Homebrew; break; case "H": game.Status = RomStatus.Hack; break; case "U": game.Status = RomStatus.Unknown; break; default: game.Status = RomStatus.GoodDump; break; } game.Name = items[2]; game.System = items[3]; game.MetaData = items.Length >= 6 ? items[5] : null; game.Region = items.Length >= 7 ? items[6] : string.Empty; game.ForcedCore = items.Length >= 8 ? items[7].ToLowerInvariant() : string.Empty; if (db.ContainsKey(game.Hash)) { Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, db[game.Hash].Name); } db[game.Hash] = game; } catch { Console.WriteLine("Error parsing database entry: " + line); } } } }
public static void LoadDatabase(string path) { using (var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while (reader.EndOfStream == false) { var line = reader.ReadLine() ?? string.Empty; try { if (line.StartsWith(";")) { continue; // comment } if (line.StartsWith("#")) { LoadDatabase_Escape(line, Path.GetDirectoryName(path)); continue; } if (line.Trim().Length == 0) { continue; } var items = line.Split('\t'); var game = new CompactGameInfo { Hash = RemoveHashType(items[0].ToUpper()) }; // remove a hash type identifier. well don't really need them for indexing (theyre just there for human purposes) switch (items[1].Trim()) { case "B": game.Status = RomStatus.BadDump; break; case "V": game.Status = RomStatus.BadDump; break; case "T": game.Status = RomStatus.TranslatedRom; break; case "O": game.Status = RomStatus.Overdump; break; case "I": game.Status = RomStatus.BIOS; break; case "D": game.Status = RomStatus.Homebrew; break; case "H": game.Status = RomStatus.Hack; break; case "U": game.Status = RomStatus.Unknown; break; default: game.Status = RomStatus.GoodDump; break; } game.Name = items[2]; game.System = items[3]; game.MetaData = items.Length >= 6 ? items[5] : null; game.Region = items.Length >= 7 ? items[6] : string.Empty; if (db.ContainsKey(game.Hash)) { Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, db[game.Hash].Name); } db[game.Hash] = game; } catch { Console.WriteLine("Error parsing database entry: " + line); } } } }