private static ReturnCode FixFileMoveToSort(RvFile fixFile, out string errorMessage) { ReturnCode returnCode; returnCode = FixFileUtils.CreateToSortDirs(fixFile, out RvFile outDir, out string toSortFileName); if (returnCode != ReturnCode.Good) { errorMessage = ""; return(returnCode); } string fixFileFullName = fixFile.FullName; string toSortFullName = Path.Combine(outDir.FullName, toSortFileName); //create new tosort record // FileInfo toSortFile = new FileInfo(toSortFullName); RvFile toSortRom = new RvFile(FileType.File) { Name = toSortFileName, Size = fixFile.Size, CRC = fixFile.CRC, //TimeStamp = toSortFile.LastWriteTime, DatStatus = DatStatus.InToSort }; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "-->", outDir.FullName, "", fixFileFullName)); returnCode = FixFileUtils.MoveFile(fixFile, toSortRom, toSortFullName, out bool fileMoved, out errorMessage); if (returnCode != ReturnCode.Good) { return(returnCode); } if (!fileMoved) { returnCode = FixFileUtils.CopyFile(fixFile, null, toSortFullName, toSortRom, false, out errorMessage); if (returnCode != ReturnCode.Good) { return(returnCode); } string fixFilePath = fixFile.FullName; if (!File.SetAttributes(fixFilePath, FileAttributes.Normal)) { int error = Error.GetLastError(); Report.ReportProgress(new bgwShowError(fixFilePath, "Error Setting File Attributes to Normal. Before Delete Moving ToSort. Code " + error)); } File.Delete(fixFilePath); // here we just deleted a file so also delete it from the DB, // and recurse up deleting unnedded DIR's FixFileUtils.CheckDeleteFile(fixFile); } outDir.ChildAdd(toSortRom); return(ReturnCode.Good); }
private static ReturnCode FixFileCanBeFixed(RvFile fixFile, List <RvFile> fileProcessQueue, ref int totalFixed, out string errorMessage) { string fixFileFullName = fixFile.FullName; FixFileUtils.CheckCreateDirectories(fixFile.Parent); // check to see if there is already a file with the name of the fixFile, and move it out the way. ReturnCode rc = FixFilePreCheckFixFile(fixFile, out errorMessage); if (rc != ReturnCode.Good) { return(rc); } // now we can fix the file. ReturnCode returnCode; List <RvFile> lstFixRomTable = new List <RvFile>(); List <RvFile> family = fixFile.FileGroup.Files; foreach (RvFile file in family) { if (file.GotStatus == GotStatus.Got && DBHelper.CheckIfMissingFileCanBeFixedByGotFile(fixFile, file)) { lstFixRomTable.Add(file); } } if (DBHelper.IsZeroLengthFile(fixFile)) { RvFile fileIn = new RvFile(FileType.File); returnCode = FixFileUtils.CopyFile(fileIn, null, fixFile.FullName, fixFile, false, out errorMessage); if (returnCode != ReturnCode.Good) { errorMessage = fixFile.FullName + " " + fixFile.RepStatus + " " + returnCode + " : " + errorMessage; return(returnCode); } // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted. FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true); totalFixed++; return(ReturnCode.Good); } RvFile fixingFile = FindSourceFile.FindSourceToUseForFix(fixFile, lstFixRomTable); string fts = fixingFile.FullName; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "<--", Path.GetDirectoryName(fts), Path.GetFileName(fts), fixingFile.Name)); fixFile.FileTestFix(fixingFile); returnCode = FixFileUtils.MoveFile(fixingFile, fixFile, null, out bool fileMoved, out errorMessage); if (returnCode != ReturnCode.Good) { return(returnCode); } if (fileMoved) { // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted. FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true); totalFixed++; return(ReturnCode.Good); } returnCode = FixFileUtils.CopyFile(fixingFile, null, fixFile.FullName, fixFile, false, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; case ReturnCode.SourceDataStreamCorrupt: { Report.ReportProgress(new bgwShowFixError("CRC Error")); // the file we used for fix turns out to be corrupt // mark the source file as Corrupt fixingFile.GotStatus = GotStatus.Corrupt; return(returnCode); } default: Report.ReportProgress(new bgwShowFixError("Failed")); return(returnCode); } // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted. FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true); totalFixed++; return(ReturnCode.Good); }
private static ReturnCode FixFileMoveToCorrupt(RvFile fixFile, out string errorMessage) { string corruptDir = Path.Combine(DB.ToSort(), "Corrupt"); if (!Directory.Exists(corruptDir)) { Directory.CreateDirectory(corruptDir); } string fixFileFullName = fixFile.FullName; string toSortCorruptFullName = Path.Combine(corruptDir, fixFile.Name); string toSortCorruptFileName = fixFile.Name; int fileC = 0; while (File.Exists(toSortCorruptFullName)) { fileC++; toSortCorruptFileName = fixFile.Name + fileC; toSortCorruptFullName = Path.Combine(corruptDir, toSortCorruptFileName); } //create new tosort record // FileInfo toSortCorruptFile = new FileInfo(toSortCorruptFullName); RvFile toSortCorruptRom = new RvFile(FileType.File) { Name = toSortCorruptFileName, Size = fixFile.Size, CRC = fixFile.CRC, //TimeStamp = toSortFile.LastWriteTime, DatStatus = DatStatus.InToSort }; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "-->", "Corrupt", "", fixFile.Name)); ReturnCode returnCode = FixFileUtils.MoveFile(fixFile, toSortCorruptRom, toSortCorruptFullName, out bool fileMoved, out errorMessage); if (returnCode != ReturnCode.Good) { return(returnCode); } if (!fileMoved) { returnCode = FixFileUtils.CopyFile(fixFile, null, toSortCorruptFullName, toSortCorruptRom, false, out errorMessage); if (returnCode != ReturnCode.Good) { return(returnCode); } string fixFilePath = fixFile.FullName; if (!File.SetAttributes(fixFilePath, FileAttributes.Normal)) { int error = Error.GetLastError(); Report.ReportProgress(new bgwShowError(fixFilePath, "Error Setting File Attributes to Normal. Before Delete Moving ToSort. Code " + error)); } File.Delete(fixFilePath); // here we just deleted a file so also delete it from the DB, // and recurse up deleting unnedded DIR's FixFileUtils.CheckDeleteFile(fixFile); } RvFile toSort = DB.RvFileToSort(); RvFile rvCorruptDir = new RvFile(FileType.Dir) { Name = "Corrupt", DatStatus = DatStatus.InToSort }; int found = toSort.ChildNameSearch(rvCorruptDir, out int indexCorrupt); if (found != 0) { rvCorruptDir.GotStatus = GotStatus.Got; indexCorrupt = toSort.ChildAdd(rvCorruptDir); } toSort.Child(indexCorrupt).ChildAdd(toSortCorruptRom); errorMessage = ""; return(ReturnCode.Good); }