public int ChildAdd(RvBase child) { int index; ChildNameSearch(child, out index); ChildAdd(child, index); return index; }
public void ChildAdd(RvBase child, int index) { if ( (FileType == FileType.Dir && child.FileType == FileType.ZipFile) || (FileType == FileType.Zip && child.FileType != FileType.ZipFile) ) ReportError.SendAndShow("Typing to add a " + child.FileType + " to a " + FileType); _children.Insert(index, child); child.Parent = this; UpdateRepStatusArrUpTree(child, 1); }
public static int CompareName(RvBase var1, RvBase var2) { int retv = TrrntZipStringCompare(var1.Name, var2.Name); if (retv != 0) return retv; FileType f1 = var1.FileType; FileType f2 = var2.FileType; if (f1 == FileType.ZipFile) { if (f2 != FileType.ZipFile) ReportError.SendAndShow("Incompatible Compare type"); return Math.Sign(String.Compare(var1.Name, var2.Name, StringComparison.Ordinal)); } return f1.CompareTo(f2); }
public int ChildNameSearch(RvBase lName, out int index) { int intBottom = 0; int intTop = _children.Count; int intMid = 0; int intRes = -1; //Binary chop to find the closest match while ((intBottom < intTop) && (intRes != 0)) { intMid = (intBottom + intTop) / 2; intRes = DBHelper.CompareName(lName, _children[intMid]); if (intRes < 0) { intTop = intMid; } else if (intRes > 0) { intBottom = intMid + 1; } } index = intMid; // if match was found check up the list for the first match if (intRes == 0) { int intRes1 = 0; while ((index > 0) && (intRes1 == 0)) { intRes1 = DBHelper.CompareName(lName, _children[index - 1]); if (intRes1 == 0) { index--; } } } // if the search is greater than the closest match move one up the list else if (intRes > 0) { index++; } return(intRes); }
public bool FindChild(RvBase lName, out int index) { if (ChildNameSearch(lName, out index) != 0) { ReportError.UnhandledExceptionHandler("Could not find self in Parent " + FullName); return(false); } do { if (_children[index] == lName) { return(true); } index++; } while ((index < _children.Count) && (DBHelper.CompareName(lName, _children[index]) == 0)); return(false); }
public override void DatAdd(RvBase file) { RvFile tFile = file as RvFile; if (tFile == null) { ReportError.SendAndShow("Error setting Dat Set Got"); return; } if (Size == null && tFile.Size != null) { Size = tFile.Size; } if (CRC == null && tFile.CRC != null) { CRC = tFile.CRC; } if (SHA1 == null && tFile.SHA1 != null) { SHA1 = tFile.SHA1; } if (MD5 == null && tFile.MD5 != null) { MD5 = tFile.MD5; } if (SHA1CHD == null && tFile.SHA1CHD != null) { SHA1CHD = tFile.SHA1CHD; } if (MD5CHD == null && tFile.MD5CHD != null) { MD5CHD = tFile.MD5CHD; } FileStatusSet( FileStatus.SizeFromDAT | FileStatus.CRCFromDAT | FileStatus.SHA1FromDAT | FileStatus.MD5FromDAT | FileStatus.SHA1CHDFromDAT | FileStatus.MD5CHDFromDAT, tFile); Merge = tFile.Merge; Status = tFile.Status; base.DatAdd(file); }
public override void CopyTo(RvBase c) { RvFile cf = c as RvFile; if (cf != null) { cf.Size = Size; cf.CRC = CRC; cf.SHA1 = SHA1; cf.MD5 = MD5; cf.Merge = Merge; cf.Status = Status; cf._fileStatus = _fileStatus; cf.SHA1CHD = SHA1CHD; cf.MD5CHD = MD5CHD; cf.ZipFileIndex = ZipFileIndex; cf.ZipFileHeaderPosition = ZipFileHeaderPosition; cf.CHDVersion = CHDVersion; } base.CopyTo(c); }
public virtual void DatAdd(RvBase b) { // Parent , TimeStamp Should already be correct. if (GotStatus == GotStatus.NotGot) { ReportError.SendAndShow("Error Adding DAT to NotGot File " + b.GotStatus); } SetStatus(b.DatStatus, GotStatus.Got); if (Name == b.Name) // case match so all is good { FileName = null; } else { FileName = Name; Name = b.Name; } Dat = b.Dat; }
private void UpdateRepStatusArrUpTree(RvBase child, int dir) { DirStatus.UpdateRepStatus(child.RepStatus, dir); RvDir rvDir = child as RvDir; if (rvDir != null) DirStatus.UpdateRepStatus(rvDir.DirStatus, dir); if (Parent != null) Parent.UpdateRepStatusArrUpTree(child, dir); }
public override void Read(BinaryReader br, List <RvDat> parentDirDats) { base.Read(br, parentDirDats); bool foundTree = br.ReadBoolean(); if (foundTree) { Tree = new RvTreeRow(); Tree.Read(br); } else { Tree = null; } bool foundGame = br.ReadBoolean(); if (foundGame) { Game = new RvGame(); Game.Read(br); } else { Game = null; } int count = br.ReadInt32(); _dirDats.Clear(); for (int i = 0; i < count; i++) { RvDat dat = new RvDat { DatIndex = i }; dat.Read(br); _dirDats.Add(dat); string datname = TreeFullName + @"\" + dat.GetData(RvDat.DatData.DatName); if ((datname.Length >= 9) && (datname.Substring(0, 9) == @"RomVault\")) { datname = datname.Substring(9); } DB.Bgw.ReportProgress(0, new bgwText("Loading: " + datname)); DB.Bgw.ReportProgress((int)br.BaseStream.Position); } if (_dirDats.Count > 0) { parentDirDats = _dirDats; } count = br.ReadInt32(); _children.Clear(); for (int i = 0; i < count; i++) { RvBase tChild = DBTypeGet.GetRvType((FileType)br.ReadByte()); tChild.Parent = this; tChild.Read(br, parentDirDats); _children.Add(tChild); } if (DBTypeGet.isCompressedDir(FileType)) { ZipStatus = (ZipStatus)br.ReadByte(); } }
public override void DatAdd(RvBase b) { Tree = ((RvDir)b).Tree; Game = ((RvDir)b).Game; if (_dirDats.Count > 0) ReportError.SendAndShow(Resources.RvDir_SetDat_Setting_Dir_with_a_dat_list); base.DatAdd(b); }
public bool FindChild(RvBase lName, out int index) { if (ChildNameSearch(lName, out index) != 0) { ReportError.UnhandledExceptionHandler("Could not find self in Parent " + FullName); return false; } do { if (_children[index] == lName) return true; index++; } while (index < _children.Count && DBHelper.CompareName(lName, _children[index]) == 0); return false; }
private static ReturnCode FixBase(RvBase child, bool thisSelected) { // skip any files that have already been deleted if (child.RepStatus == RepStatus.Deleted) return ReturnCode.Good; if (_cacheSaveTimer.Elapsed.Minutes > Settings.CacheSaveTimePeriod) { ReportProgress("Saving Cache"); DB.Write(); ReportProgress("Saving Cache Complete"); _cacheSaveTimer.Reset(); _cacheSaveTimer.Start(); } ReturnCode returnCode = ReturnCode.LogicError; switch (child.FileType) { case FileType.Zip: if (!thisSelected) return ReturnCode.Good; if (!String.IsNullOrEmpty(child.FileName)) { string strDir = child.Parent.FullName; File.Move(Path.Combine(strDir, child.FileName + ".zip"), Path.Combine(strDir, child.Name + ".zip")); child.FileName = null; } do { returnCode = FixZip((RvDir)child); } while (returnCode == ReturnCode.StartOver); break; case FileType.Dir: if (thisSelected) { if (!String.IsNullOrEmpty(child.FileName)) { string strDir = child.Parent.FullName; System.IO.Directory.Move(Path.Combine(strDir, child.FileName), Path.Combine(strDir, "__RomVault.tmpDir")); Directory.Move(Path.Combine(strDir, "__RomVault.tmpDir"), Path.Combine(strDir, child.Name)); child.FileName = null; } } returnCode = FixDir((RvDir)child, thisSelected); return returnCode; case FileType.File: if (!thisSelected) return ReturnCode.Good; do { returnCode = FixFile((RvFile)child); } while (returnCode == ReturnCode.StartOver); break; } switch (returnCode) { case ReturnCode.Good: // all good, move alone. break; case ReturnCode.RescanNeeded: ReportError.Show(_error); break; case ReturnCode.LogicError: ReportError.UnhandledExceptionHandler(_error); break; case ReturnCode.FileSystemError: ReportError.Show(_error); break; case ReturnCode.FindFixes: ReportError.Show("You Need to Find Fixes before Fixing. (Incorrect File Status's found for fixing.)"); break; default: ReportError.UnhandledExceptionHandler(Resources.FixFiles_FixDirChildren_Unknown_result_type + returnCode); break; } return returnCode; }
private void DatSetSelected(RvBase cf) { DirTree.Refresh(); if (Settings.IsMono) { if (GameGrid.RowCount > 0) GameGrid.CurrentCell = GameGrid[0,0]; if (RomGrid.RowCount > 0) RomGrid.CurrentCell = RomGrid[0,0]; } GameGrid.Rows.Clear(); RomGrid.Rows.Clear(); // clear sorting GameGrid.Columns[_gameGridSortColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.None; _gameGridSortColumnIndex = 0; _gameGridSortOrder = SortOrder.Descending; if (cf == null) return; UpdateGameGrid((RvDir)cf); }
public virtual void CopyTo(RvBase c) { c.Name = Name; c.FileName = FileName; //c.Parent = Parent; c.Dat = Dat; c.TimeStamp = TimeStamp; c.ReportIndex = ReportIndex; c._datStatus = _datStatus; c._gotStatus = _gotStatus; c.RepStatus = RepStatus; }
public virtual void FileAdd(RvBase file) { TimeStamp = file.TimeStamp; FileCheckName(file); if (file.GotStatus == GotStatus.NotGot) ReportError.SendAndShow("Error setting got to a NotGot File"); GotStatus = file.GotStatus; }
private static void DBFileNotFound(RvBase dbChild, RvDir dbDir, ref int dbIndex) { if (dbChild == null) { ReportError.SendAndShow(Resources.FileScanning_CheckADir_Error_in_File_Scanning_Code); return; } if (dbChild.FileRemove() == EFile.Delete) dbDir.ChildRemove(dbIndex); else { switch (dbChild.FileType) { case FileType.Zip: MarkAsMissing((RvDir)dbChild); break; case FileType.Dir: RvDir tDir = (RvDir)dbChild; if (tDir.Tree == null) MarkAsMissing(tDir); break; } dbIndex++; } }
public override void FileAdd(RvBase file) { RvFile tFile = file as RvFile; if (tFile == null) { ReportError.SendAndShow("Error setting File Got"); return; } if (Size == null && tFile.Size != null) Size = tFile.Size; if (CRC == null && tFile.CRC != null) CRC = tFile.CRC; if (SHA1 == null && tFile.SHA1 != null) SHA1 = tFile.SHA1; if (MD5 == null && tFile.MD5 != null) MD5 = tFile.MD5; if (SHA1CHD == null && tFile.SHA1CHD != null) SHA1CHD = tFile.SHA1CHD; if (MD5CHD == null && tFile.MD5CHD != null) MD5CHD = tFile.MD5CHD; CHDVersion = tFile.CHDVersion; FileStatusSet( FileStatus.SizeFromHeader | FileStatus.CRCFromHeader | FileStatus.SHA1FromHeader | FileStatus.MD5FromHeader | FileStatus.SHA1CHDFromHeader | FileStatus.MD5CHDFromHeader | FileStatus.SizeVerified | FileStatus.CRCVerified | FileStatus.SHA1Verified | FileStatus.MD5Verified | FileStatus.SHA1CHDVerified | FileStatus.MD5CHDVerified, tFile); ZipFileIndex = tFile.ZipFileIndex; ZipFileHeaderPosition = tFile.ZipFileHeaderPosition; base.FileAdd(file); }
private static void MatchFound(RvBase dbChild, RvBase fileChild) { // only check a zip if the filestamp has changed, we asume it is the same if the filestamp has not changed. switch (dbChild.FileType) { case FileType.Zip: if (dbChild.TimeStamp != fileChild.TimeStamp || EScanLevel == eScanLevel.Level3 || (EScanLevel == eScanLevel.Level2 && !IsDeepScanned((RvDir)dbChild))) { // this is done first as the CheckADir could change this value if the zip turns out to be corrupt dbChild.FileAdd(fileChild); CheckADir((RvDir)dbChild, false); } else // this is still needed incase the filenames case (upper/lower characters) have changed, but nothing else dbChild.FileCheckName(fileChild); break; case FileType.Dir: RvDir tDir = (RvDir)dbChild; if (tDir.Tree == null) // do not recurse into directories that are in the tree, as they are processed by the top level code. CheckADir(tDir, true); if (_fileErrorAbort) return; dbChild.FileAdd(fileChild); break; case FileType.File: case FileType.ZipFile: if (dbChild.TimeStamp == fileChild.TimeStamp && dbChild.GotStatus == GotStatus.Corrupt) fileChild.GotStatus = GotStatus.Corrupt; dbChild.FileAdd(fileChild); break; default: throw new Exception("Unsuported file type " + dbChild.FileType); } }
public override void DatAdd(RvBase file) { RvFile tFile = file as RvFile; if (tFile == null) { ReportError.SendAndShow("Error setting Dat Set Got"); return; } if (Size == null && tFile.Size != null) Size = tFile.Size; if (CRC == null && tFile.CRC != null) CRC = tFile.CRC; if (SHA1 == null && tFile.SHA1 != null) SHA1 = tFile.SHA1; if (MD5 == null && tFile.MD5 != null) MD5 = tFile.MD5; if (SHA1CHD == null && tFile.SHA1CHD != null) SHA1CHD = tFile.SHA1CHD; if (MD5CHD == null && tFile.MD5CHD != null) MD5CHD = tFile.MD5CHD; FileStatusSet( FileStatus.SizeFromDAT | FileStatus.CRCFromDAT | FileStatus.SHA1FromDAT | FileStatus.MD5FromDAT | FileStatus.SHA1CHDFromDAT | FileStatus.MD5CHDFromDAT, tFile); Merge = tFile.Merge; Status = tFile.Status; base.DatAdd(file); }
private static void GetSelectedFilesSortSHA1CHD(ref List<RvFile> lstFiles, RvBase val, bool selected) { if (selected) { RvFile rvFile = val as RvFile; if (rvFile != null) { if (rvFile.SHA1CHD != null) lstFiles.Add(rvFile); } } RvDir rvVal = val as RvDir; if (rvVal == null) return; for (int i = 0; i < rvVal.ChildCount; i++) { bool nextSelect = selected; if (rvVal.Tree != null) nextSelect = rvVal.Tree.Checked == RvTreeRow.TreeSelect.Selected; GetSelectedFilesSortSHA1CHD(ref lstFiles, rvVal.Child(i), nextSelect); } }
private static void FindAllDats(RvBase b, ReportType rt) { RvDir d = b as RvDir; if (d == null) return; if (d.DirDatCount > 0) { for (int i = 0; i < d.DirDatCount; i++) { RvDat dat = d.DirDat(i); int correct = 0; int missing = 0; int fixesNeeded = 0; if (d.Dat == dat) { correct += d.DirStatus.CountCorrect(); missing += d.DirStatus.CountMissing(); fixesNeeded += d.DirStatus.CountFixesNeeded(); } else { for (int j = 0; j < d.ChildCount; j++) { RvDir c = d.Child(j) as RvDir; if (c == null || c.Dat != dat) continue; correct += c.DirStatus.CountCorrect(); missing += c.DirStatus.CountMissing(); fixesNeeded += c.DirStatus.CountFixesNeeded(); } } switch (rt) { case ReportType.Complete: if (correct > 0 && missing == 0 && fixesNeeded == 0) _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); break; case ReportType.CompletelyMissing: if (correct == 0 && missing > 0 && fixesNeeded == 0) _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); break; case ReportType.PartialMissing: if ((correct > 0 && missing > 0) || fixesNeeded > 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); _fileNameLength = 0; _fileSizeLength = 0; _repStatusLength = 0; ReportMissingFindSizes(d, dat, rt); ReportDrawBars(); ReportMissing(d, dat, rt); ReportDrawBars(); _ts.WriteLine(); } break; case ReportType.Fixing: if (fixesNeeded > 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); _fileNameLength = 0; _fileSizeLength = 0; _repStatusLength = 0; ReportMissingFindSizes(d, dat, rt); ReportDrawBars(); ReportMissing(d, dat, rt); ReportDrawBars(); _ts.WriteLine(); } break; } } } if (b.Dat != null) return; for (int i = 0; i < d.ChildCount; i++) FindAllDats(d.Child(i), rt); }
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>"); } } } }
public int ChildNameSearch(RvBase lName, out int index) { int intBottom = 0; int intTop = _children.Count; int intMid = 0; int intRes = -1; //Binary chop to find the closest match while (intBottom < intTop && intRes != 0) { intMid = (intBottom + intTop) / 2; intRes = DBHelper.CompareName(lName, _children[intMid]); if (intRes < 0) intTop = intMid; else if (intRes > 0) intBottom = intMid + 1; } index = intMid; // if match was found check up the list for the first match if (intRes == 0) { int intRes1 = 0; while (index > 0 && intRes1 == 0) { intRes1 = DBHelper.CompareName(lName, _children[index - 1]); if (intRes1 == 0) index--; } } // if the search is greater than the closest match move one up the list else if (intRes > 0) index++; return intRes; }
private static bool FullCompare(RvBase var1, RvBase var2) { int retv = DBHelper.CompareName(var1, var2); if (retv != 0) return false; FileType v1 = var1.FileType; FileType v2 = var2.FileType; retv = Math.Sign(v1.CompareTo(v2)); if (retv != 0) return false; // filetypes are now know to be the same // Dir's and Zip's are not deep scanned so matching here is done if ((v1 == FileType.Dir) || (v1 == FileType.Zip)) return true; RvFile f1 = (RvFile)var1; RvFile f2 = (RvFile)var2; if (f1.Size != null && f2.Size != null) { retv = ULong.iCompare(f1.Size, f2.Size); if (retv != 0) return false; } if (f1.CRC != null && f2.CRC != null) { retv = ArrByte.iCompare(f1.CRC, f2.CRC); if (retv != 0) return false; } if (f1.SHA1 != null && f2.SHA1 != null) { retv = ArrByte.iCompare(f1.SHA1, f2.SHA1); if (retv != 0) return false; } if (f1.MD5 != null && f2.MD5 != null) { retv = ArrByte.iCompare(f1.MD5, f2.MD5); if (retv != 0) return false; } if (f1.SHA1CHD != null && f2.SHA1CHD != null) { retv = ArrByte.iCompare(f1.SHA1CHD, f2.SHA1CHD); if (retv != 0) return false; } if (f1.MD5CHD != null && f2.MD5CHD != null) { retv = ArrByte.iCompare(f1.MD5CHD, f2.MD5CHD); if (retv != 0) return false; } return true; }
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 void RemoveOldDats(RvBase dbDir, RvDir tmpDir) { // now compare the old and new dats removing any old dats // in the current directory RvDir lDir = dbDir as RvDir; if (lDir == null) return; int dbIndex = 0; int scanIndex = 0; while (dbIndex < lDir.DirDatCount || scanIndex < tmpDir.DirDatCount) { RvDat dbDat = null; RvDat fileDat = null; int res = 0; if (dbIndex < lDir.DirDatCount && scanIndex < tmpDir.DirDatCount) { dbDat = lDir.DirDat(dbIndex); fileDat = tmpDir.DirDat(scanIndex); res = DBHelper.DatCompare(dbDat, fileDat); } else if (scanIndex < tmpDir.DirDatCount) { //this is a new dat that we have now found at the end of the list //fileDat = tmpDir.DirDat(scanIndex); res = 1; } else if (dbIndex < lDir.DirDatCount) { dbDat = lDir.DirDat(dbIndex); res = -1; } switch (res) { case 0: dbDat.Status = DatUpdateStatus.Correct; dbIndex++; scanIndex++; break; case 1: // this is a new dat that we will add next time around scanIndex++; break; case -1: dbDat.Status = DatUpdateStatus.Delete; lDir.DirDatRemove(dbIndex); break; } } // now scan the child directory structure of this directory dbIndex = 0; scanIndex = 0; while (dbIndex < lDir.ChildCount || scanIndex < tmpDir.ChildCount) { RvBase dbChild = null; RvBase fileChild = null; int res = 0; if (dbIndex < lDir.ChildCount && scanIndex < tmpDir.ChildCount) { dbChild = lDir.Child(dbIndex); fileChild = tmpDir.Child(scanIndex); res = DBHelper.CompareName(dbChild, fileChild); } else if (scanIndex < tmpDir.ChildCount) { //found a new directory on the end of the list //fileChild = tmpDir.Child(scanIndex); res = 1; } else if (dbIndex < lDir.ChildCount) { dbChild = lDir.Child(dbIndex); res = -1; } switch (res) { case 0: // found a matching directory in DATRoot So recurse back into it RemoveOldDats(dbChild, (RvDir)fileChild); dbIndex++; scanIndex++; break; case 1: // found a new directory will be added later scanIndex++; break; case -1: if (dbChild.FileType == FileType.Dir && dbChild.Dat == null) RemoveOldDats(dbChild, new RvDir(FileType.Dir)); dbIndex++; break; } } }
private static bool FullCompare(RvBase dbFile, RvBase testFile, bool secondPass, string fullDir = "", eScanLevel sLevel = eScanLevel.Level3) { Debug.WriteLine("Comparing Dat File " + dbFile.TreeFullName); Debug.WriteLine("Comparing File " + testFile.TreeFullName); int retv = DBHelper.CompareName(dbFile, testFile); if (retv != 0) return false; FileType dbfileType = dbFile.FileType; FileType dbtestFile = testFile.FileType; retv = Math.Sign(dbfileType.CompareTo(dbtestFile)); if (retv != 0) return false; // filetypes are now know to be the same // Dir's and Zip's are not deep scanned so matching here is done if ((dbfileType == FileType.Dir) || (dbfileType == FileType.Zip)) return true; RvFile dbFileF = (RvFile)dbFile; RvFile testFileF = (RvFile)testFile; if (dbFileF.Size != null && testFileF.Size != null) { retv = ULong.iCompare(dbFileF.Size, testFileF.Size); if (retv != 0) return false; } if (dbFileF.CRC != null && testFileF.CRC != null) { retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC); if (retv != 0) return false; } if (dbFileF.SHA1 != null && testFileF.SHA1 != null) { retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1); if (retv != 0) return false; } if (dbFileF.MD5 != null && testFileF.MD5 != null) { retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5); if (retv != 0) return false; } if (dbFileF.SHA1CHD != null && testFileF.SHA1CHD != null) { retv = ArrByte.iCompare(dbFileF.SHA1CHD, testFileF.SHA1CHD); if (retv != 0) return false; } if (dbFileF.MD5CHD != null && testFileF.MD5CHD != null) { retv = ArrByte.iCompare(dbFileF.MD5CHD, testFileF.MD5CHD); if (retv != 0) return false; } // beyond here we only test files if (dbtestFile != FileType.File) return true; // if scanning at level 3 then we have already deep checked the file so all is OK. if (sLevel == eScanLevel.Level3) return true; // if we got this far then everything we have so far has matched, but that may not be enough. // now we see if we need to get any more info and try again. // if the file stamps do not match or the file in the DB we are comparing with has not been deep scanned // and the file we are scanning has not already been deep scanned, then we need to do a deep scan, and check the deep scan values // files are always deep scanned, so the test for IsDeepScanned(dbFileF) is probably not really needed here. if ((dbFileF.TimeStamp != testFileF.TimeStamp || !IsDeepScanned(dbFileF)) && !IsDeepScanned(testFileF)) { if (!secondPass) return false; DeepScanFile(fullDir, testFileF); if (dbFileF.CRC != null && testFileF.CRC != null) { retv = ArrByte.iCompare(dbFileF.CRC, testFileF.CRC); if (retv != 0) return false; } if (dbFileF.SHA1 != null && testFileF.SHA1 != null) { retv = ArrByte.iCompare(dbFileF.SHA1, testFileF.SHA1); if (retv != 0) return false; } if (dbFileF.MD5 != null && testFileF.MD5 != null) { retv = ArrByte.iCompare(dbFileF.MD5, testFileF.MD5); if (retv != 0) return false; } } // CHDman test, if we are only scanning at level 1 then don't do CHDman test so we are done. if (sLevel == eScanLevel.Level1) return true; if ((dbFileF.TimeStamp != testFileF.TimeStamp || (!IschdmanScanned(dbFileF)) && !IschdmanScanned(testFileF))) { ChdManCheck(fullDir, testFileF); } return true; }
private static EFile RemoveOldDatsCleanUpFiles(RvBase dbDir) { if (dbDir.Dat != null) { if (dbDir.Dat.Status == DatUpdateStatus.Correct) return EFile.Keep; if (dbDir.Dat.Status == DatUpdateStatus.Delete) { if (dbDir.DatRemove() == EFile.Delete) return EFile.Delete; //delete } } FileType ft = dbDir.FileType; // if we are checking a dir or zip recurse into it. if (ft != FileType.Zip && ft != FileType.Dir) return EFile.Keep; RvDir tDir = dbDir as RvDir; // remove all DATStatus's here they will get set back correctly when adding dats back in below. dbDir.DatStatus = DatStatus.NotInDat; for (int i = 0; i < tDir.ChildCount; i++) { if (RemoveOldDatsCleanUpFiles(tDir.Child(i)) == EFile.Keep) continue; tDir.ChildRemove(i); i--; } if (ft == FileType.Zip && dbDir.GotStatus == GotStatus.Corrupt) return EFile.Keep; // if this directory is now empty it should be deleted return tDir.ChildCount == 0 ? EFile.Delete : EFile.Keep; }
private static void RemoveOldTree(RvBase dbBase) { RvDir dbDir = dbBase as RvDir; if (dbDir == null) return; if (dbDir.DatStatus == DatStatus.NotInDat && dbDir.Tree != null) dbDir.Tree = null; for (int i = 0; i < dbDir.ChildCount; i++) RemoveOldTree(dbDir.Child(i)); }
private static void SetMissingStatus(RvBase dbChild) { if (dbChild.FileRemove() == EFile.Delete) { ReportError.SendAndShow("Error is Set Mssing Status in DatUpdate"); return; } FileType ft = dbChild.FileType; if (ft == FileType.Zip || ft == FileType.Dir) { RvDir dbDir = (RvDir)dbChild; for (int i = 0; i < dbDir.ChildCount; i++) SetMissingStatus(dbDir.Child(i)); } }
public virtual void DatAdd(RvBase b) { // Parent , TimeStamp Should already be correct. if (GotStatus == GotStatus.NotGot) ReportError.SendAndShow("Error Adding DAT to NotGot File " + b.GotStatus); SetStatus(b.DatStatus, GotStatus.Got); if (Name == b.Name) // case match so all is good { FileName = null; } else { FileName = Name; Name = b.Name; } Dat = b.Dat; }
public static void ReportStatusReset(RvBase tBase) { tBase.RepStatusReset(); FileType ftBase = tBase.FileType; if (ftBase != FileType.Zip && ftBase != FileType.Dir) return; RvDir tDir = (RvDir)tBase; for (int i = 0; i < tDir.ChildCount; i++) ReportStatusReset(tDir.Child(i)); }
public void FileCheckName(RvBase file) { // Don't care about bad case if the file is not in a dat. if (DatStatus == DatStatus.NotInDat || DatStatus == DatStatus.InUnsorted) Name = file.Name; FileName = Name == file.Name ? null : file.Name; }
private static void CheckReprocess(RvBase tCheck, bool fastProcess = false) { switch (tCheck.FileType) { case FileType.File: if (tCheck.RepStatus == RepStatus.Delete && !_processList.Contains(tCheck)) _processList.Add(tCheck); break; case FileType.ZipFile: RvDir p = tCheck.Parent; if (fastProcess) { if (!_checkList.Contains(p)) _checkList.Add(p); break; } if (!_processList.Contains(p)) { bool hasdelete = false; bool hasNeededForFix = false; for (int i = 0; i < p.ChildCount; i++) { RvBase f = p.Child(i); if (f.RepStatus == RepStatus.Delete) hasdelete = true; else if (f.RepStatus == RepStatus.NeededForFix || f.RepStatus == RepStatus.Rename) { hasNeededForFix = true; break; } } if (hasdelete && !hasNeededForFix) { Debug.WriteLine(tCheck.Parent.FullName + " adding to process list."); _processList.Add(p); } } break; default: ReportError.SendAndShow("Unknow repair file type recheck."); break; } }