private static void LoadRomFromDat(RvGame rvGame, XmlNode romNode) { if (romNode.Attributes == null) { return; } XmlNode name = romNode.Attributes.GetNamedItem("name"); string loadflag = VarFix.String(romNode.Attributes.GetNamedItem("loadflag")); if (name != null) { RvRom rvRom = new RvRom(); rvRom.Name = VarFix.CleanFullFileName(name); rvRom.Size = VarFix.ULong(romNode.Attributes.GetNamedItem("size")); rvRom.CRC = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8); rvRom.SHA1 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40); rvRom.Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")); _indexContinue = rvGame.AddRom(rvRom); } else if (loadflag.ToLower() == "continue") { RvRom tROM = rvGame.Roms[_indexContinue]; tROM.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size")); } else if (loadflag.ToLower() == "ignore") { RvRom tROM = rvGame.Roms[_indexContinue]; tROM.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size")); } }
private static void RomCheckCollect(RvRom tRom, bool merge) { if (merge) { if (string.IsNullOrEmpty(tRom.Merge)) { tRom.Merge = "(Auto Merged)"; } tRom.PutInZip = false; return; } if (!string.IsNullOrEmpty(tRom.Merge)) { tRom.Merge = "(No-Merge) " + tRom.Merge; } if (ArrByte.bCompare(tRom.CRC, new byte[] { 0, 0, 0, 0 }) && (tRom.Size == 0)) { tRom.PutInZip = true; return; } tRom.PutInZip = true; }
private static bool LoadRomFromDat(RvGame rvGame) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after rom", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.Next.ToLower() != "name") { DatUpdate.SendAndShowDat("Name not found as first object in ( )", DatFileLoader.Filename); return(false); } RvRom rvRom = new RvRom(); rvRom.Name = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "size": rvRom.Size = VarFix.ULong(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "crc": rvRom.CRC = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 8); DatFileLoader.Gn(); break; case "sha1": rvRom.SHA1 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 40); DatFileLoader.Gn(); break; case "md5": rvRom.MD5 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 32); DatFileLoader.Gn(); break; case "merge": rvRom.Merge = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "flags": rvRom.Status = VarFix.ToLower(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "date": DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "bios": DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "region": DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "offs": DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "nodump": rvRom.Status = "nodump"; DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in rom", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } rvGame.AddRom(rvRom); return(true); }
public static uint?Execute(RvRom tFile) { if (tFile.SHA1 != null) { CommandSHA1.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1); CommandSHA1.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); CommandSHA1.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandSHA1.Parameters["size"].Value = tFile.Size; object res = CommandSHA1.ExecuteScalar(); if (res == null || res == DBNull.Value) { return(null); } return((uint?)Convert.ToInt32(res)); } if (tFile.MD5 != null) { CommandMD5.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); CommandMD5.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandMD5.Parameters["size"].Value = tFile.Size; object res = CommandMD5.ExecuteScalar(); if (res == null || res == DBNull.Value) { return(null); } return((uint?)Convert.ToInt32(res)); } if (tFile.CRC != null) { CommandCRC.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandCRC.Parameters["size"].Value = tFile.Size; object res = CommandCRC.ExecuteScalar(); if (res == null || res == DBNull.Value) { return(null); } return((uint?)Convert.ToInt32(res)); } if (tFile.Size != null && tFile.Size == 0) { CommandSize.Parameters["size"].Value = tFile.Size; object res = CommandSize.ExecuteScalar(); if (res == null || res == DBNull.Value) { return(null); } return((uint?)Convert.ToInt32(res)); } return(null); }
private static void LoadRomFromDat(RvGame rvGame, XmlNode romNode) { if (romNode.Attributes == null) { return; } RvRom rvRom = new RvRom(); rvRom.Name = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")); rvRom.Size = VarFix.ULong(romNode.Attributes.GetNamedItem("size")); rvRom.CRC = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8); rvRom.SHA1 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40); rvRom.MD5 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("md5"), 32); rvRom.Merge = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("merge")); rvRom.Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")); rvGame.AddRom(rvRom); }
private static void DatSetRemoveUnneededDirs(RvDat tDat) { if (tDat.Games == null) { return; } for (int g = 0; g < tDat.Games.Count; g++) { RvGame tGame = tDat.Games[g]; for (int r = 0; r < tGame.RomCount - 1; r++) { // first find any directories, zero length with filename ending in a '/' // there are RvFiles that are really directories (probably inside a zip file) RvRom f0 = tGame.Roms[r]; if (f0.Name.Length == 0) { continue; } if (f0.Name.Substring(f0.Name.Length - 1, 1) != "/") { continue; } // if the next file contains that found directory, then the directory file can be deleted RvRom f1 = tGame.Roms[r + 1]; if (f1.Name.Length <= f0.Name.Length) { continue; } if (f0.Name != f1.Name.Substring(0, f0.Name.Length)) { continue; } tGame.Roms.RemoveAt(r); r--; } } }
private static void LoadRomFromDat(RvGame rvGame, XmlNode romNode, HeaderFileType datFileType) { if (romNode.Attributes == null) { return; } RvRom rvRom = new RvRom { AltType = datFileType, Name = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")), Size = VarFix.ULong(romNode.Attributes.GetNamedItem("size")), CRC = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8), SHA1 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40), MD5 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("md5"), 32), Merge = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("merge")), Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")) }; rvGame.AddRom(rvRom); }
private static void DatSetRenameAndRemoveDups(RvDat tDat) { if (tDat.Games == null) { return; } for (int g = 0; g < tDat.Games.Count; g++) { RvGame tGame = tDat.Games[g]; for (int r = 0; r < tGame.RomCount - 1; r++) { RvRom f0 = tGame.Roms[r]; RvRom f1 = tGame.Roms[r + 1]; if (f0.Name != f1.Name) { continue; } if ((f0.Size != f1.Size) || (ArrByte.iCompare(f0.CRC, f1.CRC) != 0)) { tGame.Roms.RemoveAt(r + 1); // remove F1 f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1; int pos = tGame.AddRom(f1); // if this rename moved the File back up the list, start checking again from that file. if (pos < r) { r = pos; } } else { tGame.Roms.RemoveAt(r + 1); } r--; } } }
private static bool LoadRomFromDat(string rootName, HeaderFileType datFileType, out RvRom rvRom, out string game, out string description, out string romof, out string cloneof) { // Set the current out vars to blank for the time being rvRom = new RvRom(); game = ""; description = ""; romof = ""; cloneof = ""; if (!DatFileLoader.Next.Contains("¬")) { DatUpdate.SendAndShowDat("¬ not found in the rom definition on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } // Some old RC DATs have this behavior if (DatFileLoader.Next.Contains("¬N¬O")) { DatFileLoader.Next = DatFileLoader.Next.Replace("¬N¬O", "") + "¬¬"; } string[] split = DatFileLoader.Next.Split('¬'); game = split[3]; description = split[4]; romof = split[1]; cloneof = split[1]; rvRom = new RvRom { Name = split[5], CRC = VarFix.CleanMD5SHA1(split[6], 8), Size = Int64.TryParse(split[7], out var temp) ? VarFix.FixLong(split[7]) : null, Merge = split[9], }; return(true); }
public static uint?FindAFile(RvRom tFile) { if (_commandSHA1 == null) { _commandSHA1 = new SQLiteCommand(@" select FileId from FILES WHERE ( @sha1 = sha1 ) AND ( @md5 is NULL OR @md5 = md5 ) AND ( @crc is NULL OR @crc = crc ) AND ( @size is NULL OR @size = Size ) limit 1 ", DBSqlite.db.Connection); _commandSHA1.Parameters.Add(new SQLiteParameter("sha1")); _commandSHA1.Parameters.Add(new SQLiteParameter("md5")); _commandSHA1.Parameters.Add(new SQLiteParameter("crc")); _commandSHA1.Parameters.Add(new SQLiteParameter("size")); _commandSHA1Alt = new SQLiteCommand(@" select FileId from FILES WHERE ( @alttype = alttype ) AND ( @sha1 = altsha1 ) AND ( @md5 is NULL OR @md5 = altmd5 ) AND ( @crc is NULL OR @crc = altcrc ) AND ( @size is NULL OR @size = altSize ) limit 1 ", DBSqlite.db.Connection); _commandSHA1Alt.Parameters.Add(new SQLiteParameter("alttype")); _commandSHA1Alt.Parameters.Add(new SQLiteParameter("sha1")); _commandSHA1Alt.Parameters.Add(new SQLiteParameter("md5")); _commandSHA1Alt.Parameters.Add(new SQLiteParameter("crc")); _commandSHA1Alt.Parameters.Add(new SQLiteParameter("size")); _commandMD5 = new SQLiteCommand(@" select FileId from FILES WHERE ( @md5 = md5 ) AND ( @crc is NULL OR @crc = crc ) AND ( @size is NULL OR @size = Size ) limit 1 ", DBSqlite.db.Connection); _commandMD5.Parameters.Add(new SQLiteParameter("md5")); _commandMD5.Parameters.Add(new SQLiteParameter("crc")); _commandMD5.Parameters.Add(new SQLiteParameter("size")); _commandMD5Alt = new SQLiteCommand(@" select FileId from FILES WHERE ( @alttype = alttype ) AND ( @md5 = altmd5 ) AND ( @crc is NULL OR @crc = altcrc ) AND ( @size is NULL OR @size = altSize ) limit 1 ", DBSqlite.db.Connection); _commandMD5Alt.Parameters.Add(new SQLiteParameter("alttype")); _commandMD5Alt.Parameters.Add(new SQLiteParameter("md5")); _commandMD5Alt.Parameters.Add(new SQLiteParameter("crc")); _commandMD5Alt.Parameters.Add(new SQLiteParameter("size")); _commandCRC = new SQLiteCommand(@" select FileId from FILES WHERE ( @crc = crc ) AND ( @size is NULL OR @size = Size ) limit 1 ", DBSqlite.db.Connection); _commandCRC.Parameters.Add(new SQLiteParameter("crc")); _commandCRC.Parameters.Add(new SQLiteParameter("size")); _commandCRCAlt = new SQLiteCommand(@" select FileId from FILES WHERE ( @alttype = alttype ) AND ( @crc = altcrc ) AND ( @size is NULL OR @size = altSize ) limit 1 ", DBSqlite.db.Connection); _commandCRCAlt.Parameters.Add(new SQLiteParameter("alttype")); _commandCRCAlt.Parameters.Add(new SQLiteParameter("crc")); _commandCRCAlt.Parameters.Add(new SQLiteParameter("size")); _commandSize = new SQLiteCommand(@" select FileId from FILES WHERE ( @size = Size ) limit 1 ", DBSqlite.db.Connection); _commandSize.Parameters.Add(new SQLiteParameter("size")); } if (tFile.SHA1 != null) { _commandSHA1.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1); _commandSHA1.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); _commandSHA1.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandSHA1.Parameters["size"].Value = tFile.Size; object res = _commandSHA1.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType)) { return(null); } _commandSHA1Alt.Parameters["alttype"].Value = (int)tFile.AltType; _commandSHA1Alt.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1); _commandSHA1Alt.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); _commandSHA1Alt.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandSHA1Alt.Parameters["size"].Value = tFile.Size; res = _commandSHA1Alt.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } return(null); } if (tFile.MD5 != null) { _commandMD5.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); _commandMD5.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandMD5.Parameters["size"].Value = tFile.Size; object res = _commandMD5.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType)) { return(null); } _commandMD5Alt.Parameters["alttype"].Value = (int)tFile.AltType; _commandMD5Alt.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); _commandMD5Alt.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandMD5Alt.Parameters["size"].Value = tFile.Size; res = _commandMD5Alt.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } return(null); } if (tFile.CRC != null) { _commandCRC.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandCRC.Parameters["size"].Value = tFile.Size; object res = _commandCRC.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(tFile.AltType)) { return(null); } _commandCRCAlt.Parameters["alttype"].Value = (int)tFile.AltType; _commandCRCAlt.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); _commandCRCAlt.Parameters["size"].Value = tFile.Size; res = _commandCRCAlt.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } return(null); } if (tFile.Size != null && tFile.Size == 0) { _commandSize.Parameters["size"].Value = tFile.Size; object res = _commandSize.ExecuteScalar(); if (res != null && res != DBNull.Value) { return((uint?)Convert.ToInt32(res)); } } return(null); }
public static bool ReadDat(string strFilename, out RvDat rvDat) { HeaderFileType datFileType = HeaderFileType.Nothing; rvDat = new RvDat(); int errorCode = DatFileLoader.LoadDat(strFilename); if (errorCode != 0) { DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename); return(false); } string filename = Path.GetFileName(strFilename); DatFileLoader.Gn(); if (DatFileLoader.EndOfStream()) { return(false); } if (DatFileLoader.Next.ToLower() == "[credits]") { if (!LoadHeaderFromDat(filename, rvDat, out datFileType, DatFileLoader.Next.ToLower())) { return(false); } DatFileLoader.Gn(); } else if (DatFileLoader.Next.ToLower() == "[dat]") { if (!LoadHeaderFromDat(filename, rvDat, out datFileType, DatFileLoader.Next.ToLower())) { return(false); } DatFileLoader.Gn(); } else if (DatFileLoader.Next.ToLower() == "[emulator]") { if (!LoadHeaderFromDat(filename, rvDat, out datFileType, DatFileLoader.Next.ToLower())) { return(false); } DatFileLoader.Gn(); } // Everything else if a rom/game string lastgame = ""; bool foundgame = false; RvGame rvGame = new RvGame(); while (!DatFileLoader.EndOfStream()) { // Set loop variables foundgame = true; string game = "", description = "", romof = "", cloneof = ""; RvRom rvRom = new RvRom(); if (!LoadRomFromDat("", datFileType, out rvRom, out game, out description, out romof, out cloneof)) { return(false); } DatFileLoader.Gn(); // If we have a new game finally, add the last one if (lastgame != game && lastgame != "") { rvDat.AddGame(rvGame); foundgame = false; rvGame = new RvGame(); } // For everything else, add to the new rvGame rvGame.Name = (String.IsNullOrEmpty(rvGame.Name) ? game : rvGame.Name); rvGame.Description = (String.IsNullOrEmpty(rvGame.Description) ? description : rvGame.Description); rvGame.CloneOf = (String.IsNullOrEmpty(rvGame.CloneOf) ? cloneof : rvGame.CloneOf); rvGame.RomOf = (String.IsNullOrEmpty(rvGame.RomOf) ? romof : rvGame.RomOf); rvGame.AddRom(rvRom); lastgame = game; } // If we had a lingering game, add it if (foundgame) { rvDat.AddGame(rvGame); } DatFileLoader.Close(); return(true); }
private void UpdateRomGrid(uint GameId) { RomGrid.Rows.Clear(); IEnumerable <RvRom> roms = RvRom.ReadRoms(GameId); foreach (RvRom rom in roms) { RomGrid.Rows.Add(); int iRow = RomGrid.Rows.Count - 1; RomGrid.Rows[iRow].Selected = false; RomGrid.Rows[iRow].Tag = rom.RomId; RomGrid.Rows[iRow].Cells[1].Value = rom.Name; if (rom.Size != null) { RomGrid.Rows[iRow].Cells[2].Value = rom.Size; } else if (rom.FileSize != null) { RomGrid.Rows[iRow].Cells[2].Style.ForeColor = Color.FromArgb(0, 0, 255); RomGrid.Rows[iRow].Cells[2].Value = rom.Size; } if (rom.FileCompressedSize != null) { RomGrid.Rows[iRow].Cells[3].Style.ForeColor = Color.FromArgb(0, 0, 255); RomGrid.Rows[iRow].Cells[3].Value = rom.FileCompressedSize; } RomGrid.Rows[iRow].Cells[4].Value = rom.Merge; if (rom.CRC != null) { RomGrid.Rows[iRow].Cells[5].Value = VarFix.ToString(rom.CRC); } else if (rom.FileCRC != null) { RomGrid.Rows[iRow].Cells[5].Style.ForeColor = Color.FromArgb(0, 0, 255); RomGrid.Rows[iRow].Cells[5].Value = VarFix.ToString(rom.FileCRC); } if (rom.SHA1 != null) { RomGrid.Rows[iRow].Cells[6].Value = VarFix.ToString(rom.SHA1); } else if (rom.FileSHA1 != null) { RomGrid.Rows[iRow].Cells[6].Style.ForeColor = Color.FromArgb(0, 0, 255); RomGrid.Rows[iRow].Cells[6].Value = VarFix.ToString(rom.FileSHA1); } if (rom.MD5 != null) { RomGrid.Rows[iRow].Cells[7].Value = VarFix.ToString(rom.MD5); } else if (rom.FileMD5 != null) { RomGrid.Rows[iRow].Cells[7].Style.ForeColor = Color.FromArgb(0, 0, 255); RomGrid.Rows[iRow].Cells[7].Value = VarFix.ToString(rom.FileMD5); } RomGrid.Rows[iRow].Cells[8].Value = rom.Status; RomGrid.Rows[iRow].Cells[9].Value = rom.PutInZip; if (((rom.Status == "nodump") && (rom.CRC == null) && (rom.SHA1 == null) && (rom.MD5 == null) && (rom.FileId == null)) || !rom.PutInZip) { RomGrid.Rows[iRow].DefaultCellStyle.BackColor = CGray; } else { RomGrid.Rows[iRow].DefaultCellStyle.BackColor = rom.FileId != null ? CGreen : CRed; } } }
public static uint? Execute(RvRom tFile) { if (tFile.SHA1 != null) { CommandSHA1.Parameters["sha1"].Value = VarFix.ToDBString(tFile.SHA1); CommandSHA1.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); CommandSHA1.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandSHA1.Parameters["size"].Value = tFile.Size; object res = CommandSHA1.ExecuteScalar(); if (res == null || res == DBNull.Value) return null; return (uint?)Convert.ToInt32(res); } if (tFile.MD5 != null) { CommandMD5.Parameters["md5"].Value = VarFix.ToDBString(tFile.MD5); CommandMD5.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandMD5.Parameters["size"].Value = tFile.Size; object res = CommandMD5.ExecuteScalar(); if (res == null || res == DBNull.Value) return null; return (uint?)Convert.ToInt32(res); } if (tFile.CRC != null) { CommandCRC.Parameters["crc"].Value = VarFix.ToDBString(tFile.CRC); CommandCRC.Parameters["size"].Value = tFile.Size; object res = CommandCRC.ExecuteScalar(); if (res == null || res == DBNull.Value) return null; return (uint?)Convert.ToInt32(res); } if (tFile.Size != null && tFile.Size == 0) { CommandSize.Parameters["size"].Value = tFile.Size; object res = CommandSize.ExecuteScalar(); if (res == null || res == DBNull.Value) return null; return (uint?)Convert.ToInt32(res); } return null; }
private static void CopyDir(DatDir datD, HeaderFileType headerFileType, RvDat retDat = null, RvGame retGame = null) { DatBase[] datB = datD.ToArray(); if (datB == null) { return; } foreach (DatBase b in datB) { switch (b) { case DatDir nDir: if (nDir.DGame == null) { break; } DatGame dGame = nDir.DGame; RvGame cGame = new RvGame(); cGame.Name = b.Name; cGame.Description = dGame.Description; cGame.Manufacturer = dGame.Manufacturer; cGame.CloneOf = dGame.CloneOf; cGame.RomOf = dGame.RomOf; cGame.SampleOf = dGame.SampleOf; cGame.SourceFile = dGame.SourceFile; cGame.IsBios = dGame.IsBios; cGame.Board = dGame.Board; cGame.Year = dGame.Year; if (dGame.IsEmuArc) { cGame.IsTrurip = true; cGame.Publisher = dGame.Publisher; cGame.Developer = dGame.Developer; //cGame.Edition //cGame.Version //cGame.Type //cGame.Media //cGame.Language cGame.Players = dGame.Players; cGame.Ratings = dGame.Ratings; cGame.Genre = dGame.Genre; //cGame.Peripheral //cGame.BarCode //cGame.MediaCatalogNumber } retDat?.AddGame(cGame); CopyDir(nDir, headerFileType, null, cGame); break; case DatFile nFile: if (nFile.isDisk) { break; } RvRom nf = new RvRom() { Name = nFile.Name, Size = nFile.Size, CRC = nFile.CRC, SHA1 = nFile.SHA1, MD5 = nFile.MD5, Merge = nFile.Merge, Status = nFile.Status, AltType = headerFileType }; retGame?.AddRom(nf); break; } } }
private static void ExtractGame(RvGame tGame, string outDir) { if (buffer == null) { buffer = new byte[BufferSize]; } ZipReturn zr; bool romGot = false; for (int rIndex = 0; rIndex < tGame.Roms.Count; rIndex++) { if (tGame.Roms[rIndex].FileId != null) { romGot = true; break; } } if (!romGot) { return; } // export the rom; ZipFile zipOut = new ZipFile(); string filename = Path.Combine(outDir, tGame.Name + ".zip"); filename = filename.Replace(@"/", @"\"); if (!Directory.Exists(filename)) { string dir = Path.GetDirectoryName(filename); Directory.CreateDirectory(dir); } zr = zipOut.ZipFileCreate(filename); if (zr != ZipReturn.ZipGood) { MessageBox.Show("Error creating " + Path.Combine(outDir, tGame.Name + ".zip") + " " + zr); return; } for (int rIndex = 0; rIndex < tGame.Roms.Count; rIndex++) { RvRom tRom = tGame.Roms[rIndex]; if (tRom.FileId != null) { GZip sourceGZip = new GZip(); string sha1 = Getfilename(GetFile.Execute((uint)tRom.FileId)); zr = sourceGZip.ReadGZip(sha1, false); if (zr != ZipReturn.ZipGood) { sourceGZip.Close(); continue; } Stream outStream; zipOut.ZipFileOpenWriteStream(true, true, tRom.Name, sourceGZip.uncompressedSize, 8, out outStream); Stream gZipStream; zr = sourceGZip.GetRawStream(out gZipStream); if (zr == ZipReturn.ZipGood) { // write the gzip stream to the zipstream ulong sizetogo = sourceGZip.compressedSize; while (sizetogo > 0) { int sizenow = sizetogo > BufferSize ? (int)BufferSize : (int)sizetogo; gZipStream.Read(buffer, 0, sizenow); outStream.Write(buffer, 0, sizenow); sizetogo = sizetogo - (ulong)sizenow; } } sourceGZip.Close(); zipOut.ZipFileCloseWriteStream(sourceGZip.crc); } } zipOut.ZipFileClose(); }
private static bool LoadRomFromDat(RvGame rvGame, HeaderFileType datFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after rom on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.Next.ToLower() != "name") { DatUpdate.SendAndShowDat("Name not found as first object in ( ) on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } RvRom rvRom = new RvRom { Name = VarFix.CleanFullFileName(DatFileLoader.Gn()), AltType = datFileType }; DatFileLoader.Gn(); while (rvRom.CRC == null || rvRom.Size == null || DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "size": rvRom.Size = VarFix.ULong(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "crc": rvRom.CRC = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 8); DatFileLoader.Gn(); break; case "md5": rvRom.MD5 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 32); DatFileLoader.Gn(); break; case "sha1": rvRom.SHA1 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 40); DatFileLoader.Gn(); break; case "sha256": // No-op until larger hashes are supported DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "sha384": // No-op until larger hashes are supported DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "sha512": // No-op until larger hashes are supported DatFileLoader.Gn(); DatFileLoader.Gn(); break; case "date": rvRom.Date = DatFileLoader.Gn(); rvRom.Date += " " + DatFileLoader.Gn(); DatFileLoader.Gn(); break; default: rvRom.Name += " " + DatFileLoader.Next; DatFileLoader.Gn(); break; } } rvGame.AddRom(rvRom); return(true); }