private static void OpenDefaultDB() { DirTree = new RvDir(FileType.Dir) { Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; RvDir rv = new RvDir(FileType.Dir) { Name = "ROMVault", Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; DirTree.ChildAdd(rv); RvDir ts = new RvDir(FileType.Dir) { Name = "Unsorted", Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; DirTree.ChildAdd(ts); }
private static void OpenDefaultDB() { DirTree = new RvDir(FileType.Dir) { Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; RvDir rv = new RvDir(FileType.Dir) { Name = "RomVault", Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; DirTree.ChildAdd(rv); RvDir ts = new RvDir(FileType.Dir) { Name = "ToSort", Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect }; DirTree.ChildAdd(ts); }
private static void LoadDiskFromDat(ref RvDir tGame, XmlNode romNode) { if (romNode.Attributes == null) return; XmlNode name = romNode.Attributes.GetNamedItem("name"); RvFile tRom = new RvFile(FileType.File) { Name = VarFix.CleanFullFileName(name) + ".chd", SHA1CHD = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40), Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")), Dat = tGame.Dat }; if (tRom.SHA1CHD != null) tRom.FileStatusSet(FileStatus.SHA1CHDFromDAT); tGame.ChildAdd(tRom); }
private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode, FileType thisFileType) { if (romNode.Attributes == null) return; RvFile tRom = new RvFile(thisFileType) { Dat = tGame.Dat, Size = VarFix.ULong(romNode.Attributes.GetNamedItem("size")), Name = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")), 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")) }; if (tRom.Size != null) tRom.FileStatusSet(FileStatus.SizeFromDAT); if (tRom.CRC != null) tRom.FileStatusSet(FileStatus.CRCFromDAT); if (tRom.SHA1 != null) tRom.FileStatusSet(FileStatus.SHA1FromDAT); if (tRom.MD5 != null) tRom.FileStatusSet(FileStatus.MD5FromDAT); tGame.ChildAdd(tRom); }
private static void LoadDirFromDat(ref RvDir tDat, XmlNode dirNode, FileType thisFileType) { if (dirNode.Attributes == null) return; RvDir parent = tDat; string fullname = VarFix.CleanFullFileName(dirNode.Attributes.GetNamedItem("name")); while (fullname.Contains("/")) { int firstSlash = fullname.IndexOf("/", StringComparison.Ordinal); string dir = fullname.Substring(0, firstSlash); dir = VarFix.CleanFileName(dir); 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; } } RvDir tDir = new RvDir(FileType.Dir) { Name = fullname, DatStatus = DatStatus.InDatCollect, Dat = tDat.Dat, Tree = new RvTreeRow() }; int index1; if (parent.ChildNameSearch(tDir, out index1) == 0) tDir = (RvDir)parent.Child(index1); else tDat.ChildAdd(tDir, index1); XmlNodeList dirNodeList = dirNode.SelectNodes("dir"); if (dirNodeList != null) { for (int i = 0; i < dirNodeList.Count; i++) { LoadDirFromDat(ref tDir, dirNodeList[i], thisFileType); } } XmlNodeList gameNodeList = dirNode.SelectNodes("game"); if (gameNodeList != null) { for (int i = 0; i < gameNodeList.Count; i++) { LoadGameFromDat(ref tDir, gameNodeList[i], thisFileType); } } }
private static void UpdateDirs(RvDir dbDir, RvDir fileDir) { int dbIndex = 0; int scanIndex = 0; dbDir.DatStatus=DatStatus.InDatCollect; if (dbDir.Tree == null) { Debug.WriteLine("Adding Tree View to " + dbDir.Name); dbDir.Tree = new RvTreeRow(); } Debug.WriteLine(""); Debug.WriteLine("Now scanning dirs"); while (dbIndex < dbDir.ChildCount || scanIndex < fileDir.ChildCount) { RvBase dbChild = null; RvBase fileChild = null; int res = 0; if (dbIndex < dbDir.ChildCount && scanIndex < fileDir.ChildCount) { dbChild = dbDir.Child(dbIndex); fileChild = fileDir.Child(scanIndex); res = DBHelper.CompareName(dbChild, fileChild); Debug.WriteLine("Checking " + dbChild.Name + " : and " + fileChild.Name + " : " + res); } else if (scanIndex < fileDir.ChildCount) { fileChild = fileDir.Child(scanIndex); res = 1; Debug.WriteLine("Checking : and " + fileChild.Name + " : " + res); } else if (dbIndex < dbDir.ChildCount) { dbChild = dbDir.Child(dbIndex); res = -1; } switch (res) { case 0: // found a matching directory in DATRoot So recurse back into it if (dbChild.GotStatus == GotStatus.Got) { if (dbChild.Name != fileChild.Name) // check if the case of the Item in the DB is different from the Dat Root Actual filename { if (!string.IsNullOrEmpty(dbChild.FileName)) // if we do not already have a different case name stored { dbChild.FileName = dbChild.Name; // copy the DB filename to the FileName } else // We already have a different case filename found in ROMRoot { if (dbChild.FileName == fileChild.Name) // check if the DATRoot name does now match the name in the DB Filename { dbChild.FileName = null; // if it does undo the BadCase Flag } } dbChild.Name = fileChild.Name; // Set the db Name to match the DATRoot Name. } } else dbChild.Name = fileChild.Name; UpdateDatList((RvDir)dbChild,(RvDir)fileChild); dbIndex++; scanIndex++; break; case 1: // found a new directory in Dat RvDir tDir = new RvDir(FileType.Dir) { Name = fileChild.Name, Tree = new RvTreeRow(), DatStatus = DatStatus.InDatCollect, }; dbDir.ChildAdd(tDir, dbIndex); Debug.WriteLine("Adding new Dir and Calling back in to check this DIR " + tDir.Name); UpdateDatList(tDir,(RvDir)fileChild); dbIndex++; scanIndex++; break; case -1: // all files dbIndex++; break; } } }
private static bool UpdateDatFile(RvDat file, bool autoAddDirectory, RvDir thisDirectory) { // Read the new Dat File into newDatFile RvDir newDatFile = DatReader.ReadInDatFile(file, _bgw); // If we got a valid Dat File back if (newDatFile == null || newDatFile.Dat == null) { ReportError.Show("Error reading Dat " + file.GetData(RvDat.DatData.DatFullName)); return false; } newDatFile.Dat.AutoAddDirectory = autoAddDirectory; if ((autoAddDirectory || !String.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))) && newDatFile.Dat.GetData(RvDat.DatData.DirSetup)!= "noautodir") { // if we are auto adding extra directorys then create a new directory. newDatFile.Name = !String.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)) ? newDatFile.Dat.GetData(RvDat.DatData.RootDir) : newDatFile.Dat.GetData(RvDat.DatData.DatName); newDatFile.DatStatus = DatStatus.InDatCollect; newDatFile.Tree = new RvTreeRow(); RvDir newDirectory = new RvDir(FileType.Dir) { Dat = newDatFile.Dat }; // add the DAT into this directory newDirectory.ChildAdd(newDatFile); newDatFile = newDirectory; } if (thisDirectory.Tree == null) thisDirectory.Tree = new RvTreeRow(); RvDat conflictDat; if (MergeInDat(thisDirectory, newDatFile, out conflictDat, true)) { ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatFullName) + " is trying to use the same dirctory and so will be ignored."); return false; } //SetInDat(thisDirectory); // Add the new Dat thisDirectory.DirDatAdd(newDatFile.Dat); // Merge the files/directories in the Dat MergeInDat(thisDirectory, newDatFile, out conflictDat, false); return true; }
private static bool RecursiveDatTree(RvDir tDir, out int datCount) { datCount = 0; string strPath = tDir.DatFullName; if (!Directory.Exists(strPath)) { ReportError.Show(Resources.DatUpdate_UpdateDatList_Path + strPath + Resources.DatUpdate_UpdateDatList_Not_Found); return false; } DirectoryInfo oDir = new DirectoryInfo(strPath); FileInfo[] oFilesIn = oDir.GetFiles("*.dat", false); datCount += oFilesIn.Length; foreach (FileInfo file in oFilesIn) { RvDat tDat = new RvDat(); tDat.AddData(RvDat.DatData.DatFullName, file.FullName); tDat.TimeStamp = file.LastWriteTime; tDir.DirDatAdd(tDat); } oFilesIn = oDir.GetFiles("*.xml", false); datCount += oFilesIn.Length; foreach (FileInfo file in oFilesIn) { RvDat tDat = new RvDat(); tDat.AddData(RvDat.DatData.DatFullName, file.FullName); tDat.TimeStamp = file.LastWriteTime; tDir.DirDatAdd(tDat); } if (tDir.DirDatCount > 1) for (int i = 0; i < tDir.DirDatCount; i++) tDir.DirDat(i).AutoAddDirectory = true; DirectoryInfo[] oSubDir = oDir.GetDirectories(false); foreach (DirectoryInfo t in oSubDir) { RvDir cDir = new RvDir(FileType.Dir) { Name = t.Name, DatStatus = DatStatus.InDatCollect }; int index = tDir.ChildAdd(cDir); int retDatCount; RecursiveDatTree(cDir, out retDatCount); datCount += retDatCount; if (retDatCount == 0) tDir.ChildRemove(index); } return true; }
private static ReturnCode FixZip(RvDir fixZip) { //Check for error status if (fixZip.DirStatus.HasUnknown()) return ReturnCode.FindFixes; // Error bool needsTrrntzipped = fixZip.ZipStatus != ZipStatus.TrrntZip && fixZip.GotStatus == GotStatus.Got && fixZip.DatStatus == DatStatus.InDatCollect && (Settings.FixLevel == eFixLevel.TrrntZipLevel1 || Settings.FixLevel == eFixLevel.TrrntZipLevel2 || Settings.FixLevel == eFixLevel.TrrntZipLevel3); // file corrupt and not in tosort // if file cannot be fully fixed copy to corrupt // process zipfile if (fixZip.GotStatus == GotStatus.Corrupt && fixZip.DatStatus != DatStatus.InToSort) { ReturnCode movReturnCode = MoveZiptoCorrupt(fixZip); if (movReturnCode != ReturnCode.Good) return movReturnCode; } // has fixable // process zipfile else if (fixZip.DirStatus.HasFixable()) { // do nothing here but continue on to process zip. } // need trrntzipped // process zipfile else if (needsTrrntzipped) { // do nothing here but continue on to process zip. } // got empty zip that should be deleted // process zipfile else if (fixZip.GotStatus == GotStatus.Got && fixZip.GotStatus != GotStatus.Corrupt && !fixZip.DirStatus.HasAnyFiles()) { // do nothing here but continue on to process zip. } // else // skip this zipfile else { // nothing can be done to return return ReturnCode.Good; } string fixZipFullName = fixZip.TreeFullName; if (!fixZip.DirStatus.HasFixable() && needsTrrntzipped) ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), "", 0, "TrrntZipping", "", "", "")); CheckCreateParent(fixZip.Parent); ReportError.LogOut(""); ReportError.LogOut(fixZipFullName + " : " + fixZip.RepStatus); ReportError.LogOut("------------------------------------------------------------"); Debug.WriteLine(fixZipFullName + " : " + fixZip.RepStatus); ReportError.LogOut("Zip File Status Before Fix:"); for (int intLoop = 0; intLoop < fixZip.ChildCount; intLoop++) ReportError.LogOut((RvFile)fixZip.Child(intLoop)); ReportError.LogOut(""); ZipFile tempZipOut = null; ZipFile toSortCorruptOut = null; ZipFile toSortZipOut = null; RvDir toSortGame = null; RvDir toSortCorruptGame = null; ReturnCode returnCode; List<RvFile> fixZipTemp = new List<RvFile>(); for (int iRom = 0; iRom < fixZip.ChildCount; iRom++) { RvFile zipFileFixing = new RvFile(FileType.ZipFile); fixZip.Child(iRom).CopyTo(zipFileFixing); if (iRom == fixZipTemp.Count) fixZipTemp.Add(zipFileFixing); else fixZipTemp[iRom] = zipFileFixing; ReportError.LogOut(zipFileFixing.RepStatus + " : " + fixZip.Child(iRom).FullName); switch (zipFileFixing.RepStatus) { #region Nothing to copy // any file we do not have or do not want in the destination zip case RepStatus.Missing: case RepStatus.NotCollected: case RepStatus.Rename: case RepStatus.Delete: if (! ( // got the file in the original zip but will be deleting it (zipFileFixing.DatStatus == DatStatus.NotInDat && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.NotInDat && zipFileFixing.GotStatus == GotStatus.Corrupt) || (zipFileFixing.DatStatus == DatStatus.InDatMerged && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.InToSort && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.InToSort && zipFileFixing.GotStatus == GotStatus.Corrupt) || // do not have this file and cannot fix it here (zipFileFixing.DatStatus == DatStatus.InDatCollect && zipFileFixing.GotStatus == GotStatus.NotGot) || (zipFileFixing.DatStatus == DatStatus.InDatBad && zipFileFixing.GotStatus == GotStatus.NotGot) || (zipFileFixing.DatStatus == DatStatus.InDatMerged && zipFileFixing.GotStatus == GotStatus.NotGot) ) ) ReportError.SendAndShow(Resources.FixFiles_FixZip_Error_in_Fix_Rom_Status + zipFileFixing.RepStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.DatStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.GotStatus); if (zipFileFixing.RepStatus == RepStatus.Delete) { returnCode = DoubleCheckDelete(zipFileFixing); if (returnCode != ReturnCode.Good) goto ZipOpenFailed; } zipFileFixing.GotStatus = GotStatus.NotGot; break; #endregion #region Copy from Original to Destination // any files we are just moving from the original zip to the destination zip case RepStatus.Correct: case RepStatus.InToSort: case RepStatus.NeededForFix: case RepStatus.Corrupt: { if (! ( (zipFileFixing.DatStatus == DatStatus.InDatCollect && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.InDatMerged && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.NotInDat && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.InToSort && zipFileFixing.GotStatus == GotStatus.Got) || (zipFileFixing.DatStatus == DatStatus.InToSort && zipFileFixing.GotStatus == GotStatus.Corrupt) ) ) ReportError.SendAndShow(Resources.FixFiles_FixZip_Error_in_Fix_Rom_Status + zipFileFixing.RepStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.DatStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.GotStatus); RvFile foundFile; bool rawcopy = (zipFileFixing.RepStatus == RepStatus.InToSort) || (zipFileFixing.RepStatus == RepStatus.Corrupt); // Correct rawcopy=false // NeededForFix rawcopy=false // InToSort rawcopy=true // Corrupt rawcopy=true RepStatus originalStatus = zipFileFixing.RepStatus; returnCode = FixFileCopy.CopyFile( (RvFile)fixZip.Child(iRom), ref tempZipOut, Path.Combine(fixZip.Parent.FullName, "__RomVault.tmp"), zipFileFixing, rawcopy, out _error, out foundFile); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; if (originalStatus == RepStatus.NeededForFix) zipFileFixing.RepStatus = RepStatus.NeededForFix; break; case ReturnCode.SourceCRCCheckSumError: { RvFile tFile = (RvFile)fixZip.Child(iRom); tFile.GotStatus = GotStatus.Corrupt; ReCheckFile(tFile); //decrease index so this file gets reprocessed iRom--; continue; } case ReturnCode.SourceCheckSumError: { // Set the file in the zip that we thought we correctly had as missing RvFile tFile = (RvFile)fixZip.Child(iRom); if (tFile.FileRemove() == EFile.Delete) { _error = "Should not mark for delete as it is in a DAT"; return ReturnCode.LogicError; } // Add in at the current location the incorrect file. (This file will be reprocessed and then at some point deleted.) fixZip.ChildAdd(foundFile, iRom); AddFoundFile(foundFile); ReCheckFile(tFile); //decrease index so this file gets reprocessed iRom--; continue; } // not needed as source and destination are the same // case ReturnCode.DestinationCheckSumError: default: _error = zipFileFixing.FullName + " " + zipFileFixing.RepStatus + " " + returnCode + " : " + _error; goto ZipOpenFailed; } } break; #endregion #region Case.CanBeFixed case RepStatus.CanBeFixed: case RepStatus.CorruptCanBeFixed: { if (!(zipFileFixing.DatStatus == DatStatus.InDatCollect && (zipFileFixing.GotStatus == GotStatus.NotGot || zipFileFixing.GotStatus == GotStatus.Corrupt))) ReportError.SendAndShow(Resources.FixFiles_FixZip_Error_in_Fix_Rom_Status + zipFileFixing.RepStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.DatStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.GotStatus); ReportError.LogOut("Fixing File:"); ReportError.LogOut(zipFileFixing); string strPath = fixZip.Parent.FullName; string tempZipFilename = Path.Combine(strPath, "__RomVault.tmp"); if (DBHelper.IsZeroLengthFile(zipFileFixing)) { RvFile fileIn = new RvFile(FileType.ZipFile) { Size = 0 }; RvFile foundFile; returnCode = FixFileCopy.CopyFile(fileIn, ref tempZipOut, tempZipFilename, zipFileFixing, false, out _error, out foundFile); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; default: _error = zipFileFixing.FullName + " " + zipFileFixing.RepStatus + " " + returnCode + " : " + _error; goto ZipOpenFailed; } break; } #if NEWFINDFIX List<RvFile> lstFixRomTable = new List<RvFile>(); List<RvFile> family = zipFileFixing.MyFamily.Family; for (int iFind = 0; iFind < family.Count; iFind++) { if (family[iFind].GotStatus == GotStatus.Got && FindFixes.CheckIfMissingFileCanBeFixedByGotFile(zipFileFixing, family[iFind])) lstFixRomTable.Add(family[iFind]); } #else List<RvFile> lstFixRomTable; DBHelper.RomSearchFindFixes(zipFileFixing, _lstRomTableSortedCRCSize, out lstFixRomTable); #endif ReportError.LogOut("Found Files To use for Fixes:"); foreach (RvFile t in lstFixRomTable) ReportError.LogOut(t); if (lstFixRomTable.Count > 0) { string ts = lstFixRomTable[0].Parent.FullName; string sourceDir; string sourceFile; if (lstFixRomTable[0].FileType == FileType.ZipFile) { sourceDir = Path.GetDirectoryName(ts); sourceFile = Path.GetFileName(ts); } else { sourceDir = ts; sourceFile = ""; } ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), zipFileFixing.Name, zipFileFixing.Size, "<--", sourceDir, sourceFile, lstFixRomTable[0].Name)); RvFile foundFile; returnCode = FixFileCopy.CopyFile(lstFixRomTable[0], ref tempZipOut, tempZipFilename, zipFileFixing, false, out _error, out foundFile); switch (returnCode) { case ReturnCode.Good: // correct reply so continue; break; case ReturnCode.SourceCRCCheckSumError: { ReportProgress(new bgwShowFixError("CRC Error")); // the file we used for fix turns out to be corrupt RvFile tFile = (RvFile)fixZip.Child(iRom); // mark the source file as Corrupt lstFixRomTable[0].GotStatus = GotStatus.Corrupt; // recheck for the fix ReCheckFile(tFile); // if the file being used from the fix is actually from this file then we have a big mess, and we are just going to // start over on this zip. if (lstFixRomTable[0].Parent == fixZip) { returnCode = ReturnCode.StartOver; goto ZipOpenFailed; } // add the fixing source zip into the processList so that it is also reprocessed and we just changed it. if (!_processList.Contains(lstFixRomTable[0].Parent)) _processList.Add(lstFixRomTable[0].Parent); // and go back one and try again. iRom--; continue; } case ReturnCode.SourceCheckSumError: { ReportProgress(new bgwShowFixError("Failed")); // the file we used for fix turns out not not match its own DAT's correct MD5/SHA1 // (Problem with logic here is that it could still match the file being fixed, but this case is not correctly handled) RvFile tFile = (RvFile)fixZip.Child(iRom); // remove the file we thought we correctly had (The file that we where trying to use for the fix) if (lstFixRomTable[0].FileRemove() == EFile.Delete) { _error = "Should not mark for delete as it is in a DAT"; return ReturnCode.LogicError; } // possibly use a check here to see if the index of the found file is futher down the zip and so we can just contine // instead of restarting. // add in the actual file we found lstFixRomTable[0].Parent.ChildAdd(foundFile); AddFoundFile(foundFile); // recheck for the fix ReCheckFile(tFile); // if the file being used from the fix is actually from this file then we have a big mess, and we are just going to // start over on this zip. if (lstFixRomTable[0].Parent == fixZip) { returnCode = ReturnCode.StartOver; goto ZipOpenFailed; } // add the fixing source zip into the processList so that it is also reprocessed and we just changed it. if (!_processList.Contains(lstFixRomTable[0].Parent)) _processList.Add(lstFixRomTable[0].Parent); // and go back one and try again. iRom--; continue; } case ReturnCode.DestinationCheckSumError: { ReportProgress(new bgwShowFixError("Failed")); // the file we used for fix turns out not to have the correct MD5/SHA1 RvFile tFile = (RvFile)fixZip.Child(iRom); // recheck for the fix ReCheckFile(tFile); // if the file being used from the fix is actually from this file then we have a big mess, and we are just going to // start over on this zip. // The need for this is that the file being pulled in from inside this zip will be marked as Rename // and so would then automatically be deleted, in the case this exception happens, this source file instead // should be set to move to tosort. if (lstFixRomTable[0].Parent == fixZip) { returnCode = ReturnCode.StartOver; goto ZipOpenFailed; } // and go back one and try again. iRom--; continue; } default: //_error = zipFileFixing.FullName + " " + zipFileFixing.RepStatus + " " + returnCode + Environment.NewLine + _error; goto ZipOpenFailed; } //Check to see if the files used for fix, can now be set to delete CheckReprocessClearList(); foreach (RvFile tFixRom in lstFixRomTable) { if (tFixRom.RepStatus == RepStatus.NeededForFix) { tFixRom.RepStatus = RepStatus.Delete; ReportError.LogOut("Setting File Status to Delete:"); ReportError.LogOut(tFixRom); CheckReprocess(tFixRom, true); } } CheckReprocessFinalCheck(); _fixed++; } else // thought we could fix it, turns out we cannot zipFileFixing.GotStatus = GotStatus.NotGot; } break; #endregion #region Case.MoveToSort case RepStatus.MoveToSort: { if (!(zipFileFixing.DatStatus == DatStatus.NotInDat && zipFileFixing.GotStatus == GotStatus.Got)) ReportError.SendAndShow(Resources.FixFiles_FixZip_Error_in_Fix_Rom_Status + zipFileFixing.RepStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.DatStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.GotStatus); ReportError.LogOut("Moving File out to ToSort:"); ReportError.LogOut(zipFileFixing); // move the rom out to the To Sort Directory if (toSortGame == null) { string toSortFullName = Path.Combine(Settings.ToSort(), fixZip.Name + ".zip"); string toSortFileName = fixZip.Name; int fileC = 0; while (File.Exists(toSortFullName)) { fileC++; toSortFullName = Path.Combine(Settings.ToSort(), fixZip.Name + fileC + ".zip"); toSortFileName = fixZip.Name + fileC; } toSortGame = new RvDir(FileType.Zip) { Name = toSortFileName, DatStatus = DatStatus.InToSort, GotStatus = GotStatus.Got }; } RvFile toSortRom = new RvFile(FileType.ZipFile) { Name = zipFileFixing.Name, Size = zipFileFixing.Size, CRC = zipFileFixing.CRC, SHA1 = zipFileFixing.SHA1, MD5 = zipFileFixing.MD5 }; toSortRom.SetStatus(DatStatus.InToSort, GotStatus.Got); toSortRom.FileStatusSet( FileStatus.SizeFromHeader | FileStatus.SizeVerified | FileStatus.CRCFromHeader | FileStatus.CRCVerified | FileStatus.SHA1FromHeader | FileStatus.SHA1Verified | FileStatus.MD5FromHeader | FileStatus.MD5Verified , zipFileFixing); toSortGame.ChildAdd(toSortRom); string destination = Path.Combine(Settings.ToSort(), toSortGame.Name + ".zip"); ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), zipFileFixing.Name, zipFileFixing.Size, "-->", "ToSort", Path.GetFileName(destination), toSortRom.Name)); RvFile foundFile; returnCode = FixFileCopy.CopyFile((RvFile)fixZip.Child(iRom), ref toSortZipOut, destination, toSortRom, true, out _error, out foundFile); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; //raw copying so Checksums are not checked //case ReturnCode.SourceCRCCheckSumError: //case ReturnCode.SourceCheckSumError: //case ReturnCode.DestinationCheckSumError: default: _error = zipFileFixing.FullName + " " + zipFileFixing.RepStatus + " " + returnCode + " : " + _error; goto ZipOpenFailed; } zipFileFixing.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted } break; #endregion #region Case.MoveToCorrupt case RepStatus.MoveToCorrupt: { if (!((zipFileFixing.DatStatus == DatStatus.InDatCollect || zipFileFixing.DatStatus == DatStatus.NotInDat) && zipFileFixing.GotStatus == GotStatus.Corrupt)) ReportError.SendAndShow(Resources.FixFiles_FixZip_Error_in_Fix_Rom_Status + zipFileFixing.RepStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.DatStatus + Resources.FixFiles_FixZip_Colon + zipFileFixing.GotStatus); ReportError.LogOut("Moving File to Corrupt"); ReportError.LogOut(zipFileFixing); string toSortFullName; if (toSortCorruptGame == null) { string corruptDir = Path.Combine(Settings.ToSort(), "Corrupt"); if (!Directory.Exists(corruptDir)) { Directory.CreateDirectory(corruptDir); } toSortFullName = Path.Combine(corruptDir, fixZip.Name + ".zip"); string toSortFileName = fixZip.Name; int fileC = 0; while (File.Exists(toSortFullName)) { fileC++; toSortFullName = Path.Combine(corruptDir, fixZip.Name + fileC + ".zip"); toSortFileName = fixZip.Name + fileC; } toSortCorruptGame = new RvDir(FileType.Zip) { Name = toSortFileName, DatStatus = DatStatus.InToSort, GotStatus = GotStatus.Got }; } else { string corruptDir = Path.Combine(Settings.ToSort(), "Corrupt"); toSortFullName = Path.Combine(corruptDir, toSortCorruptGame.Name + ".zip"); } RvFile toSortCorruptRom = new RvFile(FileType.ZipFile) { Name = zipFileFixing.Name, Size = zipFileFixing.Size, CRC = zipFileFixing.CRC }; toSortCorruptRom.SetStatus(DatStatus.InToSort, GotStatus.Corrupt); toSortCorruptGame.ChildAdd(toSortCorruptRom); ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), zipFileFixing.Name, zipFileFixing.Size, "-->", "Corrupt", Path.GetFileName(toSortFullName), zipFileFixing.Name)); RvFile foundFile; returnCode = FixFileCopy.CopyFile((RvFile)fixZip.Child(iRom), ref toSortCorruptOut, toSortFullName, toSortCorruptRom, true, out _error, out foundFile); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; // doing a raw copy so not needed // case ReturnCode.SourceCRCCheckSumError: // case ReturnCode.SourceCheckSumError: // case ReturnCode.DestinationCheckSumError: default: _error = zipFileFixing.FullName + " " + zipFileFixing.RepStatus + " " + returnCode + " : " + _error; goto ZipOpenFailed; } zipFileFixing.GotStatus = GotStatus.NotGot; } break; #endregion default: ReportError.UnhandledExceptionHandler("Unknown file status found " + zipFileFixing.RepStatus + " while fixing file " + fixZip.Name + " Dat Status = " + zipFileFixing.DatStatus + " GotStatus " + zipFileFixing.GotStatus); break; } } #region if ToSort Zip Made then close the zip and add this new zip to the Database if (toSortGame != null) { toSortZipOut.ZipFileClose(); toSortGame.TimeStamp = toSortZipOut.TimeStamp; toSortGame.DatStatus = DatStatus.InToSort; toSortGame.GotStatus = GotStatus.Got; toSortGame.ZipStatus = toSortZipOut.ZipStatus; RvDir toSort = (RvDir)DB.DirTree.Child(1); toSort.ChildAdd(toSortGame); } #endregion #region if Corrupt Zip Made then close the zip and add this new zip to the Database if (toSortCorruptGame != null) { toSortCorruptOut.ZipFileClose(); toSortCorruptGame.TimeStamp = toSortCorruptOut.TimeStamp; toSortCorruptGame.DatStatus = DatStatus.InToSort; toSortCorruptGame.GotStatus = GotStatus.Got; RvDir toSort = (RvDir)DB.DirTree.Child(1); int indexcorrupt; RvDir corruptDir = new RvDir(FileType.Dir) { Name = "Corrupt", DatStatus = DatStatus.InToSort }; int found = toSort.ChildNameSearch(corruptDir, out indexcorrupt); if (found != 0) { corruptDir.GotStatus = GotStatus.Got; indexcorrupt = toSort.ChildAdd(corruptDir); } ((RvDir)toSort.Child(indexcorrupt)).ChildAdd(toSortCorruptGame); } #endregion #region Process original Zip string filename = fixZip.FullName; if (File.Exists(filename)) { if (!File.SetAttributes(filename, FileAttributes.Normal)) { int error = Error.GetLastError(); ReportProgress(new bgwShowError(filename, "Error Setting File Attributes to Normal. Deleting Original Fix File. Code " + error)); } try { File.Delete(filename); } catch (Exception) { int error = Error.GetLastError(); _error = "Error While trying to delete file " + filename + ". Code " + error; if (tempZipOut != null && tempZipOut.ZipOpen != ZipOpenType.Closed) tempZipOut.ZipFileClose(); return ReturnCode.RescanNeeded; } } #endregion bool checkDelete = false; #region process the temp Zip rename it to the original Zip if (tempZipOut != null && tempZipOut.ZipOpen != ZipOpenType.Closed) { string tempFilename = tempZipOut.ZipFilename; tempZipOut.ZipFileClose(); if (tempZipOut.LocalFilesCount() > 0) { // now rename the temp fix file to the correct filename File.Move(tempFilename, filename); FileInfo nFile = new FileInfo(filename); RvDir tmpZip = new RvDir(FileType.Zip) { Name = Path.GetFileNameWithoutExtension(filename), TimeStamp = nFile.LastWriteTime }; tmpZip.SetStatus(fixZip.DatStatus, GotStatus.Got); fixZip.FileAdd(tmpZip); fixZip.ZipStatus = tempZipOut.ZipStatus; } else { File.Delete(tempFilename); checkDelete = true; } } else checkDelete = true; #endregion #region Now put the New Game Status information into the Database. int intLoopFix = 0; foreach (RvFile tmpZip in fixZipTemp) { tmpZip.CopyTo(fixZip.Child(intLoopFix)); if (fixZip.Child(intLoopFix).RepStatus == RepStatus.Deleted) if (fixZip.Child(intLoopFix).FileRemove() == EFile.Delete) { fixZip.ChildRemove(intLoopFix); continue; } intLoopFix++; } #endregion if (checkDelete) CheckDeleteObject(fixZip); ReportError.LogOut(""); ReportError.LogOut("Zip File Status After Fix:"); for (int intLoop = 0; intLoop < fixZip.ChildCount; intLoop++) ReportError.LogOut((RvFile)fixZip.Child(intLoop)); ReportError.LogOut(""); return ReturnCode.Good; ZipOpenFailed: if (tempZipOut != null) tempZipOut.ZipFileCloseFailed(); if (toSortZipOut != null) toSortZipOut.ZipFileCloseFailed(); if (toSortCorruptOut != null) toSortCorruptOut.ZipFileCloseFailed(); return returnCode; }
private static void DatSetRemoveGameDir(RvDir newDir) { if (newDir.ChildCount != 1) return; RvDir child = newDir.Child(0) as RvDir; if (child.FileType != FileType.Dir) return; if (child.Game == null) return; newDir.ChildRemove(0); newDir.Game = child.Game; for (int i = 0; i < child.ChildCount; i++) newDir.ChildAdd(child.Child(i), i); }
private static void DatSetCreateSubDirs(RvDir tDat) { for (int g = 0; g < tDat.ChildCount; g++) { if (tDat.Child(g).FileType == FileType.Zip) continue; RvDir datGame = (RvDir)tDat.Child(g); // first do a quick check to see if anything needs done. bool fixNeeded = false; for (int r = 0; r < datGame.ChildCount; r++) { fixNeeded = datGame.Child(r).Name.Contains("/"); if (fixNeeded) break; } // if nothing needs done skip to next game if (!fixNeeded) continue; RvDir fixedGame = new RvDir(FileType.Dir); while (datGame.ChildCount > 0) { RvBase nextChild = datGame.Child(0); datGame.ChildRemove(0); if (nextChild.GetType() == typeof(RvFile)) { RvFile tFile = (RvFile)nextChild; if (tFile.Name.Contains("/")) { RvDir tBase = fixedGame; Debug.WriteLine("tFile " + tFile.TreeFullName); while (tFile.Name.Contains("/")) { int dirIndex = tFile.Name.IndexOf("/", StringComparison.Ordinal); string dirName = tFile.Name.Substring(0, dirIndex); RvDir tDir = new RvDir(FileType.Dir) { Name = dirName, DatStatus = DatStatus.InDatCollect, Dat = datGame.Dat }; int index; if (tBase.ChildNameSearch(tDir, out index) != 0) tBase.ChildAdd(tDir, index); tBase = (RvDir)tBase.Child(index); tFile.Name = tFile.Name.Substring(tFile.Name.IndexOf("/", StringComparison.Ordinal) + 1); } tBase.ChildAdd(tFile); } else fixedGame.ChildAdd(nextChild); } else fixedGame.ChildAdd(nextChild); } for (int r = 0; r < fixedGame.ChildCount; r++) datGame.ChildAdd(fixedGame.Child(r), r); } }
private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode) { if (romNode.Attributes == null) return; XmlNode name = romNode.Attributes.GetNamedItem("name"); string loadflag = VarFix.String(romNode.Attributes.GetNamedItem("loadflag")); if (name != null) { RvFile tRom = new RvFile(FileType.ZipFile) { Name = VarFix.CleanFullFileName(name), Size = VarFix.ULong(romNode.Attributes.GetNamedItem("size")), CRC = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8), SHA1 = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40), Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")), Dat = tGame.Dat }; if (tRom.Size != null) tRom.FileStatusSet(FileStatus.SizeFromDAT); if (tRom.CRC != null) tRom.FileStatusSet(FileStatus.CRCFromDAT); if (tRom.SHA1 != null) tRom.FileStatusSet(FileStatus.SHA1FromDAT); _indexContinue = tGame.ChildAdd(tRom); } else if (loadflag.ToLower() == "continue") { RvFile tZippedFile = (RvFile)tGame.Child(_indexContinue); tZippedFile.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size")); } }
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 void CheckADir(RvDir dbDir, bool report) { if (_cacheSaveTimer.Elapsed.TotalMinutes > Settings.CacheSaveTimePeriod) { _bgw.ReportProgress(0, "Saving Cache"); DB.Write(); _bgw.ReportProgress(0, "Saving Cache Complete"); _cacheSaveTimer.Reset(); _cacheSaveTimer.Start(); } string fullDir = dbDir.FullName; if (report) _bgw.ReportProgress(0, new bgwText2(fullDir)); DatStatus chechingDatStatus = dbDir.IsInToSort ? DatStatus.InToSort : DatStatus.NotInDat; // this is a temporary rvDir structure to store the data about the actual directory/files we are scanning // we will first populate this variable with the real file data from the directory, and then compare it // with the data in dbDir. RvDir fileDir = null; Debug.WriteLine(fullDir); FileType ft = dbDir.FileType; #region "Populate fileDir" // if we are scanning a ZIP file then populate scanDir from the ZIP file switch (ft) { case FileType.Zip: { fileDir = new RvDir(ft); // open the zip file ZipFile checkZ = new ZipFile(); ZipReturn zr = checkZ.ZipFileOpen(fullDir, dbDir.TimeStamp, true); if (zr == ZipReturn.ZipGood) { dbDir.ZipStatus = checkZ.ZipStatus; // to be Scanning a ZIP file means it is either new or has changed. // as the code below only calls back here if that is true. // // Level1: Only use header CRC's // Just get the CRC for the ZIP headers. // // Level2: Fully checksum changed only files // We know this file has been changed to do a full checksum scan. // // Level3: Fully checksum everything // So do a full checksum scan. if (EScanLevel == eScanLevel.Level2 || EScanLevel == eScanLevel.Level3) checkZ.DeepScan(); // add all of the file information from the zip file into scanDir for (int i = 0; i < checkZ.LocalFilesCount(); i++) { RvFile tFile = new RvFile(DBTypeGet.FileFromDir(ft)) { Name = checkZ.Filename(i), ZipFileIndex = i, ZipFileHeaderPosition = checkZ.LocalHeader(i), Size = checkZ.UncompressedSize(i), CRC = checkZ.CRC32(i) }; // all 3 levels read the CRC from the ZIP header tFile.SetStatus(chechingDatStatus, GotStatus.Got); tFile.FileStatusSet(FileStatus.SizeFromHeader | FileStatus.CRCFromHeader); // if we are in level 2 or level 3 then do a full CheckSum Scan. if (EScanLevel == eScanLevel.Level2 || EScanLevel == eScanLevel.Level3) { // DeepScan will return ZipReturn.ZipCRCDecodeError if the headers CRC and // the actual CRC do not match. // So we just need to set the MD5 and SHA1 from the ZIP file. zr = checkZ.FileStatus(i); if (zr == ZipReturn.ZipUntested) { _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir + " : " + checkZ.Filename(i))); } else if (zr != ZipReturn.ZipGood) { _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir + " : " + checkZ.Filename(i))); tFile.GotStatus = GotStatus.Corrupt; } else { tFile.MD5 = checkZ.MD5(i); tFile.SHA1 = checkZ.SHA1(i); tFile.FileStatusSet(FileStatus.SizeVerified | FileStatus.CRCVerified | FileStatus.SHA1Verified | FileStatus.MD5Verified); } } fileDir.ChildAdd(tFile); } } else if (zr == ZipReturn.ZipFileLocked) { _bgw.ReportProgress(0, new bgwShowError(fullDir, "Zip File Locked")); dbDir.TimeStamp = 0; dbDir.GotStatus = GotStatus.FileLocked; } else { _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir)); dbDir.GotStatus = GotStatus.Corrupt; } checkZ.ZipFileClose(); } break; case FileType.Dir: { fileDir = new RvDir(FileType.Dir); DirectoryInfo oDir = new DirectoryInfo(fullDir); DirectoryInfo[] oDirs = oDir.GetDirectories(); FileInfo[] oFiles = oDir.GetFiles(); // add all the subdirectories into scanDir foreach (DirectoryInfo dir in oDirs) { RvBase tDir = new RvDir(FileType.Dir) { Name = dir.Name, TimeStamp = dir.LastWriteTime, }; tDir.SetStatus(chechingDatStatus, GotStatus.Got); fileDir.ChildAdd(tDir); } // add all the files into scanDir foreach (FileInfo oFile in oFiles) { // if we find any zip files add them as zip files. string fExt = Path.GetExtension(oFile.Name); switch (fExt.ToLower()) { case ".zip": { RvDir tGame = new RvDir(FileType.Zip) { Name = Path.GetFileNameWithoutExtension(oFile.Name), TimeStamp = oFile.LastWriteTime, }; tGame.SetStatus(chechingDatStatus, GotStatus.Got); fileDir.ChildAdd(tGame); } break; default: { string fName = oFile.Name; if (fName == "__RomVault.tmp") { File.Delete(oFile.FullName); continue; } // Scanning a file // // Level1 & 2 : (are the same for files) Fully checksum changed only files // Here we are just getting the TimeStamp of the File, and later // if the TimeStamp was not matched we will have to read the files CRC, MD5 & SHA1 // // Level3: Fully checksum everything // Get everything about the file right here so // read CRC, MD5 & SHA1 // add all the files in the sub-directory to scanDir RvFile tFile = new RvFile(FileType.File) { Name = fName, Size = (ulong)oFile.Length, TimeStamp = oFile.LastWriteTime }; tFile.FileStatusSet(FileStatus.SizeVerified); int errorCode = CHD.CheckFile(oFile, out tFile.SHA1CHD, out tFile.MD5CHD, out tFile.CHDVersion); if (errorCode == 0) { if (tFile.SHA1CHD != null) tFile.FileStatusSet(FileStatus.SHA1CHDFromHeader); if (tFile.MD5CHD != null) tFile.FileStatusSet(FileStatus.MD5CHDFromHeader); tFile.SetStatus(chechingDatStatus, GotStatus.Got); // if we are scanning at Level3 then we get all the info here if (EScanLevel == eScanLevel.Level3) { DeepScanFile(fullDir, tFile); ChdManCheck(fullDir, tFile); } } else if (errorCode == 32) { tFile.GotStatus = GotStatus.FileLocked; _bgw.ReportProgress(0, new bgwShowError(fullDir, "File Locked")); } else { string filename = Path.Combine(fullDir, tFile.Name); ReportError.Show("File: " + filename + " Error: " + new Win32Exception(errorCode).Message + ". Scan Aborted."); _fileErrorAbort = true; return; } fileDir.ChildAdd(tFile); } break; } } } break; default: ReportError.SendAndShow("Un supported file type in CheckADir " + ft); break; } #endregion if (fileDir == null) { ReportError.SendAndShow("Unknown Reading File Type in Dir Scanner"); return; } if (report) { _bgw.ReportProgress(0, new bgwSetRange2(fileDir.ChildCount - 1)); _bgw.ReportProgress(0, new bgwRange2Visible(true)); } if (!DBTypeGet.isCompressedDir(ft) && _bgw.CancellationPending) return; Compare(dbDir, fileDir, report, true); }
/* private static void SetInDat(RvDir tDir) { tDir.DatStatus = DatStatus.InDatCollect; if (tDir.Parent != null) SetInDat(tDir.Parent); } */ private static Boolean MergeInDat(RvDir dbDat, RvDir newDat, out RvDat conflict, bool checkOnly) { conflict = null; int dbIndex = 0; int newIndex = 0; while (dbIndex < dbDat.ChildCount || newIndex < newDat.ChildCount) { RvBase dbChild = null; RvBase newDatChild = null; int res = 0; if (dbIndex < dbDat.ChildCount && newIndex < newDat.ChildCount) { dbChild = dbDat.Child(dbIndex); // are files newDatChild = newDat.Child(newIndex); // is from a dat item res = DBHelper.CompareName(dbChild, newDatChild); } else if (newIndex < newDat.ChildCount) { newDatChild = newDat.Child(newIndex); res = 1; } else if (dbIndex < dbDat.ChildCount) { dbChild = dbDat.Child(dbIndex); res = -1; } if (res == 0) { if (dbChild == null || newDatChild == null) { SendAndShowDat(Resources.DatUpdate_MergeInDat_Error_in_Logic, dbDat.FullName); break; } List<RvBase> dbDats = new List<RvBase>(); List<RvBase> newDats = new List<RvBase>(); int dbDatsCount = 1; int newDatsCount = 1; dbDats.Add(dbChild); newDats.Add(newDatChild); while (dbIndex + dbDatsCount < dbDat.ChildCount && DBHelper.CompareName(dbChild, dbDat.Child(dbIndex + dbDatsCount)) == 0) { dbDats.Add(dbDat.Child(dbIndex + dbDatsCount)); dbDatsCount += 1; } while (newIndex + newDatsCount < newDat.ChildCount && DBHelper.CompareName(newDatChild, newDat.Child(newIndex + newDatsCount)) == 0) { newDats.Add(newDat.Child(newIndex + newDatsCount)); newDatsCount += 1; } if (dbDatsCount > 1 || newDatsCount > 1) { ReportError.SendAndShow("Double Name Found"); } for (int indexdb = 0; indexdb < dbDatsCount; indexdb++) { if (dbDats[indexdb].DatStatus == DatStatus.NotInDat) continue; if (checkOnly) { conflict = dbChild.Dat; return true; } SendAndShowDat(Resources.DatUpdate_MergeInDat_Unkown_Update_Dat_Status + dbChild.DatStatus, dbDat.FullName); break; } if (!checkOnly) { for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++) { if (newDats[indexNewDats].SearchFound) continue; for (int indexDbDats = 0; indexDbDats < dbDatsCount; indexDbDats++) { if (dbDats[indexDbDats].SearchFound) continue; bool matched = FullCompare(dbDats[indexDbDats], newDats[indexNewDats]); if (!matched) continue; dbDats[indexDbDats].DatAdd(newDats[indexNewDats]); FileType ft = dbChild.FileType; if (ft == FileType.Zip || ft == FileType.Dir) { RvDir dChild = (RvDir)dbChild; RvDir dNewChild = (RvDir)newDatChild; MergeInDat(dChild, dNewChild, out conflict, checkOnly); } dbDats[indexDbDats].SearchFound = true; newDats[indexNewDats].SearchFound = true; } } for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++) { if (newDats[indexNewDats].SearchFound) continue; dbDat.ChildAdd(newDats[indexNewDats], dbIndex); dbChild = dbDat.Child(dbIndex); SetMissingStatus(dbChild); dbIndex++; } } dbIndex += dbDatsCount; newIndex += newDatsCount; } if (res == 1) { if (!checkOnly) { dbDat.ChildAdd(newDatChild, dbIndex); dbChild = dbDat.Child(dbIndex); SetMissingStatus(dbChild); dbIndex++; } newIndex++; } if (res == -1) { dbIndex++; } } return false; }
private static void NewFileFound(RvBase fileChild, RvDir dbDir, int dbIndex) { if (fileChild == null) { ReportError.SendAndShow(Resources.FileScanning_CheckADir_Error_in_File_Scanning_Code); return; } // this could be an unknown file, or dirctory. // if item is a directory add the directory and call back in again // add the newly found item switch (fileChild.FileType) { case FileType.Zip: dbDir.ChildAdd(fileChild, dbIndex); CheckADir((RvDir)fileChild, false); break; case FileType.Dir: dbDir.ChildAdd(fileChild, dbIndex); CheckADir((RvDir)fileChild, true); break; case FileType.File: RvFile tChild = (RvFile)fileChild; // if we have not read the files CRC in the checking code, we need to read it now. if (tChild.GotStatus != GotStatus.FileLocked) { if (!IsDeepScanned(tChild)) DeepScanFile(dbDir.FullName, tChild); if (!IschdmanScanned(tChild) && EScanLevel == eScanLevel.Level2) ChdManCheck(dbDir.FullName, tChild); } dbDir.ChildAdd(fileChild, dbIndex); break; case FileType.ZipFile: dbDir.ChildAdd(fileChild, dbIndex); break; default: throw new Exception("Unsuported file type " + fileChild.FileType); } }
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; }