private void BtnDeleteSelectedClick(object sender, EventArgs e) { ChangesMade = true; for (int j = 0; j < DataGridGames.SelectedRows.Count; j++) { string datLocation = DataGridGames.SelectedRows[j].Cells["CDAT"].Value.ToString(); if (datLocation == "RomVault") { ReportError.Show("You cannot delete the " + datLocation + " Directory Settings", "RomVault Rom Location"); } else { DatUpdate.CheckAllDats(DB.DirRoot.Child(0), datLocation); for (int i = 0; i < Settings.rvSettings.DatRules.Count; i++) { if (Settings.rvSettings.DatRules[i].DirKey == datLocation) { Settings.rvSettings.DatRules.RemoveAt(i); i--; } } } } Settings.WriteConfig(Settings.rvSettings); UpdateGrid(); }
private void BtnDeleteClick(object sender, EventArgs e) { string datLocation = _rule.DirKey; if (datLocation == "RomVault") { ReportError.Show("You cannot delete the " + datLocation + " Directory Settings", "RomVault Rom Location"); return; } else { ChangesMade = true; DatUpdate.CheckAllDats(DB.DirRoot.Child(0), datLocation); for (int i = 0; i < Settings.rvSettings.DatRules.Count; i++) { if (Settings.rvSettings.DatRules[i].DirKey == datLocation) { Settings.rvSettings.DatRules.RemoveAt(i); i--; } } } Settings.WriteConfig(Settings.rvSettings); UpdateGrid(); Close(); }
private static bool LoadNewDat(RvDat fileDat, RvFile thisDirectory) { // Read the new Dat File into newDatFile RvFile newDatFile = DatReader.ReadInDatFile(fileDat, _thWrk, out string extraDirName); // If we got a valid Dat File back if (newDatFile?.Dat == null) { ReportError.Show("Error reading Dat " + fileDat.GetData(RvDat.DatData.DatRootFullName)); return(false); } if (newDatFile.ChildCount == 0) { return(false); } if (!string.IsNullOrWhiteSpace(extraDirName)) { newDatFile.Name = VarFix.CleanFileName(extraDirName); newDatFile.DatStatus = DatStatus.InDatCollect; newDatFile.Tree = new RvTreeRow(); RvFile newDirectory = new RvFile(FileType.Dir) { Dat = newDatFile.Dat }; // add the DAT into this directory newDirectory.ChildAdd(newDatFile); newDatFile = newDirectory; newDatFile.Dat.AutoAddedDirectory = true; } else { newDatFile.Dat.AutoAddedDirectory = false; } if (thisDirectory.Tree == null) { thisDirectory.Tree = new RvTreeRow(); } if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true)) { ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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); }
public static void Read(object sender, DoWorkEventArgs e) { Bgw = sender as BackgroundWorker; Program.SyncCont = e.Argument as SynchronizationContext; if (!File.Exists(Settings.CacheFile)) { OpenDefaultDB(); Bgw = null; Program.SyncCont = null; return; } DirTree = new RvDir(FileType.Dir); FileStream fs = new FileStream(Settings.CacheFile, FileMode.Open, FileAccess.Read); if (fs.Length < 4) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } BinaryReader br = new BinaryReader(fs); if (Bgw != null) { Bgw.ReportProgress(0, new bgwSetRange((int)fs.Length)); } DBVersion.VersionNow = br.ReadInt32(); if (DBVersion.VersionNow != DBVersion.Version) { ReportError.Show(Resources.DB_Read_Data_Cache_version_is_out_of_date_you_should_now_rescan_your_dat_directory_and_roms_directory_); OpenDefaultDB(); } else { DirTree.Read(br, null); } if (fs.Position > fs.Length - 8) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } ulong testEOF = br.ReadUInt64(); if (testEOF != EndCacheMarker) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } br.Close(); fs.Close(); fs.Dispose(); Bgw = null; Program.SyncCont = null; }
public static void Read(ThreadWorker thWrk) { ThWrk = thWrk; if (!File.Exists(Settings.rvSettings.CacheFile)) { OpenDefaultDB(); ThWrk = null; return; } DirRoot = new RvFile(FileType.Dir); using (FileStream fs = new FileStream(Settings.rvSettings.CacheFile, FileMode.Open, FileAccess.Read)) { if (fs.Length < 4) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } using (BinaryReader br = new BinaryReader(fs, Encoding.UTF8, true)) { DivideProgress = fs.Length / 1000; DivideProgress = DivideProgress == 0 ? 1 : DivideProgress; ThWrk?.Report(new bgwSetRange(1000)); DBVersion.VersionNow = br.ReadInt32(); if (DBVersion.VersionNow != DBVersion.Version) { ReportError.Show( "Data Cache version is out of date you should now rescan your dat directory and roms directory."); br.Close(); fs.Close(); fs.Dispose(); OpenDefaultDB(); ThWrk = null; return; } else { DirRoot.Read(br, null); } if (fs.Position > fs.Length - 8) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } ulong testEOF = br.ReadUInt64(); if (testEOF != EndCacheMarker) { ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup."); } } } ThWrk = null; }
public static void FromAFile(RvFile file, string directory, EScanLevel eScanLevel, ThreadWorker bgw, ref bool fileErrorAbort) { string filename = Path.Combine(directory, file.Name); ICompress fileToScan = new Compress.File.File(); ZipReturn zr = fileToScan.ZipFileOpen(filename, file.FileModTimeStamp); if (zr == ZipReturn.ZipFileLocked) { file.GotStatus = GotStatus.FileLocked; return; } if (zr != ZipReturn.ZipGood) { ReportError.Show("File: " + filename + " Error: " + zr + ". Scan Aborted."); file.GotStatus = GotStatus.FileLocked; fileErrorAbort = true; return; } if (_fs == null) { _fs = new FileScan(); } List <FileScan.FileResults> fr = _fs.Scan(fileToScan, true, eScanLevel == EScanLevel.Level2 || eScanLevel == EScanLevel.Level3); file.HeaderFileType = fr[0].HeaderFileType; file.Size = fr[0].Size; file.CRC = fr[0].CRC; file.SHA1 = fr[0].SHA1; file.MD5 = fr[0].MD5; file.AltSize = fr[0].AltSize; file.AltCRC = fr[0].AltCRC; file.AltSHA1 = fr[0].AltSHA1; file.AltMD5 = fr[0].AltMD5; file.FileStatusSet( FileStatus.SizeVerified | (file.HeaderFileType != HeaderFileType.Nothing ? FileStatus.HeaderFileTypeFromHeader : 0) | (file.CRC != null ? FileStatus.CRCVerified : 0) | (file.SHA1 != null ? FileStatus.SHA1Verified : 0) | (file.MD5 != null ? FileStatus.MD5Verified : 0) | (file.AltSize != null ? FileStatus.AltSizeVerified : 0) | (file.AltCRC != null ? FileStatus.AltCRCVerified : 0) | (file.AltSHA1 != null ? FileStatus.AltSHA1Verified : 0) | (file.AltMD5 != null ? FileStatus.AltMD5Verified : 0) ); if (fr[0].HeaderFileType == HeaderFileType.CHD) { CHD.CheckFile(file, directory); if (eScanLevel == EScanLevel.Level2 || eScanLevel == EScanLevel.Level3) { Utils.ChdManCheck(file, directory, bgw, ref fileErrorAbort); } } fileToScan.ZipFileClose(); }
private static bool UpdateDatFile(RvDat file, bool autoAddDirectory, RvFile thisDirectory) { // Read the new Dat File into newDatFile RvFile newDatFile = DatReader.ReadInDatFile(file, _thWrk); // If we got a valid Dat File back if (newDatFile?.Dat == null) { ReportError.Show("Error reading Dat " + file.GetData(RvDat.DatData.DatRootFullName)); 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 directories 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(); RvFile newDirectory = new RvFile(FileType.Dir) { Dat = newDatFile.Dat }; // add the DAT into this directory newDirectory.ChildAdd(newDatFile); newDatFile = newDirectory; } if (thisDirectory.Tree == null) { thisDirectory.Tree = new RvTreeRow(); } if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true)) { ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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); }
public static void ChdManCheck(RvFile tFile, string directory, ThreadWorker thWrk, ref bool fileErrorAbort) { string filename = Path.Combine(directory, tFile.Name); if (tFile.FileStatusIs(FileStatus.AltSHA1FromHeader | FileStatus.AltSHA1Verified)) { return; } thWrk.Report(new bgwText2(filename)); CHD.CHDManCheck res = CHD.ChdmanCheck(filename, thWrk, out string error); switch (res) { case CHD.CHDManCheck.Good: tFile.FileStatusSet( (tFile.AltSHA1 != null ? FileStatus.AltSHA1Verified : 0) | (tFile.AltMD5 != null ? FileStatus.AltMD5Verified : 0) ); return; case CHD.CHDManCheck.Corrupt: thWrk.Report(new bgwShowError(filename, error)); tFile.GotStatus = GotStatus.Corrupt; return; case CHD.CHDManCheck.CHDReturnError: case CHD.CHDManCheck.CHDUnknownError: thWrk.Report(new bgwShowError(filename, error)); return; case CHD.CHDManCheck.ChdmanNotFound: return; case CHD.CHDManCheck.CHDNotFound: ReportError.Show("File: " + filename + " Error: Not Found scan Aborted."); fileErrorAbort = true; return; default: ReportError.UnhandledExceptionHandler(error); return; } }
private static void FileSystemError(string status) { ReportError.Show(status); }
public static void FromAFile(RvFile file, string directory, EScanLevel eScanLevel, ThreadWorker bgw, ref bool fileErrorAbort) { _bgw = bgw; string filename = Path.Combine(directory, string.IsNullOrWhiteSpace(file.FileName) ? file.Name : file.FileName); ICompress fileToScan = new Compress.File.File(); ZipReturn zr = fileToScan.ZipFileOpen(filename, file.FileModTimeStamp); if (zr == ZipReturn.ZipFileLocked) { file.GotStatus = GotStatus.FileLocked; return; } if (zr != ZipReturn.ZipGood) { ReportError.Show("File: " + filename + " Error: " + zr + ". Scan Aborted."); file.GotStatus = GotStatus.FileLocked; fileErrorAbort = true; return; } if (_fs == null) { _fs = new FileScan(); } List <FileScan.FileResults> fr = _fs.Scan(fileToScan, true, eScanLevel == EScanLevel.Level2 || eScanLevel == EScanLevel.Level3); file.HeaderFileType = fr[0].HeaderFileType; file.Size = fr[0].Size; file.CRC = fr[0].CRC; file.SHA1 = fr[0].SHA1; file.MD5 = fr[0].MD5; file.AltSize = fr[0].AltSize; file.AltCRC = fr[0].AltCRC; file.AltSHA1 = fr[0].AltSHA1; file.AltMD5 = fr[0].AltMD5; file.FileStatusSet( FileStatus.SizeVerified | (file.HeaderFileType != HeaderFileType.Nothing ? FileStatus.HeaderFileTypeFromHeader : 0) | (file.CRC != null ? FileStatus.CRCVerified : 0) | (file.SHA1 != null ? FileStatus.SHA1Verified : 0) | (file.MD5 != null ? FileStatus.MD5Verified : 0) | (file.AltSize != null ? FileStatus.AltSizeVerified : 0) | (file.AltCRC != null ? FileStatus.AltCRCVerified : 0) | (file.AltSHA1 != null ? FileStatus.AltSHA1Verified : 0) | (file.AltMD5 != null ? FileStatus.AltMD5Verified : 0) ); if (fr[0].HeaderFileType == HeaderFileType.CHD) { bool deepCheck = (eScanLevel == EScanLevel.Level2 || eScanLevel == EScanLevel.Level3); CHD.fileProcess = FileProcess; CHD.fileProgress = FileProgress; CHD.fileSystemError = FileSystemError; CHD.fileError = FileError; CHD.generalError = GeneralError; hdErr result = CHD.CheckFile(file.Name, directory, Settings.isLinux, ref deepCheck, out uint?chdVersion, out byte[] chdSHA1, out byte[] chdMD5, ref fileErrorAbort); switch (result) { case hdErr.HDERR_NONE: file.CHDVersion = chdVersion; if (chdSHA1 != null) { file.AltSHA1 = chdSHA1; file.FileStatusSet(FileStatus.AltSHA1FromHeader); if (deepCheck) { file.FileStatusSet(FileStatus.AltSHA1Verified); } } if (chdMD5 != null) { file.AltMD5 = chdMD5; file.FileStatusSet(FileStatus.AltMD5FromHeader); if (deepCheck) { file.FileStatusSet(FileStatus.AltMD5Verified); } } break; case hdErr.HDERR_OUT_OF_MEMORY: case hdErr.HDERR_INVALID_FILE: case hdErr.HDERR_INVALID_DATA: case hdErr.HDERR_READ_ERROR: case hdErr.HDERR_DECOMPRESSION_ERROR: case hdErr.HDERR_CANT_VERIFY: file.GotStatus = GotStatus.Corrupt; break; default: ReportError.UnhandledExceptionHandler(result.ToString()); break; } } fileToScan.ZipFileClose(); }
private static bool RecursiveDatTree(RvFile tDir, out int datCount) { datCount = 0; string strPath = RvFile.GetDatPhysicalPath(tDir.DatTreeFullName); if (!Directory.Exists(strPath)) { ReportError.Show("Path: " + strPath + " Not Found."); return(false); } DirectoryInfo oDir = new DirectoryInfo(strPath); List <FileInfo> lFilesIn = new List <FileInfo>(); FileInfo[] oFilesIn = oDir.GetFiles("*.dat"); lFilesIn.AddRange(oFilesIn); oFilesIn = oDir.GetFiles("*.xml"); lFilesIn.AddRange(oFilesIn); datCount += lFilesIn.Count; foreach (FileInfo file in lFilesIn) { RvDat tDat = new RvDat(); tDat.AddData(RvDat.DatData.DatRootFullName, Path.Combine(tDir.DatTreeFullName, file.Name)); tDat.TimeStamp = file.LastWriteTime; string datRootFullName = tDat.GetData(RvDat.DatData.DatRootFullName); DatRule datRule = DatReader.FindDatRule(datRootFullName); tDat.MultiDatOverride = datRule.MultiDATDirOverride; tDat.UseDescriptionAsDirName = datRule.UseDescriptionAsDirName; tDat.SingleArchive = datRule.SingleArchive; tDat.RemoveSubDir = datRule.RemoveSubDir; tDir.DirDatAdd(tDat); } if (tDir.DirDatCount > 1) { for (int i = 0; i < tDir.DirDatCount; i++) { tDir.DirDat(i).MultiDatsInDirectory = true; } } DirectoryInfo[] oSubDir = oDir.GetDirectories(); foreach (DirectoryInfo t in oSubDir) { RvFile cDir = new RvFile(FileType.Dir) { Name = t.Name, DatStatus = DatStatus.InDatCollect }; int index = tDir.ChildAdd(cDir); RecursiveDatTree(cDir, out int retDatCount); datCount += retDatCount; if (retDatCount == 0) { tDir.ChildRemove(index); } } return(true); }
private static bool LoadNewDat(RvDat fileDat, RvFile thisDirectory) { // Read the new Dat File into newDatFile RvFile newDatFile = DatReader.ReadInDatFile(fileDat, _thWrk); // If we got a valid Dat File back if (newDatFile?.Dat == null) { ReportError.Show("Error reading Dat " + fileDat.GetData(RvDat.DatData.DatRootFullName)); return(false); } if (newDatFile.ChildCount == 0) { return(false); } if ( !fileDat.MultiDatOverride && newDatFile.Dat.GetData(RvDat.DatData.DirSetup) != "noautodir" && ( fileDat.MultiDatsInDirectory || !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)) ) ) { // if we are auto adding extra directories then create a new directory. string dirName = ""; if (string.IsNullOrEmpty(dirName) && fileDat.UseDescriptionAsDirName && !string.IsNullOrWhiteSpace(newDatFile.Dat.GetData(RvDat.DatData.Description))) { dirName = newDatFile.Dat.GetData(RvDat.DatData.Description); } if (string.IsNullOrEmpty(dirName) && !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))) { dirName = newDatFile.Dat.GetData(RvDat.DatData.RootDir); } if (string.IsNullOrEmpty(dirName)) { dirName = newDatFile.Dat.GetData(RvDat.DatData.DatName); } if (string.IsNullOrEmpty(dirName)) { dirName = Path.GetFileNameWithoutExtension(newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName)); } newDatFile.Name = VarFix.CleanFileName(dirName); newDatFile.DatStatus = DatStatus.InDatCollect; newDatFile.Tree = new RvTreeRow(); RvFile newDirectory = new RvFile(FileType.Dir) { Dat = newDatFile.Dat }; // add the DAT into this directory newDirectory.ChildAdd(newDatFile); newDatFile = newDirectory; newDatFile.Dat.AutoAddedDirectory = true; } else { newDatFile.Dat.AutoAddedDirectory = false; } if (thisDirectory.Tree == null) { thisDirectory.Tree = new RvTreeRow(); } if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true)) { ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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(RvFile tDir, out int datCount) { datCount = 0; string strPath = RvFile.GetDatPhysicalPath(tDir.DatTreeFullName); if (!Directory.Exists(strPath)) { ReportError.Show($"Path: {strPath} Not Found."); return(false); } DirectoryInfo oDir = new DirectoryInfo(strPath); List <FileInfo> lFilesIn = new List <FileInfo>(); FileInfo[] oFilesIn = oDir.GetFiles("*.dat"); lFilesIn.AddRange(oFilesIn); oFilesIn = oDir.GetFiles("*.xml"); lFilesIn.AddRange(oFilesIn); datCount += lFilesIn.Count; foreach (FileInfo file in lFilesIn) { RvDat tDat = new RvDat(); tDat.SetData(RvDat.DatData.DatRootFullName, Path.Combine(tDir.DatTreeFullName, file.Name)); tDat.TimeStamp = file.LastWriteTime; // this works passing in the full DirectoryName of the Dat, because the rules // has a directory separator character added to the end of them, // so they match up to the directory name in this full Directory Name. string datRootFullName = tDat.GetData(RvDat.DatData.DatRootFullName); DatRule datRule = DatReader.FindDatRule(datRootFullName); tDat.MultiDatOverride = datRule.MultiDATDirOverride; tDat.UseDescriptionAsDirName = datRule.UseDescriptionAsDirName; tDat.SingleArchive = datRule.SingleArchive; tDat.SubDirType = datRule.SubDirType; tDir.DirDatAdd(tDat); } if (tDir.DirDatCount > 1) { for (int i = 0; i < tDir.DirDatCount; i++) { tDir.DirDat(i).MultiDatsInDirectory = true; } } DirectoryInfo[] oSubDir = oDir.GetDirectories(); foreach (DirectoryInfo t in oSubDir) { RvFile cDir = new RvFile(FileType.Dir) { Name = t.Name, DatStatus = DatStatus.InDatCollect }; int index = tDir.ChildAdd(cDir); RecursiveDatTree(cDir, out int retDatCount); datCount += retDatCount; if (retDatCount == 0) { tDir.ChildRemove(index); } } return(true); }
private static ReturnCode FixFilePreCheckFixFile(RvFile fixFile, out string errorMessage) { errorMessage = ""; string fileName = fixFile.FullName; // find all files in the DB with this name // there could be another file if: // there is a wrong file with the same name that can just be deleted // there is a wrong file with the same name that needs moved to ToSort // there is a wrong file with the same name that is needed to fix another file List <RvFile> testList = new List <RvFile>(); RvFile parent = fixFile.Parent; // start by finding the first file in the DB. (This should always work, as it will at least find the current file that CanBeFixed if (parent.ChildNameSearch(fixFile, out int index) != 0) { ReportError.Show("Logic error trying to find the file we are fixing " + fileName); return(ReturnCode.LogicError); } testList.Add(parent.Child(index++)); // now loop to see if there are any more files with the same name. (This is a case insensative compare) while (index < parent.ChildCount && DBHelper.CompareName(fixFile, parent.Child(index)) == 0) { testList.Add(parent.Child(index)); index++; } // if we found more that one file in the DB then we need to process the incorrect file first. if (testList.Count > 1) { foreach (RvFile testChild in testList) { if (testChild == fixFile) { continue; } if (testChild.DatStatus != DatStatus.NotInDat) { ReportError.Show("Trying to fix a file that already exists " + fileName); return(ReturnCode.LogicError); } RvFile testFile = testChild; if (!testFile.IsFile) { ReportError.Show("Did not find a file logic error while fixing duplicate named file. in FixFile"); return(ReturnCode.LogicError); } switch (testFile.RepStatus) { case RepStatus.Delete: { ReturnCode ret = FixFileDelete(testFile, out errorMessage); if (ret != ReturnCode.Good) { return(ret); } break; } case RepStatus.MoveToSort: { ReturnCode ret = FixFileMoveToSort(testFile, out errorMessage); if (ret != ReturnCode.Good) { return(ret); } break; } case RepStatus.MoveToCorrupt: { ReturnCode ret = FixFileMoveToCorrupt(testFile, out errorMessage); if (ret != ReturnCode.Good) { return(ret); } break; } case RepStatus.NeededForFix: case RepStatus.Rename: { // so now we have found the file with the same case insensative name and can rename it to something else to get it out of the way for now. // need to check that the .tmp filename does not already exists. File.SetAttributes(testChild.FullName, FileAttributes.Normal); File.Move(testChild.FullName, testChild.FullName + ".tmp"); if (!parent.FindChild(testChild, out index)) { ReportError.Show("Unknown file status in Matching File found of " + testFile.RepStatus); return(ReturnCode.LogicError); } parent.ChildRemove(index); testChild.Name = testChild.Name + ".tmp"; parent.ChildAdd(testChild); break; } default: { ReportError.Show("Unknown file status in Matching File found of " + testFile.RepStatus); return(ReturnCode.LogicError); } } } } else { // if there is only one file in the DB then it must be the current file that CanBeFixed if (testList[0] != fixFile) { ReportError.Show("Logic error trying to find the file we are fixing " + fileName + " DB found file does not match"); return(ReturnCode.LogicError); } } return(ReturnCode.Good); }
private static bool RecursiveDatTree(RvFile tDir, out int datCount) { datCount = 0; string strPath = RvFile.GetDatPhysicalPath(tDir.DatTreeFullName); if (!Directory.Exists(strPath)) { ReportError.Show("Path: " + strPath + " 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.DatRootFullName, Path.Combine(tDir.DatTreeFullName, file.Name)); 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.DatRootFullName, Path.Combine(tDir.DatTreeFullName, file.Name)); 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) { RvFile cDir = new RvFile(FileType.Dir) { Name = t.Name, DatStatus = DatStatus.InDatCollect }; int index = tDir.ChildAdd(cDir); RecursiveDatTree(cDir, out int retDatCount); datCount += retDatCount; if (retDatCount == 0) { tDir.ChildRemove(index); } } return(true); }
private static ReturnCode FixBase(RvFile child, bool thisSelected, List <RvFile> fileProcessQueue, ref int totalFixed, ref int reportedFixed, Stopwatch cacheSaveTimer) { // skip any files that have already been deleted if (child.RepStatus == RepStatus.Deleted) { return(ReturnCode.Good); } CheckDBWrite(cacheSaveTimer); string errorMessage = ""; ReturnCode returnCode = ReturnCode.LogicError; switch (child.FileType) { case FileType.Zip: case FileType.SevenZip: if (!thisSelected) { return(ReturnCode.Good); } if (!string.IsNullOrEmpty(child.FileName)) { string strDir = child.Parent.FullNameCase; Report.ReportProgress(new bgwShowFix(strDir, child.Name, null, null, "Rename", null, child.FileName, null)); File.Move(Path.Combine(strDir, child.FileName), Path.Combine(strDir, child.Name)); child.FileName = null; } returnCode = FixAZip.FixZip(child, fileProcessQueue, ref totalFixed, out errorMessage); break; case FileType.Dir: if (thisSelected) { if (!string.IsNullOrEmpty(child.FileName)) { string strDir = child.Parent.FullName; 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(child, thisSelected, fileProcessQueue, ref totalFixed, ref reportedFixed, cacheSaveTimer); return(returnCode); case FileType.File: if (!thisSelected) { return(ReturnCode.Good); } returnCode = FixAFile.FixFile(child, fileProcessQueue, ref totalFixed, out errorMessage); break; } switch (returnCode) { case ReturnCode.Good: // all good, move alone. break; case ReturnCode.Cancel: break; case ReturnCode.RescanNeeded: case ReturnCode.TreeStructureError: ReportError.Show(errorMessage); break; case ReturnCode.LogicError: ReportError.UnhandledExceptionHandler(errorMessage); break; case ReturnCode.FileSystemError: ReportError.Show(errorMessage); break; case ReturnCode.FindFixes: ReportError.Show("You Need to Find Fixes before Fixing. (Incorrect File Status's found for fixing.)"); break; case ReturnCode.SourceCheckSumMismatch: case ReturnCode.DestinationCheckSumMismatch: ReportError.Show(errorMessage); break; case ReturnCode.SourceDataStreamCorrupt: ReportError.Show(errorMessage); break; case ReturnCode.ToSortNotFound: ReportError.Show("Your Primary ToSort directory could not be found."); break; default: ReportError.UnhandledExceptionHandler("Unknown result type " + returnCode); break; } return(returnCode); }