private static bool LoadHeaderFromDat(ref RvDir tDir, ref FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadHeaderFromDat_not_found_after_clrmamepro, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); string forceZipping = ""; RvDat tDat = new RvDat(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "name": tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.GnRest())); DatFileLoader.Gn(); break; case "description": tDat.AddData(RvDat.DatData.Description, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "category": tDat.AddData(RvDat.DatData.Category, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "version": tDat.AddData(RvDat.DatData.Version, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "date": tDat.AddData(RvDat.DatData.Date, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "author": tDat.AddData(RvDat.DatData.Author, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "email": tDat.AddData(RvDat.DatData.Email, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "homepage": tDat.AddData(RvDat.DatData.HomePage, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "url": tDat.AddData(RvDat.DatData.URL, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "comment": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "header": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcezipping": forceZipping = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcepacking": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; // incorrect usage case "forcemerging": tDat.AddData(RvDat.DatData.MergeType, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "forcenodump": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "dir": tDat.AddData(RvDat.DatData.DirSetup, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadHeaderFromDat_not_known_in_clrmamepro, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } thisFileType = forceZipping.ToLower() != "no" ? FileType.ZipFile : FileType.File; tDir.Dat = tDat; return(true); }
private static bool LoadArchiveFromDat() { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after Archive", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "name": DatFileLoader.Gn(); DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + " not know in Archive", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
private static bool LoadEmulator() { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after emulator", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "name": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "version": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; } } return(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); }
private static bool LoadDiskFromDat(ref RvDir tGame) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadRomFromDat_not_found_after_rom, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.Next.ToLower() != "name") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename); return(false); } string filename = VarFix.CleanFullFileName(DatFileLoader.Gn()); RvFile tRom = new RvFile(FileType.File) { Name = filename }; DatFileLoader.Gn(); tRom.Dat = tGame.Dat; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "sha1": tRom.SHA1CHD = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 40); DatFileLoader.Gn(); break; case "md5": tRom.MD5CHD = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 32); DatFileLoader.Gn(); break; case "merge": tRom.Merge = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "flags": tRom.Status = VarFix.ToLower(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "nodump": tRom.Status = "nodump"; DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadRomFromDat_not_known_in_rom, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } if (tRom.SHA1CHD != null) { tRom.FileStatusSet(FileStatus.SHA1CHDFromDAT); } if (tRom.MD5CHD != null) { tRom.FileStatusSet(FileStatus.MD5CHDFromDAT); } tGame.ChildAdd(tRom); return(true); }
private static bool LoadDirFromDat(RvDat rvDat, string rootName, HeaderFileType datFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after game", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.Next.ToLower() != "name") { DatUpdate.SendAndShowDat("Name not found as first object in ( )", DatFileLoader.Filename); return(false); } string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest()); fullname = Path.Combine(rootName, fullname); DatFileLoader.Gn(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "dir": DatFileLoader.Gn(); if (!LoadDirFromDat(rvDat, fullname, datFileType)) { return(false); } DatFileLoader.Gn(); break; case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(rvDat, fullname, datFileType)) { return(false); } DatFileLoader.Gn(); break; case "resource": DatFileLoader.Gn(); if (!LoadGameFromDat(rvDat, fullname, datFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error Keyword " + DatFileLoader.Next + " not know in dir", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
private static bool LoadHeaderFromDat(string Filename, long fileTimeStamp, RvDat rvDat) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after clrmamepro", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); rvDat.Filename = Filename; rvDat.DatTimeStamp = fileTimeStamp; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "name": rvDat.Name = VarFix.CleanFileName(DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "description": rvDat.Description = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "category": rvDat.Category = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "version": rvDat.Version = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "date": rvDat.Date = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "author": rvDat.Author = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "email": rvDat.Email = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "homepage": rvDat.Homepage = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "url": rvDat.URL = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "comment": rvDat.Comment = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "header": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcezipping": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcepacking": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; // incorrect usage case "forcemerging": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcenodump": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "dir": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in clrmamepro", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
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() == "doscenter") { DatFileLoader.Gn(); if (!LoadHeaderFromDat(filename, rvDat, out datFileType)) { return(false); } DatFileLoader.Gn(); } while (!DatFileLoader.EndOfStream()) { switch (DatFileLoader.Next.ToLower()) { case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(rvDat, "", datFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error on line " + DatFileLoader.LineNumber + ": key word '" + DatFileLoader.Next + "' not known", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } DatFileLoader.Close(); return(true); }
private static bool LoadRomFromDat(ref RvDir tGame, FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadRomFromDat_not_found_after_rom, DatFileLoader.Filename); return(false); } string line = DatFileLoader.GnRest(); string linelc = line.ToLower(); int posName = linelc.IndexOf("name ", StringComparison.Ordinal); int posSize = linelc.IndexOf(" size ", posName + 5, StringComparison.Ordinal); int posDate = linelc.IndexOf(" date ", posSize + 6, StringComparison.Ordinal); int posCrc = linelc.IndexOf(" crc ", posDate + 6, StringComparison.Ordinal); int posEnd = linelc.IndexOf(" )", posCrc + 5, StringComparison.Ordinal); if (posName < 0 || posSize < 0 || posDate < 0 || posCrc < 0 || posEnd < 0) { DatFileLoader.Gn(); return(false); } string name = line.Substring(posName + 5, posSize - (posName + 5)); string size = line.Substring(posSize + 6, posDate - (posSize + 6)); //string date = line.Substring(posDate + 6, posCrc - (posDate + 6)); string crc = line.Substring(posCrc + 5, posEnd - (posCrc + 5)); RvFile tRom = new RvFile(thisFileType) { Dat = tGame.Dat, Name = VarFix.CleanFullFileName(name.Trim()), Size = VarFix.ULong(size.Trim()), CRC = VarFix.CleanMD5SHA1(crc.Trim(), 8) }; if (tRom.Size != null) { tRom.FileStatusSet(FileStatus.SizeFromDAT); } if (tRom.CRC != null) { tRom.FileStatusSet(FileStatus.CRCFromDAT); } tGame.ChildAdd(tRom); return(true); }
private static bool LoadHeaderFromDat(ref RvDir tDir, ref FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadHeaderFromDat_not_found_after_clrmamepro, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); RvDat tDat = new RvDat(); while (DatFileLoader.Next != ")") { string nextstr = DatFileLoader.Next.ToLower(); if (nextstr.Length > 5 && nextstr.Substring(0, 5) == "name:") { tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.Next.Substring(5) + " " + DatFileLoader.GnRest()).Trim()); DatFileLoader.Gn(); } else { switch (nextstr) { case "name:": tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.GnRest())); DatFileLoader.Gn(); break; case "description:": tDat.AddData(RvDat.DatData.Description, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "version:": tDat.AddData(RvDat.DatData.Version, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "date:": tDat.AddData(RvDat.DatData.Date, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "author:": tDat.AddData(RvDat.DatData.Author, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "homepage:": tDat.AddData(RvDat.DatData.HomePage, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "comment:": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadHeaderFromDat_not_known_in_clrmamepro, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } } thisFileType = FileType.ZipFile; tDir.Dat = tDat; return(true); }
private static bool LoadDiskFromDat(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); } string filename = VarFix.CleanFullFileName(DatFileLoader.Gn()); byte[] sha1; byte[] md5; string Merge; string Status; DatFileLoader.Gn(); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "sha1": sha1 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 40); DatFileLoader.Gn(); break; case "md5": md5 = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 32); DatFileLoader.Gn(); break; case "merge": Merge = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "flags": Status = VarFix.ToLower(DatFileLoader.Gn()); DatFileLoader.Gn(); break; case "nodump": Status = "nodump"; DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in rom", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
public static bool ReadDat(ref RvDir tDat, string strFilename) { RvDir tNow = tDat; FileType thisFileType = FileType.Unknown; int errorCode = DatFileLoader.LoadDat(strFilename); if (errorCode != 0) { DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename); return(false); } DatFileLoader.Gn(); while (!DatFileLoader.EndOfStream()) { switch (DatFileLoader.Next.ToLower()) { case "doscenter": _cleanFileNames = true; DatFileLoader.Gn(); if (!LoadHeaderFromDat(ref tNow, ref thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(ref tNow, thisFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_ReadDat_not_known, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } DatFileLoader.Close(); return(true); }
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); }
private static bool LoadDirFromDat(ref RvDir tDat, ref FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.Next.ToLower() != "name") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename); return(false); } RvDir parent = tDat; string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest()); while (fullname.Contains("/")) { int firstSlash = fullname.IndexOf("/", StringComparison.Ordinal); string dir = fullname.Substring(0, firstSlash); dir = VarFix.CleanFileName(dir); fullname = fullname.Substring(firstSlash + 1); if (parent.ChildNameSearch(new RvDir(FileType.Dir) { Name = dir }, out int index) == 0) { parent = (RvDir)parent.Child(index); } else { RvDir tpDir = new RvDir(FileType.Dir) { Name = dir, DatStatus = DatStatus.InDatCollect, Dat = tDat.Dat, Tree = new RvTreeRow() }; parent.ChildAdd(tpDir, index); parent = tpDir; } } RvDir tDir = new RvDir(FileType.Dir) { Name = fullname }; DatFileLoader.Gn(); tDir.DatStatus = DatStatus.InDatCollect; tDir.Dat = tDat.Dat; if (parent.ChildNameSearch(tDir, out int index1) == 0) { tDir = (RvDir)parent.Child(index1); } else { parent.ChildAdd(tDir, index1); } while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "dir": DatFileLoader.Gn(); if (!LoadDirFromDat(ref tDir, ref thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(ref tDir, false, thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "resource": DatFileLoader.Gn(); if (!LoadGameFromDat(ref tDir, true, thisFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadDirFromDat_Error_Keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadDirFromDat_not_know_in_dir, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
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); }
private static bool LoadGameFromDat(ref RvDir tDat, FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); string snext = DatFileLoader.Next.ToLower(); if (snext != "name") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename); return(false); } RvDir parent = tDat; string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest()); if (_cleanFileNames) { fullname = fullname.Replace("/", "-"); } while (fullname.Contains("/")) { int firstSlash = fullname.IndexOf("/", StringComparison.Ordinal); string dir = fullname.Substring(0, firstSlash); fullname = fullname.Substring(firstSlash + 1); int index; if (parent.ChildNameSearch(new RvDir(FileType.Dir) { Name = dir }, out index) == 0) { parent = (RvDir)parent.Child(index); } else { RvDir tpDir = new RvDir(FileType.Dir) { Name = dir, DatStatus = DatStatus.InDatCollect, Dat = tDat.Dat, Tree = new RvTreeRow() }; parent.ChildAdd(tpDir, index); parent = tpDir; } } if (fullname.Length > 4 && fullname.ToLower().Substring(fullname.Length - 4, 4) == ".zip") { fullname = fullname.Substring(0, fullname.Length - 4); } RvDir tDir = new RvDir(thisFileType == FileType.File ? FileType.Dir : FileType.Zip) { Name = fullname }; DatFileLoader.Gn(); tDir.Game = new RvGame(); tDir.DatStatus = DatStatus.InDatCollect; tDir.Dat = tDat.Dat; int index1; string testName = tDir.Name; int nameCount = 0; while (parent.ChildNameSearch(tDir, out index1) == 0) { tDir.Name = testName + "_" + nameCount; nameCount++; } parent.ChildAdd(tDir, index1); while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "file": DatFileLoader.Gn(); if (!LoadRomFromDat(ref tDir, thisFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadGameFromDat_not_known_in_game, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
private static bool LoadHeaderFromDat(string filename, RvDat rvDat, out HeaderFileType datFileType) { datFileType = HeaderFileType.Nothing; if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after clrmamepro on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); rvDat.Filename = filename; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "name:": rvDat.Name = VarFix.CleanFileName(DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "description:": rvDat.Description = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "category:": rvDat.Category = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "version:": rvDat.Version = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "date:": rvDat.Date = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "author:": rvDat.Author = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "email:": rvDat.Email = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "homepage:": rvDat.Homepage = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "url:": rvDat.URL = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "comment:": rvDat.Comment = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "header:": datFileType = FileHeaderReader.FileHeaderReader.GetFileTypeFromHeader(DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "forcezipping:": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcepacking:": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; // incorrect usage case "forcemerging:": rvDat.MergeType = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "forcenodump:": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; default: if (DatFileLoader.Next.ToLower().StartsWith("name:")) { rvDat.Name = DatFileLoader.Next.Remove(0, 5); DatFileLoader.GnRest(); DatFileLoader.Gn(); } else { DatUpdate.SendAndShowDat("Error on line " + DatFileLoader.LineNumber + ": key word '" + DatFileLoader.Next + "' not known in clrmamepro", DatFileLoader.Filename); DatFileLoader.Gn(); } break; } } return(true); }
private static bool LoadHeaderFromDat(string filename, RvDat rvDat, out HeaderFileType datFileType, string blockstart) { datFileType = HeaderFileType.Nothing; rvDat.Filename = filename; while (DatFileLoader.Next.ToLower() != "[games]") { // Split the line by '=' string key = DatFileLoader.Next.Split('=')[0]; string value = DatFileLoader.Next.Remove(0, key.Length + (DatFileLoader.Next.Contains("=") ? 1 : 0)); string block = blockstart; switch (key.ToLower()) { // CREDITS block case "[credits]": block = key; DatFileLoader.Gn(); break; case "author": rvDat.Author = value; DatFileLoader.Gn(); break; case "version": if (block == "[credits]") { rvDat.Date = value; } else if (block == "[dat]") { rvDat.Version = value; } DatFileLoader.Gn(); break; case "comment": rvDat.Name = value; rvDat.Description = value; rvDat.Comment = value; DatFileLoader.Gn(); break; case "url": rvDat.URL = value; DatFileLoader.Gn(); break; // DAT block case "[dat]": block = key; DatFileLoader.Gn(); break; case "plugin": DatFileLoader.Gn(); break; case "split": switch (value) { case "0": rvDat.MergeType = (String.IsNullOrEmpty(rvDat.MergeType) ? "" : rvDat.MergeType); break; case "1": rvDat.MergeType = (String.IsNullOrEmpty(rvDat.MergeType) ? "split" : rvDat.MergeType); break; } DatFileLoader.Gn(); break; case "merge": switch (value) { case "0": rvDat.MergeType = (String.IsNullOrEmpty(rvDat.MergeType) ? "" : rvDat.MergeType); break; case "1": rvDat.MergeType = (String.IsNullOrEmpty(rvDat.MergeType) ? "merge" : rvDat.MergeType); break; } DatFileLoader.Gn(); break; // EMULATOR block case "[emulator]": block = key; DatFileLoader.Gn(); break; case "refname": DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error on line " + DatFileLoader.LineNumber + ": key word '" + key + "' not known in romcenter", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } return(true); }
private static bool LoadGameFromDat(RvDat rvDat, string rootdir) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after game", DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); string snext = DatFileLoader.Next.ToLower(); string pathextra = ""; if (snext == "rebuildto") { pathextra = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); snext = DatFileLoader.Next.ToLower(); } if (snext != "name") { DatUpdate.SendAndShowDat("Name not found as first object in ( )", DatFileLoader.Filename); return(false); } string name = VarFix.CleanFullFileName(DatFileLoader.GnRest()); if (!String.IsNullOrEmpty(pathextra)) { name = pathextra + "/" + name; } DatFileLoader.Gn(); RvGame rvGame = new RvGame(); rvGame.Name = name; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "romof": rvGame.RomOf = VarFix.CleanFileName(DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "description": rvGame.Description = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sourcefile": rvGame.SourceFile = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "cloneof": rvGame.CloneOf = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sampleof": rvGame.SampleOf = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "board": rvGame.Board = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "year": rvGame.Year = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "manufacturer": rvGame.Manufacturer = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "serial": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "rebuildto": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sample": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "biosset": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "chip": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "video": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sound": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "input": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "dipswitch": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "driver": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "rom": DatFileLoader.Gn(); if (!LoadRomFromDat(rvGame)) { return(false); } DatFileLoader.Gn(); break; case "disk": DatFileLoader.Gn(); if (!LoadDiskFromDat(rvGame)) { return(false); } DatFileLoader.Gn(); break; case "archive": DatFileLoader.Gn(); if (!LoadArchiveFromDat()) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in game", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } rvDat.AddGame(rvGame); return(true); }
public static bool ReadDat(string strFilename, long fileTimeStamp, out RvDat rvDat) { rvDat = new RvDat(); int errorCode = DatFileLoader.LoadDat(strFilename); if (errorCode != 0) { DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename); return(false); } string Filename = IO.Path.GetFileName(strFilename); DatFileLoader.Gn(); if (DatFileLoader.EndOfStream()) { return(false); } if (DatFileLoader.Next.ToLower() == "clrmamepro") { DatFileLoader.Gn(); if (!LoadHeaderFromDat(Filename, fileTimeStamp, rvDat)) { return(false); } DatFileLoader.Gn(); } if (DatFileLoader.Next.ToLower() == "romvault") { DatFileLoader.Gn(); if (!LoadHeaderFromDat(Filename, fileTimeStamp, rvDat)) { return(false); } DatFileLoader.Gn(); } while (!DatFileLoader.EndOfStream()) { switch (DatFileLoader.Next.ToLower()) { case "dir": DatFileLoader.Gn(); if (!LoadDirFromDat(rvDat, "")) { return(false); } DatFileLoader.Gn(); break; case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(rvDat, "")) { return(false); } DatFileLoader.Gn(); break; case "resource": DatFileLoader.Gn(); if (!LoadGameFromDat(rvDat, "")) { return(false); } DatFileLoader.Gn(); break; case "emulator": DatFileLoader.Gn(); if (!LoadEmulator()) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } DatFileLoader.Close(); return(true); }
private static bool LoadGameFromDat(ref RvDir tDat, bool bolresource, FileType thisFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); string snext = DatFileLoader.Next.ToLower(); string pathextra = ""; if (snext == "rebuildto") { pathextra = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); snext = DatFileLoader.Next.ToLower(); } if (snext != "name") { DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename); return(false); } RvDir parent = tDat; string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest()); if (_cleanFileNames) { fullname = fullname.Replace("/", "-"); } if (!string.IsNullOrEmpty(pathextra)) { fullname = pathextra + "/" + fullname; } while (fullname.Contains("/")) { int firstSlash = fullname.IndexOf("/", StringComparison.Ordinal); string dir = fullname.Substring(0, firstSlash); fullname = fullname.Substring(firstSlash + 1); if (parent.ChildNameSearch(new RvDir(FileType.Dir) { Name = dir }, out int index) == 0) { parent = (RvDir)parent.Child(index); } else { RvDir tpDir = new RvDir(FileType.Dir) { Name = dir, DatStatus = DatStatus.InDatCollect, Dat = tDat.Dat, Tree = new RvTreeRow() }; parent.ChildAdd(tpDir, index); parent = tpDir; } } RvDir tDir = new RvDir(thisFileType == FileType.File ? FileType.Dir : FileType.Zip) { Name = fullname, DatStatus = DatStatus.InDatCollect, Dat = tDat.Dat }; string testName = tDir.Name; int nameCount = 0; int index1; while (parent.ChildNameSearch(tDir, out index1) == 0) { tDir.Name = testName + "_" + nameCount; nameCount++; } DatFileLoader.Gn(); tDir.Game = new RvGame(); tDir.Game.AddData(RvGame.GameData.IsBios, bolresource ? "Yes" : "No"); RvDir tDirCHD = new RvDir(FileType.Dir) { Name = tDir.Name, DatStatus = tDir.DatStatus, Dat = tDir.Dat, Game = tDir.Game }; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "romof": tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(DatFileLoader.GnRest())); DatFileLoader.Gn(); break; case "description": tDir.Game.AddData(RvGame.GameData.Description, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "sourcefile": tDir.Game.AddData(RvGame.GameData.Sourcefile, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "cloneof": tDir.Game.AddData(RvGame.GameData.CloneOf, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "sampleof": tDir.Game.AddData(RvGame.GameData.SampleOf, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "board": tDir.Game.AddData(RvGame.GameData.Board, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "year": tDir.Game.AddData(RvGame.GameData.Year, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "manufacturer": tDir.Game.AddData(RvGame.GameData.Manufacturer, DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "serial": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "rebuildto": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sample": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "biosset": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "chip": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "video": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sound": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "input": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "dipswitch": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "driver": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "rom": DatFileLoader.Gn(); if (!LoadRomFromDat(ref tDir, thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "disk": DatFileLoader.Gn(); if (!LoadDiskFromDat(ref tDirCHD)) { return(false); } DatFileLoader.Gn(); break; case "archive": DatFileLoader.Gn(); if (!LoadArchiveFromDat()) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadGameFromDat_not_known_in_game, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } if (tDir.ChildCount > 0) { parent.ChildAdd(tDir, index1); } if (tDirCHD.ChildCount > 0) { parent.ChildAdd(tDirCHD); } return(true); }
private static bool LoadGameFromDat(RvDat rvDat, string rootName, HeaderFileType datFileType) { if (DatFileLoader.Next != "(") { DatUpdate.SendAndShowDat("( not found after game on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } DatFileLoader.Gn(); string snext = DatFileLoader.Next.ToLower(); string pathextra = ""; if (snext == "rebuildto") { pathextra = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); snext = DatFileLoader.Next.ToLower(); } if (snext != "name") { DatUpdate.SendAndShowDat("Name not found as first object in ( ) on line " + DatFileLoader.LineNumber, DatFileLoader.Filename); return(false); } string name = VarFix.CleanFullFileName(DatFileLoader.GnRest()); name = Path.Combine(pathextra, name); name = Path.Combine(rootName, name); name = (name.EndsWith(".zip") ? name.Remove(name.Length - 4) : name); DatFileLoader.Gn(); RvGame rvGame = new RvGame { Name = name }; while (DatFileLoader.Next != ")") { switch (DatFileLoader.Next.ToLower()) { case "romof": rvGame.RomOf = VarFix.CleanFileName(DatFileLoader.GnRest()); DatFileLoader.Gn(); break; case "description": rvGame.Description = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sourcefile": rvGame.SourceFile = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "cloneof": rvGame.CloneOf = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sampleof": rvGame.SampleOf = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "board": rvGame.Board = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "year": rvGame.Year = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "manufacturer": rvGame.Manufacturer = DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "serial": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "rebuildto": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sample": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "biosset": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "chip": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "video": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "sound": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "input": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "dipswitch": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "driver": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; case "file": DatFileLoader.Gn(); if (!LoadRomFromDat(rvGame, datFileType)) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat("Error on line " + DatFileLoader.LineNumber + ": key word '" + DatFileLoader.Next + "' not known in game", DatFileLoader.Filename); DatFileLoader.Gn(); break; } } rvDat.AddGame(rvGame); return(true); }
public static bool ReadDat(ref RvDir tDat, string strFilename) { RvDir tNow = tDat; FileType thisFileType = FileType.ZipFile; int errorCode = DatFileLoader.LoadDat(strFilename); if (errorCode != 0) { DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename); return(false); } DatFileLoader.Gn(); if (DatFileLoader.EndOfStream()) { return(false); } if (DatFileLoader.Next.ToLower() == "clrmamepro") { _cleanFileNames = true; DatFileLoader.Gn(); if (!LoadHeaderFromDat(ref tNow, ref thisFileType)) { return(false); } DatFileLoader.Gn(); } if (DatFileLoader.Next.ToLower() == "romvault") { _cleanFileNames = false; DatFileLoader.Gn(); if (!LoadHeaderFromDat(ref tNow, ref thisFileType)) { return(false); } DatFileLoader.Gn(); } if (tNow.Dat == null) { tNow.Dat = new RvDat(); string cleanedName = Path.GetFileNameWithoutExtension(strFilename); tNow.Dat.AddData(RvDat.DatData.DatName, cleanedName); tNow.Dat.AddData(RvDat.DatData.Description, cleanedName); } while (!DatFileLoader.EndOfStream()) { switch (DatFileLoader.Next.ToLower()) { case "dir": DatFileLoader.Gn(); if (!LoadDirFromDat(ref tNow, ref thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "game": DatFileLoader.Gn(); if (!LoadGameFromDat(ref tNow, false, thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "resource": DatFileLoader.Gn(); if (!LoadGameFromDat(ref tNow, true, thisFileType)) { return(false); } DatFileLoader.Gn(); break; case "emulator": DatFileLoader.Gn(); if (!LoadEmulator()) { return(false); } DatFileLoader.Gn(); break; default: DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_ReadDat_not_known, DatFileLoader.Filename); DatFileLoader.Gn(); break; } } DatFileLoader.Close(); return(true); }