private static void ReportMissing(RvDir dir, RvDat dat, ReportType rt) { for (int i = 0; i < dir.ChildCount; i++) { RvBase b = dir.Child(i); if (b.Dat != null && b.Dat != dat) { continue; } RvFile f = b as RvFile; if (f != null) { if ( (rt == ReportType.PartialMissing && Partial.Contains(f.RepStatus)) || (rt == ReportType.Fixing && Fixing.Contains(f.RepStatus)) ) { string filename = f.FileNameInsideGame(); string crc = ArrByte.ToString(f.CRC); _ts.WriteLine("| " + filename + new string(' ', _fileNameLength + 1 - filename.Length) + "| " + f.Size + new string(' ', _fileSizeLength + 1 - f.Size.ToString().Length) + "| " + crc + new string(' ', 9 - crc.Length) + "| " + f.RepStatus + new string(' ', _repStatusLength + 1 - f.RepStatus.ToString().Length) + "|"); } } RvDir d = b as RvDir; if (d != null) { ReportMissing(d, dat, rt); } } }
private static void DatSetRenameAndRemoveDups(RvDir tDat) { for (int g = 0; g < tDat.ChildCount; g++) { RvDir tDir = (RvDir)tDat.Child(g); if (tDir.Game == null) { DatSetRenameAndRemoveDups(tDir); } else { for (int r = 0; r < tDir.ChildCount - 1; r++) { RvFile f0 = (RvFile)tDir.Child(r); RvFile f1 = (RvFile)tDir.Child(r + 1); if (f0.Name != f1.Name) { continue; } if (f0.Size != f1.Size || !ArrByte.bCompare(f0.CRC, f1.CRC)) { tDir.ChildRemove(r + 1); // remove F1 f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1; int pos = tDir.ChildAdd(f1); if (pos < r) { r = pos; } // if this rename moved the File back up the list, start checking again from that file. } else { tDir.ChildRemove(r + 1); } r--; } } } }
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--; } } }
// CHDs as disk private static void ProcessDir(RvDir dir, int depth = 1) { string indent = new string('\t', depth); // recursive indent List <string> disks = new List <string> { string.Empty }; for (int i = 0; i < dir.ChildCount; i++) { RvDir item = dir.Child(i) as RvDir; if ((item != null) && (item.FileType == FileType.Dir)) { if ((disks.Count > 2) && (item.Name != disks[0])) // flush the last one if there were only CHDs in it { justCHDs(indent, disks); disks.Clear(); } // tabulate next disk list, if any disks = new List <string> { item.Name, item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description) }; for (int j = 0; j < item.ChildCount; j++) { RvFile chd = item.Child(j) as RvFile; if ((chd != null) && (chd.FileType == FileType.File) && chd.Name.EndsWith(".chd")) { if (!string.IsNullOrEmpty(ArrByte.ToString(chd.SHA1CHD))) { disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" sha1=\"" + ArrByte.ToString(chd.SHA1CHD) + "\"/>"); } else { disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" status=\"nodump\"/>"); } } } } if ((item != null) && (item.FileType == FileType.Zip)) { WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">"); string desc = item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description); WriteLine(indent + "\t<description>" + clean(desc) + "</description>"); for (int j = 0; j < item.ChildCount; j++) { RvFile file = item.Child(j) as RvFile; if (file != null) { WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>"); } } if (disks.Count > 2) // take care of previous list of CHDs now { for (int j = 2; j < disks.Count; j++) { WriteLine(disks[j]); } disks.Clear(); } WriteLine(indent + "</game>"); } if ((item != null) && (item.FileType == FileType.Dir)) { if (numDisks(item) == 0) // only recurse when children are not CHDs { WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">"); ProcessDir(item, depth + 1); WriteLine(indent + "</dir>"); } } } // check for one last CHDs-only game if (disks.Count > 2) { justCHDs(indent, disks); } }
// CHDs as rom private static void PlainProcessDir(RvDir dir, int depth = 1) { string indent = new string('\t', depth); for (int i = 0; i < dir.ChildCount; i++) { RvDir item = dir.Child(i) as RvDir; if ((item != null) && ((item.FileType == FileType.Zip) || (item.FileType == FileType.Dir))) { WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">"); WriteLine(indent + "\t<description>" + clean(item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description)) + "</description>"); for (int j = 0; j < item.ChildCount; j++) { RvFile file = item.Child(j) as RvFile; if (file != null) { WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>"); } RvDir aDir = item.Child(j) as RvDir; if (aDir != null) { string dName = aDir.Name; for (int k = 0; k < aDir.ChildCount; k++) { RvFile subFile = aDir.Child(k) as RvFile; WriteLine(indent + "\t<rom name=\"" + dName + "\\" + clean(subFile.Name) + "\" size=\"" + subFile.Size + "\" crc=\"" + ArrByte.ToString(subFile.CRC) + "\" md5=\"" + ArrByte.ToString(subFile.MD5) + "\" sha1=\"" + ArrByte.ToString(subFile.SHA1) + "\"/>"); } } } WriteLine(indent + "</game>"); } // only recurse when grandchildren are not CHDs if ((item != null) && (item.FileType == FileType.Dir) && !hasChdGrandChildren(item)) { WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">"); PlainProcessDir(item, depth + 1); WriteLine(indent + "</dir>"); } } }
private static void ReportFile(TextWriter sw, RvFile f) { sw.WriteLine(f.ReportIndex.ToString("D8") + " " + ArrByte.ToString(f.CRC) + " " + f.GotStatus.ToString().PadRight(10) + " " + f.RepStatus.ToString().PadRight(15) + " " + f.TreeFullName); }
private static void MakeFixFilesRecurse(RvBase b, bool selected) { if (selected) { if (b.Dat != null) { RvDir tDir = b as RvDir; if (tDir != null && tDir.Game != null && tDir.DirStatus.HasMissing()) { if (_tDat != b.Dat) { if (_tDat != null) { _ts.WriteLine("</datafile>"); _ts.WriteLine(); } if (_ts != null) { _ts.Close(); } _tDat = b.Dat; int test = 0; string datFilename = Path.Combine(_outdir, "fixDat_" + Path.GetFileNameWithoutExtension(_tDat.GetData(RvDat.DatData.DatFullName)) + ".dat"); while (File.Exists(datFilename)) { test++; datFilename = Path.Combine(_outdir, "fixDat_" + Path.GetFileNameWithoutExtension(_tDat.GetData(RvDat.DatData.DatFullName)) + "(" + test + ").dat"); } _ts = new StreamWriter(datFilename); _ts.WriteLine("<?xml version=\"1.0\"?>"); _ts.WriteLine( "<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">"); _ts.WriteLine(""); _ts.WriteLine("<datafile>"); _ts.WriteLine("\t<header>"); _ts.WriteLine("\t\t<name>fix_" + Etxt(_tDat.GetData(RvDat.DatData.DatName)) + "</name>"); if (_tDat.GetData(RvDat.DatData.SuperDat) == "superdat") { _ts.WriteLine("\t\t<type>SuperDAT</type>"); } _ts.WriteLine("\t\t<description>fix_" + Etxt(_tDat.GetData(RvDat.DatData.Description)) + "</description>"); _ts.WriteLine("\t\t<category>FIXDATFILE</category>"); _ts.WriteLine("\t\t<version>" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "</version>"); _ts.WriteLine("\t\t<date>" + DateTime.Now.ToString("MM/dd/yyyy") + "</date>"); _ts.WriteLine("\t\t<author>RomVault</author>"); _ts.WriteLine("\t</header>"); } _ts.WriteLine("\t<game name=\"" + Etxt(tDir.SuperDatFileName()) + "\">"); if (!string.IsNullOrEmpty(tDir.Game.GetData(RvGame.GameData.Description))) { _ts.WriteLine("\t\t<description>" + Etxt(tDir.Game.GetData(RvGame.GameData.Description)) + "</description>"); } } RvFile tRom = b as RvFile; if (tRom != null) { if (tRom.DatStatus == DatStatus.InDatCollect && tRom.GotStatus != GotStatus.Got) { string strRom; if (tRom.FileStatusIs(FileStatus.SHA1CHDFromDAT | FileStatus.MD5CHDFromDAT)) { strRom = "\t\t<disk name=\"" + Etxt(tRom.Name) + "\""; } else { strRom = "\t\t<rom name=\"" + Etxt(tRom.Name) + "\""; } if (tRom.FileStatusIs(FileStatus.SizeFromDAT) && tRom.Size != null) { strRom += " size=\"" + tRom.Size + "\""; } string strCRC = ArrByte.ToString(tRom.CRC); if (tRom.FileStatusIs(FileStatus.CRCFromDAT) && !string.IsNullOrEmpty(strCRC)) { strRom += " crc=\"" + strCRC + "\""; } string strSHA1 = ArrByte.ToString(tRom.SHA1); if (tRom.FileStatusIs(FileStatus.SHA1FromDAT) && !string.IsNullOrEmpty(strSHA1)) { strRom += " sha1=\"" + strSHA1 + "\""; } string strMD5 = ArrByte.ToString(tRom.MD5); if (tRom.FileStatusIs(FileStatus.MD5FromDAT) && !string.IsNullOrEmpty(strMD5)) { strRom += " md5=\"" + strMD5 + "\""; } string strSHA1CHD = ArrByte.ToString(tRom.SHA1CHD); if (tRom.FileStatusIs(FileStatus.SHA1CHDFromDAT) && !string.IsNullOrEmpty(strSHA1CHD)) { strRom += " sha1=\"" + strSHA1CHD + "\""; } string strMD5CHD = ArrByte.ToString(tRom.MD5CHD); if (tRom.FileStatusIs(FileStatus.MD5CHDFromDAT) && !string.IsNullOrEmpty(strMD5CHD)) { strRom += " md5=\"" + strMD5CHD + "\""; } strRom += "/>"; _ts.WriteLine(strRom); } } } } RvDir d = b as RvDir; if (d != null) { for (int i = 0; i < d.ChildCount; i++) { bool nextSelected = selected; if (d.Tree != null) { nextSelected = d.Tree.Checked == RvTreeRow.TreeSelect.Selected; } MakeFixFilesRecurse(d.Child(i), nextSelected); } } if (selected) { if (b.Dat != null) { RvDir tDir = b as RvDir; if (tDir != null && tDir.Game != null && tDir.DirStatus.HasMissing()) { _ts.WriteLine("\t</game>"); } } } }