public static ReturnCode OpenTempFizZip(RvFile fixZip, out ICompress tempFixZip, out string errorMessage) { string strPath = fixZip.Parent.FullName; string tempZipFilename = Path.Combine(strPath, "__RomVault.tmp"); ReturnCode returnCode1 = OpenOutputZip(fixZip, tempZipFilename, out tempFixZip, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"CorrectZipFile: OutputOutput {tempZipFilename} return {returnCode1}"); return(returnCode1); } return(ReturnCode.Good); }
public static DatRule FindDatRule(string datName) { ReportError.LogOut($"FindDatRule: Dat Name is {datName}"); DatRule use = null; int longest = -1; int datNameLength = datName.Length; foreach (DatRule s in Settings.rvSettings.DatRules) { if (s.DirKey.Length < 8 || s.DirKey.Substring(0, 8) != "RomVault") { continue; } string DirKey = "DatRoot" + s.DirKey.Substring(8) + System.IO.Path.DirectorySeparatorChar; int dirKeyLen = DirKey.Length; if (dirKeyLen > datNameLength) { continue; } if (datName.Substring(0, dirKeyLen) != DirKey) { continue; } if (dirKeyLen < longest) { continue; } longest = dirKeyLen; use = s; } if (use == null) { ReportError.LogOut("Use is Null"); } else { ReportError.LogOut($"Using Rule for Dir {use.DirKey} {use.DirPath}"); } return(use); }
public static ReturnCode DoubleCheckDelete(RvFile fileDeleting, out string errorMessage) { errorMessage = ""; if (!Settings.rvSettings.DoubleCheckDelete) { return(ReturnCode.Good); } ReportError.LogOut("Double Check deleting file "); ReportError.LogOut(fileDeleting); if (DBHelper.IsZeroLengthFile(fileDeleting)) { return(ReturnCode.Good); } List <RvFile> lstFixRomTable = new List <RvFile>(); List <RvFile> family = fileDeleting.FileGroup.Files; foreach (RvFile file in family) { if (file.GotStatus == GotStatus.Got && DBHelper.CheckIfMissingFileCanBeFixedByGotFile(fileDeleting, file)) { lstFixRomTable.Add(file); } } RvFile fileToCheck = null; int i = 0; while (i < lstFixRomTable.Count && fileToCheck == null) { switch (lstFixRomTable[i].RepStatus) { case RepStatus.Delete: i++; break; case RepStatus.Unknown: case RepStatus.Correct: case RepStatus.InToSort: case RepStatus.Rename: case RepStatus.NeededForFix: case RepStatus.MoveToSort: case RepStatus.Ignore: fileToCheck = lstFixRomTable[i]; break; default: ReportError.LogOut("Double Check Delete Error Unknown " + lstFixRomTable[i].FullName + " " + lstFixRomTable[i].RepStatus); ReportError.UnhandledExceptionHandler("Unknown double check delete status " + lstFixRomTable[i].RepStatus); break; } } //ReportError.LogOut("Found Files when double check deleting"); //foreach (RvFile t in lstFixRomTable) // ReportError.LogOut(t); if (fileToCheck == null) { ReportError.UnhandledExceptionHandler("Double Check Delete could not find the correct file. (" + fileDeleting.FullName + ")"); //this line of code never gets called because the above line terminates the program. return(ReturnCode.LogicError); } //if it is a file then // check it exists and the filestamp matches //if it is a ZipFile then // check the parent zip exists and the filestamp matches switch (fileToCheck.FileType) { case FileType.ZipFile: case FileType.SevenZipFile: { string fullPathCheckDelete = fileToCheck.Parent.FullNameCase; if (!File.Exists(fullPathCheckDelete)) { errorMessage = "Deleting " + fileDeleting.FullName + " Correct file not found. Resan for " + fullPathCheckDelete; return(ReturnCode.RescanNeeded); } FileInfo fi = new FileInfo(fullPathCheckDelete); if (fi.LastWriteTime != fileToCheck.Parent.FileModTimeStamp) { errorMessage = "Deleting " + fileDeleting.FullName + " Correct file timestamp not found. Resan for " + fileToCheck.FullName; return(ReturnCode.RescanNeeded); } break; } case FileType.File: { string fullPathCheckDelete = fileToCheck.FullNameCase; if (!File.Exists(fullPathCheckDelete)) { errorMessage = "Deleting " + fileDeleting.FullName + " Correct file not found. Resan for " + fullPathCheckDelete; return(ReturnCode.RescanNeeded); } FileInfo fi = new FileInfo(fullPathCheckDelete); if (fi.LastWriteTime != fileToCheck.FileModTimeStamp) { errorMessage = "Deleting " + fileDeleting.FullName + " Correct file timestamp not found. Resan for " + fileToCheck.FullName; return(ReturnCode.RescanNeeded); } break; } default: ReportError.UnhandledExceptionHandler("Unknown double check delete status " + fileToCheck.RepStatus); break; } return(ReturnCode.Good); }
private static void CHDErrorHandler(object sendingProcess, DataReceivedEventArgs outLine) { // Collect the process command output. if (String.IsNullOrEmpty(outLine.Data)) { return; } // We can get fed multiple lines worth of data because of \r line feeds string[] sLines = outLine.Data.Split(new string[] { "\r" }, StringSplitOptions.None); foreach (string sLine in sLines) { if (string.IsNullOrEmpty(sLine)) { continue; } ReportError.LogOut("CHDError: " + sLine); _bgw.ReportProgress(0, new bgwText3(sLine)); if (_resultType != CHDManCheck.Unset) { if (_errorLines > 0) { _errorLines -= 1; _result += "\r\n" + sLine; } } else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^No verification to be done; CHD has (uncompressed|no checksum)")) { _result = sLine; _resultType = CHDManCheck.Corrupt; } else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error (opening|reading) CHD file.*")) { _result = sLine; _resultType = CHDManCheck.Corrupt; } else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error opening parent CHD file .*:")) { _result = sLine; _resultType = CHDManCheck.Corrupt; } else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error: (Raw|Overall) SHA1 in header")) { _result = sLine; _resultType = CHDManCheck.Corrupt; } else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Out of memory")) { _result = sLine; _resultType = CHDManCheck.Corrupt; } // Verifying messages are a non-error else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"Verifying, \d+\.\d+\% complete\.\.\.")) { } else { _result = "Unknown message : " + sLine; _resultType = CHDManCheck.CHDUnknownError; } } }
public static CHDManCheck ChdmanCheck(string filename, BackgroundWorker bgw, out string result) { _bgw = bgw; _result = ""; _resultType = CHDManCheck.Unset; string chdExe = "chdman.exe"; if (Settings.IsUnix) { chdExe = "chdman"; } string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, chdExe); if (!File.Exists(chdPath)) { result = chdExe + " Not Found."; return(CHDManCheck.ChdmanNotFound); } if (!IO.File.Exists(filename)) { result = filename + " Not Found."; return(CHDManCheck.CHDNotFound); } string shortName = NameFix.GetShortPath(filename); using (Process exeProcess = new Process()) { exeProcess.StartInfo.FileName = chdPath; ReportError.LogOut("CHD: FileName :" + exeProcess.StartInfo.FileName); exeProcess.StartInfo.Arguments = "verify -i \"" + shortName + "\""; ReportError.LogOut("CHD: Arguments :" + exeProcess.StartInfo.Arguments); // Set UseShellExecute to false for redirection. exeProcess.StartInfo.UseShellExecute = false; // Stops the Command window from popping up. exeProcess.StartInfo.CreateNoWindow = true; // Redirect the standard output. // This stream is read asynchronously using an event handler. exeProcess.StartInfo.RedirectStandardOutput = true; exeProcess.StartInfo.RedirectStandardError = true; // Set our event handler to asynchronously read the process output. exeProcess.OutputDataReceived += CHDOutputHandler; exeProcess.ErrorDataReceived += CHDErrorHandler; _outputLineCount = 0; _errorLines = 0; ReportError.LogOut("CHD: Scanning Starting"); exeProcess.Start(); // Start the asynchronous read of the process output stream. exeProcess.BeginOutputReadLine(); exeProcess.BeginErrorReadLine(); // Wait for the process finish. exeProcess.WaitForExit(); ReportError.LogOut("CHD: Scanning Finished"); } result = _result; if (_resultType == CHDManCheck.Unset) { _resultType = CHDManCheck.Good; } _bgw.ReportProgress(0, new bgwText3("")); ReportError.LogOut("CHD: returning result " + _resultType + " " + result); return(_resultType); }
public static void CheckFilesUsedForFix(List <RvFile> lstFixRomTable, List <RvFile> fileProcessQueue, bool checkRename) { //Check to see if the files used for fix, can now be set to delete List <RvFile> parentCheckList = new List <RvFile>(); foreach (RvFile fixRom in lstFixRomTable) { //check NeededForFix files, and Rename files is checkRename==true if (fixRom.RepStatus != RepStatus.NeededForFix && (!checkRename || fixRom.RepStatus != RepStatus.Rename)) { continue; } //if this dir is locked in the tree, just set the fixRom back to InToSort or Unknown if (FindFixesListCheck.treeType(fixRom) == RvTreeRow.TreeSelect.Locked) { fixRom.RepStatus = fixRom.IsInToSort ? RepStatus.InToSort : RepStatus.Unknown; continue; } // need to add an improvement here for 7z // if we just used a file to fix a 7z, then right now that file will be marked to be deleted. // I need to check if the file is needed to fix any other 7z files, because right now // if we do delete the file after the first use, then when we fix the second 7z file we // have to go and extract it again from the first 7z file that we just fixed. // It would be much better to just not delete the file if there are any other 7z files needing // it still for a fix. // now set the fixRom to delete, as this fixRom has now been moved to its correct location. fixRom.RepStatus = RepStatus.Delete; ReportError.LogOut("Setting File Status to Delete:"); ReportError.LogOut(fixRom); switch (fixRom.FileType) { // if this is a read fixRom (not zipped) and it has just been set to delete status, // then add it to fileProcessQueue to that it is next to be deleted. case FileType.File: if (fixRom.RepStatus == RepStatus.Delete && !fileProcessQueue.Contains(fixRom)) { fileProcessQueue.Add(fixRom); } break; case FileType.ZipFile: case FileType.SevenZipFile: // if this is a compressed fixRom and adds its parent to the parentCheckList to see if the parent can now be reprocessed RvFile checkFile = fixRom.Parent; if (!parentCheckList.Contains(checkFile)) { parentCheckList.Add(checkFile); } break; default: ReportError.SendAndShow("Unknown repair fixRom type recheck."); break; } } foreach (RvFile checkFile in parentCheckList) { // if this fixRom is already in the fileProcessQueue then skip if (fileProcessQueue.Contains(checkFile)) { continue; } // the parent set has Delete status and no NeededForFix or Rename // then is can be processed next to remove the delete status files from it, as the deleted files have now // been moved to where they should be. bool hasDelete = false; bool hasNeededForFix = false; for (int i = 0; i < checkFile.ChildCount; i++) { RvFile f = checkFile.Child(i); if (f.RepStatus == RepStatus.Delete) { hasDelete = true; } else if (f.RepStatus == RepStatus.NeededForFix || f.RepStatus == RepStatus.Rename) { hasNeededForFix = true; break; } } // if nothing needed deleted or zip still have NeededForFix or Rename then skip it. if (!hasDelete || hasNeededForFix) { continue; } // else add the zip file to the reprocess queue to get cleaned up next Debug.WriteLine(checkFile.FullName + " adding to process list."); fileProcessQueue.Add(checkFile); } }
private static void CHDErrorHandler(object sendingProcess, DataReceivedEventArgs outLine) { // Collect the process command output. if (String.IsNullOrEmpty(outLine.Data)) { return; } string sOut = outLine.Data; ReportError.LogOut("CHDError: " + sOut); _bgw.ReportProgress(0, new bgwText3(sOut)); if (_resultType != CHDManCheck.Unset) { if (_errorLines > 0) { _errorLines -= 1; _result += "\r\n" + sOut; } return; } if (sOut.Length > 44) { if (sOut.Substring(0, 23) == "Error reading CHD file " && sOut.Substring(sOut.Length - 21, 21) == ": decompression error") { _result = sOut; _resultType = CHDManCheck.Corrupt; return; } } if (sOut.Length > 35) { if (sOut.Substring(0, 23) == "Error opening CHD file " && sOut.Substring(sOut.Length - 21, 21) == ": decompression error") { _result = sOut; _resultType = CHDManCheck.Corrupt; return; } } if (sOut.Length > 35) { if (sOut.Substring(0, 23) == "Error opening CHD file " && sOut.Substring(sOut.Length - 12, 12) == ": read error") { _result = sOut; _resultType = CHDManCheck.Corrupt; return; } } if (sOut.Length > 25) { if (sOut.Substring(0, 25) == "Error: Raw SHA1 in header") { _result = sOut; _errorLines = 1; _resultType = CHDManCheck.Corrupt; return; } } if (sOut.Length == 13) { if (sOut == "Out of memory") { _result = sOut; _resultType = CHDManCheck.Corrupt; return; } } // check for Verifying message if (sOut.Length >= 24) { if (sOut.Substring(0, 11) == "Verifying, " && sOut.Substring(sOut.Length - 13, 13) == " complete... ") { //_resultType = CHDManCheck.Good; return; } } ReportError.SendErrorMessage("CHDErrorHandler returned =" + sOut); _result = "Unknown message : " + sOut; _resultType = CHDManCheck.CHDUnknownError; }
public static void MoveToCorrupt(RvFile fixZip, RvFile fixZippedFile, ref RvFile toSortCorruptGame, ref ICompress toSortCorruptOut, int iRom) { if (!((fixZippedFile.DatStatus == DatStatus.InDatCollect || fixZippedFile.DatStatus == DatStatus.NotInDat) && fixZippedFile.GotStatus == GotStatus.Corrupt)) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("Moving File to Corrupt"); ReportError.LogOut(fixZippedFile); if (fixZippedFile.FileType == FileType.SevenZipFile) { fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted return; } string toSortFullName; if (toSortCorruptGame == null) { string corruptDir = Path.Combine(DB.ToSort(), "Corrupt"); if (!Directory.Exists(corruptDir)) { Directory.CreateDirectory(corruptDir); } toSortFullName = Path.Combine(corruptDir, fixZip.Name); string toSortFileName = fixZip.Name; int fileC = 0; while (File.Exists(toSortFullName)) { fileC++; string fName = Path.GetFileNameWithoutExtension(fixZip.Name); string fExt = Path.GetExtension(fixZip.Name); toSortFullName = Path.Combine(corruptDir, fName + fileC + fExt); toSortFileName = fixZip.Name + fileC; } toSortCorruptGame = new RvFile(FileType.Zip) { Name = toSortFileName, DatStatus = DatStatus.InToSort, GotStatus = GotStatus.Got }; } else { string corruptDir = Path.Combine(DB.ToSort(), "Corrupt"); toSortFullName = Path.Combine(corruptDir, toSortCorruptGame.Name); } RvFile toSortCorruptRom = new RvFile(FileType.ZipFile) { Name = fixZippedFile.Name, Size = fixZippedFile.Size, CRC = fixZippedFile.CRC }; toSortCorruptRom.SetStatus(DatStatus.InToSort, GotStatus.Corrupt); toSortCorruptGame.ChildAdd(toSortCorruptRom); if (toSortCorruptOut == null) { ReturnCode returnCode1 = OpenOutputZip(fixZip, toSortFullName, out toSortCorruptOut, out string errorMessage1); if (returnCode1 != ReturnCode.Good) { throw new FixAZip.ZipFileException(returnCode1, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode1 + Environment.NewLine + errorMessage1); } } string fixZipFullName = fixZip.TreeFullName; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, "Raw-->", "Corrupt", Path.GetFileName(toSortFullName), fixZippedFile.Name)); ReturnCode returnCode = FixFileUtils.CopyFile(fixZip.Child(iRom), toSortCorruptOut, null, toSortCorruptRom, true, out string errorMessage); 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: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted }
public static ReturnCode MovetoSort(RvFile fixZip, RvFile fixZippedFile, ref RvFile toSortGame, ref ICompress toSortZipOut, int iRom) { if (!(fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got)) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("MovetoSort:"); ReportError.LogOut(fixZippedFile); // move the rom out to the To Sort Directory string toSortFullName; if (toSortGame == null) { ReturnCode retCode = FixFileUtils.CreateToSortDirs(fixZip, out RvFile outDir, out string toSortFileName); if (retCode != ReturnCode.Good) { return(retCode); } toSortGame = new RvFile(fixZip.FileType) { Parent = outDir, Name = toSortFileName, DatStatus = DatStatus.InToSort, GotStatus = GotStatus.Got }; toSortFullName = Path.Combine(outDir.FullName, toSortGame.Name); } else { toSortFullName = toSortZipOut.ZipFilename; } // this needs header / alt info added. RvFile toSortRom = new RvFile(fixZippedFile.FileType) { Name = fixZippedFile.Name, Size = fixZippedFile.Size, CRC = fixZippedFile.CRC, SHA1 = fixZippedFile.SHA1, MD5 = fixZippedFile.MD5, HeaderFileType = fixZippedFile.HeaderFileType, AltSize = fixZippedFile.AltSize, AltCRC = fixZippedFile.AltCRC, AltSHA1 = fixZippedFile.AltSHA1, AltMD5 = fixZippedFile.AltMD5, FileGroup = fixZippedFile.FileGroup }; toSortRom.SetStatus(DatStatus.InToSort, GotStatus.Got); toSortRom.FileStatusSet( FileStatus.HeaderFileTypeFromHeader | FileStatus.SizeFromHeader | FileStatus.SizeVerified | FileStatus.CRCFromHeader | FileStatus.CRCVerified | FileStatus.SHA1FromHeader | FileStatus.SHA1Verified | FileStatus.MD5FromHeader | FileStatus.MD5Verified | FileStatus.AltSizeFromHeader | FileStatus.AltSizeVerified | FileStatus.AltCRCFromHeader | FileStatus.AltCRCVerified | FileStatus.AltSHA1FromHeader | FileStatus.AltSHA1Verified | FileStatus.AltMD5FromHeader | FileStatus.AltMD5Verified , fixZippedFile); toSortGame.ChildAdd(toSortRom); ReturnCode returnCode; string errorMessage; if (toSortZipOut == null) { returnCode = OpenOutputZip(fixZip, toSortFullName, out toSortZipOut, out errorMessage); if (returnCode != ReturnCode.Good) { throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } } string fixZipFullName = fixZip.TreeFullName; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, "Raw-->", Path.GetDirectoryName(toSortFullName), Path.GetFileName(toSortFullName), toSortRom.Name)); returnCode = FixFileUtils.CopyFile(fixZip.Child(iRom), toSortZipOut, null, toSortRom, true, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted return(ReturnCode.Good); }
/// <summary> /// Fixed a missing file inside a .ZIP file. /// </summary> /// <param name="fixZip">The RvFile of the actual .ZIP file that is being fixed.</param> /// <param name="fixZippedFile">A temp copy of the RvFile record of the actual compressed file inside the fixZip .zip that is about to be fixed.</param> /// <param name="tempFixZip">Is the new output archive file that is being created to fix this zip, that will become the new zip once done</param> /// <param name="fileProcessQueue"></param> /// <param name="totalFixed"></param> /// <param name="errorMessage"></param> /// <returns></returns> public static ReturnCode CanBeFixed(RvFile fixZip, RvFile fixZippedFile, ref ICompress tempFixZip, List <RvFile> fileProcessQueue, ref int totalFixed, out string errorMessage) { if (!(fixZippedFile.DatStatus == DatStatus.InDatCollect && (fixZippedFile.GotStatus == GotStatus.NotGot || fixZippedFile.GotStatus == GotStatus.Corrupt))) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("CanBeFixed:"); ReportError.LogOut(fixZippedFile); if (tempFixZip == null) { string strPath = fixZip.Parent.FullName; string tempZipFilename = Path.Combine(strPath, "__RomVault.tmp"); ReturnCode returnCode1 = OpenOutputZip(fixZip, tempZipFilename, out tempFixZip, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"CanBeFixed: OutputOutput {tempZipFilename} return {returnCode1}"); return(returnCode1); } } List <RvFile> lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); ReportError.LogOut("CanBeFixed: picking from"); ReportError.ReportList(lstFixRomTable); if (DBHelper.IsZeroLengthFile(fixZippedFile)) { RvFile fileIn = new RvFile(FileType.ZipFile) { Size = 0 }; ReturnCode returnCode = FixFileUtils.CopyFile(fileIn, tempFixZip, null, fixZippedFile, false, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + " : " + errorMessage); } //Check to see if the files used for fix, can now be set to delete FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, false); totalFixed++; return(ReturnCode.Good); } if (lstFixRomTable.Count > 0) { RvFile fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); if (fileIn.FileType == FileType.SevenZipFile) { ReturnCode returnCode1 = Decompress7ZipFile.DecompressSource7ZipFile(fileIn.Parent, false, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"DecompressSource7Zip: OutputOutput {fixZip.FileName} return {returnCode1}"); return(returnCode1); } lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); } ReportError.LogOut("CanBeFixed: Copying from"); ReportError.LogOut(fileIn); GetSourceDir(fileIn, out string sourceDir, out string sourceFile); string fixZipFullName = fixZip.TreeFullName; bool rawCopy = FixFileUtils.TestRawCopy(fileIn, fixZippedFile, false); Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, rawCopy ? "<--Raw" : "<--Compress", sourceDir, sourceFile, fileIn.Name)); fixZippedFile.FileTestFix(fileIn); ReturnCode returnCode = FixFileUtils.CopyFile(fileIn, tempFixZip, null, fixZippedFile, false, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply so continue; break; case ReturnCode.RescanNeeded: ReportError.LogOut($"CanBeFixed: RescanNeeded"); return(returnCode); case ReturnCode.SourceDataStreamCorrupt: { ReportError.LogOut($"CanBeFixed: Source Data Stream Corrupt / CRC Error"); Report.ReportProgress(new bgwShowFixError("CRC Error")); fileIn.GotStatus = GotStatus.Corrupt; return(returnCode); } case ReturnCode.SourceCheckSumMismatch: { ReportError.LogOut($"CanBeFixed: Source Checksum Mismatch / Fix file CRC was not as expected"); Report.ReportProgress(new bgwShowFixError("Fix file CRC was not as expected")); return(returnCode); } case ReturnCode.DestinationCheckSumMismatch: { ReportError.LogOut($"CanBeFixed: Destination Checksum Mismatch / Destination file CRC was not as expected"); Report.ReportProgress(new bgwShowFixError("Destination file CRC was not as expected")); return(returnCode); } default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } //Check to see if the files used for fix, can now be set to delete FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, false); totalFixed++; } else // thought we could fix it, turns out we cannot { fixZippedFile.GotStatus = GotStatus.NotGot; } errorMessage = ""; return(ReturnCode.Good); }
public static ReturnCode CorrectZipFile(RvFile fixZip, RvFile fixZippedFile, ref ICompress tempFixZip, int iRom, List <RvFile> fileProcessQueue, out string errorMessage) { if (! ( fixZippedFile.DatStatus == DatStatus.InDatCollect && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InDatMerged && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Corrupt ) ) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("CorrectZipFile:"); ReportError.LogOut(fixZippedFile); if (fixZippedFile.GotStatus == GotStatus.Corrupt && fixZippedFile.FileType == FileType.SevenZipFile) { fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted errorMessage = ""; return(ReturnCode.Good); } if (tempFixZip == null) { string strPath = fixZip.Parent.FullName; string tempZipFilename = Path.Combine(strPath, "__RomVault.tmp"); ReturnCode returnCode1 = OpenOutputZip(fixZip, tempZipFilename, out tempFixZip, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"CorrectZipFile: OutputOutput {tempZipFilename} return {returnCode1}"); return(returnCode1); } } bool rawcopy = fixZippedFile.RepStatus == RepStatus.InToSort || fixZippedFile.RepStatus == RepStatus.Corrupt; RvFile fileIn = fixZip.Child(iRom); List <RvFile> lstFixRomTable = null; if (fileIn.FileType == FileType.SevenZipFile && fileIn.Size > 0) { lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); ReportError.LogOut("CorrectZipFile: picking from"); ReportError.ReportList(lstFixRomTable); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); if (fileIn.FileType == FileType.SevenZipFile) { ReturnCode returnCode1 = Decompress7ZipFile.DecompressSource7ZipFile(fixZip, true, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"DecompressSource7Zip: OutputOutput {fixZip.FileName} return {returnCode1}"); return(returnCode1); } lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); } } ReportError.LogOut("Copying from"); ReportError.LogOut(fileIn); GetSourceDir(fileIn, out string sourceDir, out string sourceFile); if (Settings.rvSettings.DetailedFixReporting) { string fixZipFullName = fixZip.TreeFullName; bool rawCopy = FixFileUtils.TestRawCopy(fileIn, fixZippedFile, rawcopy); Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, rawCopy ? "<<--Raw" : "<<--Compress", sourceDir, sourceFile, fileIn.Name)); } RepStatus originalStatus = fixZippedFile.RepStatus; ReturnCode returnCode = FixFileUtils.CopyFile(fileIn, tempFixZip, null, fixZippedFile, rawcopy, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; if (originalStatus == RepStatus.NeededForFix) { fixZippedFile.RepStatus = RepStatus.NeededForFix; } break; case ReturnCode.SourceDataStreamCorrupt: { ReportError.LogOut($"CorrectZipFile: Source Data Stream Corrupt / CRC Error"); Report.ReportProgress(new bgwShowFixError("CRC Error")); RvFile tFile = fixZip.Child(iRom); tFile.GotStatus = GotStatus.Corrupt; break; } case ReturnCode.SourceCheckSumMismatch: { ReportError.LogOut($"CorrectZipFile: Source Checksum Mismatch / Fix file CRC was not as expected"); Report.ReportProgress(new bgwShowFixError("Fix file CRC was not as expected")); break; } default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + " : " + errorMessage); } // This should not be done here, as you land up marking files that are being // copied that are still set to needed for fix to delete status //Check to see if the files used for fix, can now be set to delete //if (lstFixRomTable != null) // FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, false); return(returnCode); }
public static RvFile ReadInDatFile(RvDat datFile, ThreadWorker thWrk, out string extraDirName) { try { _thWrk = thWrk; extraDirName = null; string datRootFullName = datFile.GetData(RvDat.DatData.DatRootFullName); string fullPath = RvFile.GetDatPhysicalPath(datRootFullName); Debug.WriteLine("Reading Dat " + fullPath); DatRead.ReadDat(fullPath, ReadError, out DatHeader dh); if (dh == null) { return(null); } string dirNameRule = Path.GetDirectoryName(datRootFullName) + Path.DirSeparatorChar; if ( !datFile.MultiDatOverride && dh.Dir != "noautodir" && (datFile.MultiDatsInDirectory || !string.IsNullOrEmpty(dh.RootDir)) ) { // if we are auto adding extra directories then create a new directory. extraDirName = ""; if (string.IsNullOrEmpty(extraDirName) && datFile.UseDescriptionAsDirName && !string.IsNullOrWhiteSpace(dh.Description)) { extraDirName = dh.Description; } if (string.IsNullOrEmpty(extraDirName)) { extraDirName = dh.RootDir; } if (string.IsNullOrEmpty(extraDirName)) { extraDirName = dh.Name; } if (string.IsNullOrEmpty(extraDirName)) { extraDirName = Path.GetFileNameWithoutExtension(fullPath); } dirNameRule += VarFix.CleanFileName(extraDirName) + Path.DirSeparatorChar; } ReportError.LogOut($"DatRule {dirNameRule}"); DatRule datRule = FindDatRule(dirNameRule); DatClean.CleanFilenames(dh.BaseDir); switch (datRule.Filter) { case FilterType.CHDsOnly: DatClean.RemoveNonCHD(dh.BaseDir); break; case FilterType.RomsOnly: DatClean.RemoveCHD(dh.BaseDir); break; } DatClean.RemoveNoDumps(dh.BaseDir); SetMergeType(datRule, dh); if (datRule.SingleArchive) { DatClean.MakeDatSingleLevel(dh, datRule.UseDescriptionAsDirName, datRule.SubDirType, isFile(datRule, dh)); } DatClean.RemoveUnNeededDirectories(dh.BaseDir); SetCompressionMethod(datRule, dh); // This sorts the files into the required dir order for the set compression type. (And also sets '\' characters to '/' in zip files.) DatClean.DirectoryExpand(dh.BaseDir); // this works because we only expand files, so the order inside the zip / 7z does not matter. DatClean.RemoveEmptyDirectories(dh.BaseDir); DatClean.CleanFilenamesFixDupes(dh.BaseDir); // you may get repeat filenames inside Zip's / 7Z's and they may not be sorted to find them by now. RvFile newDir = ExternalDatConverter.ConvertFromExternalDat(dh, datFile); return(newDir); } catch (Exception e) { string datRootFullName = datFile?.GetData(RvDat.DatData.DatRootFullName); Console.WriteLine(e); throw new Exception("Error is DAT " + datRootFullName + " " + e.Message); } }
/// <summary> /// Fixed a missing file inside a .ZIP file. /// </summary> /// <param name="fixZip">The RvFile of the actual .ZIP file that is being fixed.</param> /// <param name="fixZippedFile">A temp copy of the RvFile record of the actual compressed file inside the fixZip .zip that is about to be fixed.</param> /// <param name="tempFixZip">Is the new output archive file that is being created to fix this zip, that will become the new zip once done</param> /// <param name="iRom"></param> /// <param name="filesUserForFix"></param> /// <param name="errorMessage"></param> /// <returns></returns> public static ReturnCode CorrectZipFile(RvFile fixZip, RvFile fixZippedFile, ref ICompress tempFixZip, int iRom, Dictionary <string, RvFile> filesUserForFix, out string errorMessage) { if (!( fixZippedFile.DatStatus == DatStatus.InDatCollect && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InDatMerged && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Corrupt)) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("CorrectZipFile:"); ReportError.LogOut(fixZippedFile); if (fixZippedFile.GotStatus == GotStatus.Corrupt && fixZippedFile.FileType == FileType.SevenZipFile) { fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted errorMessage = ""; return(ReturnCode.Good); } if (tempFixZip == null) { ReturnCode ret1 = FixAZipFunctions.OpenTempFizZip(fixZip, out tempFixZip, out errorMessage); if (ret1 != ReturnCode.Good) { return(ret1); } } RvFile fileIn = fixZip.Child(iRom); List <RvFile> lstFixRomTable = null; if (fileIn.FileType == FileType.SevenZipFile && fileIn.Size > 0) { lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); ReportError.LogOut("CorrectZipFile: picking from"); ReportError.ReportList(lstFixRomTable); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); if (fileIn.FileType == FileType.SevenZipFile) { ReturnCode returnCode1 = Decompress7ZipFile.DecompressSource7ZipFile(fixZip, true, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"DecompressSource7Zip: OutputOutput {fixZip.FileName} return {returnCode1}"); return(returnCode1); } lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); } } ReportError.LogOut("Copying from"); ReportError.LogOut(fileIn); FixAZipFunctions.GetSourceDir(fileIn, out string sourceDir, out string sourceFile); bool rawCopyForce = fixZippedFile.RepStatus == RepStatus.InToSort || fixZippedFile.RepStatus == RepStatus.Corrupt; if (Settings.rvSettings.DetailedFixReporting) { string fixZipFullName = fixZip.TreeFullName; bool rawCopy = FixFileUtils.TestRawCopy(fileIn, fixZippedFile, rawCopyForce); Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, rawCopy ? "<<--Raw" : "<<--Compress", sourceDir, sourceFile, fileIn.Name)); } RepStatus originalStatus = fixZippedFile.RepStatus; ReturnCode returnCode = FixFileUtils.CopyFile(fileIn, tempFixZip, null, fixZippedFile, rawCopyForce, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; if (originalStatus == RepStatus.NeededForFix) { fixZippedFile.RepStatus = RepStatus.NeededForFix; } break; case ReturnCode.SourceDataStreamCorrupt: { ReportError.LogOut($"CorrectZipFile: Source Data Stream Corrupt / CRC Error"); Report.ReportProgress(new bgwShowFixError("CRC Error")); RvFile tFile = fixZip.Child(iRom); tFile.GotStatus = GotStatus.Corrupt; break; } case ReturnCode.SourceCheckSumMismatch: { ReportError.LogOut($"CorrectZipFile: Source Checksum Mismatch / Fix file CRC was not as expected"); Report.ReportProgress(new bgwShowFixError("Fix file CRC was not as expected")); break; } case ReturnCode.FileSystemError: { ReportError.LogOut($"CorrectZipFile: Source File Error {errorMessage}"); Report.ReportProgress(new bgwShowFixError($"CorrectZipFile: Source File Error {errorMessage}")); return(returnCode); } case ReturnCode.Cancel: return(returnCode); default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + " : " + errorMessage); } if (lstFixRomTable != null) { foreach (RvFile f in lstFixRomTable) { string fn = f.TreeFullName; if (!filesUserForFix.ContainsKey(fn)) { filesUserForFix.Add(fn, f); } } } return(returnCode); }
public static ReturnCode CorrectZipFile(RvFile fixZip, RvFile fixZippedFile, ref ICompress tempFixZip, int iRom, out string errorMessage) { if (! ( fixZippedFile.DatStatus == DatStatus.InDatCollect && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InDatMerged && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Corrupt ) ) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("CorrectZipFile:"); ReportError.LogOut(fixZippedFile); if (tempFixZip == null) { string strPath = fixZip.Parent.FullName; string tempZipFilename = Path.Combine(strPath, "__RomVault.tmp"); ReturnCode returnCode1 = OpenOutputZip(fixZip, tempZipFilename, out tempFixZip, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"CorrectZipFile: OutputOutput {tempZipFilename} return {returnCode1}"); return(returnCode1); } } bool rawcopy = fixZippedFile.RepStatus == RepStatus.InToSort || fixZippedFile.RepStatus == RepStatus.Corrupt; RvFile FileIn = fixZip.Child(iRom); if (Settings.rvSettings.UseFileSelection) { if (FileIn.FileType == FileType.SevenZipFile) { List <RvFile> fixFiles = FindSourceFile.GetFixFileList(fixZippedFile); ReportError.LogOut("CorrectZipFile: picking from"); ReportError.ReportList(fixFiles); FileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, fixFiles); if (FileIn.FileType == FileType.SevenZipFile) { ReturnCode returnCode1 = Decompress7ZipFile.DecompressSource7ZipFile(fixZip, true, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"DecompressSource7Zip: OutputOutput {fixZip.FileName} return {returnCode1}"); return(returnCode1); } fixFiles = FindSourceFile.GetFixFileList(fixZippedFile); FileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, fixFiles); } } } ReportError.LogOut("Copying from"); ReportError.LogOut(FileIn); RepStatus originalStatus = fixZippedFile.RepStatus; ReturnCode returnCode = FixFileUtils.CopyFile(FileIn, tempFixZip, null, fixZippedFile, rawcopy, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; if (originalStatus == RepStatus.NeededForFix) { fixZippedFile.RepStatus = RepStatus.NeededForFix; } break; case ReturnCode.SourceDataStreamCorrupt: { ReportError.LogOut($"CorrectZipFile: Source Data Stream Corrupt / CRC Error"); Report.ReportProgress(new bgwShowFixError("CRC Error")); RvFile tFile = fixZip.Child(iRom); tFile.GotStatus = GotStatus.Corrupt; break; } case ReturnCode.SourceCheckSumMismatch: { ReportError.LogOut($"CorrectZipFile: Source Checksum Mismatch / Fix file CRC was not as expected"); Report.ReportProgress(new bgwShowFixError("Fix file CRC was not as expected")); break; } default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + " : " + errorMessage); } return(returnCode); }
public static ReturnCode FixZip(RvFile fixZip, List <RvFile> fileProcessQueue, ref int totalFixed, out string errorMessage) { errorMessage = ""; //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.rvSettings.FixLevel == EFixLevel.TrrntZipLevel1 || Settings.rvSettings.FixLevel == EFixLevel.TrrntZipLevel2 || Settings.rvSettings.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 && !fixZip.DirStatus.HasFixable()) { ReturnCode moveReturnCode = FixAZipFunctions.MoveZipToCorrupt(fixZip, out errorMessage); if (moveReturnCode != ReturnCode.Good) { return(moveReturnCode); } } // 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) { // rv7Zip format is not finalized yet so do not use if (!Settings.rvSettings.ConvertToRV7Z && (fixZip.FileType == FileType.SevenZip)) //if (fixZip.FileType == FileType.SevenZip) { needsTrrntzipped = false; } // 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); } if (!fixZip.DirStatus.HasFixable() && !needsTrrntzipped) { return(ReturnCode.Good); } string fixZipFullName = fixZip.TreeFullName; if (!fixZip.DirStatus.HasFixable() && needsTrrntzipped) { Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), "", 0, "TrrntZipping", "", "", "")); } FixFileUtils.CheckCreateDirectories(fixZip.Parent); string filename = fixZip.FullName; if (fixZip.GotStatus == GotStatus.NotGot) { if (File.Exists(filename)) { errorMessage = "Unexpected file found in directory. Rescan needed.\n" + filename; return(ReturnCode.RescanNeeded); } } 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(fixZip.Child(intLoop)); } ReportError.LogOut(""); ReturnCode returnCode = ReturnCode.Good; RepStatus fileRepStatus = RepStatus.UnSet; ICompress tempFixZip = null; ICompress toSortCorruptOut = null; ICompress toSortZipOut = null; try { RvFile toSortGame = null; RvFile toSortCorruptGame = null; List <RvFile> fixZipTemp = new List <RvFile>(); FileType fixFileType = fixZip.FileType; for (int iRom = 0; iRom < fixZip.ChildCount; iRom++) { RvFile fixZippedFile = new RvFile(DBTypeGet.FileFromDir(fixFileType)); fixZip.Child(iRom).CopyTo(fixZippedFile); fixZipTemp.Add(fixZippedFile); ReportError.LogOut(fixZippedFile.RepStatus + " : " + fixZip.Child(iRom).FullName); fileRepStatus = fixZippedFile.RepStatus; switch (fixZippedFile.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 fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Corrupt || fixZippedFile.DatStatus == DatStatus.InDatMerged && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Got || fixZippedFile.DatStatus == DatStatus.InToSort && fixZippedFile.GotStatus == GotStatus.Corrupt || // do not have this file and cannot fix it here fixZippedFile.DatStatus == DatStatus.InDatCollect && fixZippedFile.GotStatus == GotStatus.NotGot || fixZippedFile.DatStatus == DatStatus.InDatBad && fixZippedFile.GotStatus == GotStatus.NotGot || fixZippedFile.DatStatus == DatStatus.InDatMerged && fixZippedFile.GotStatus == GotStatus.NotGot ) ) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } if (fixZippedFile.RepStatus == RepStatus.Delete) { if (Settings.rvSettings.DetailedFixReporting) { Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, "Delete", "", "", "")); } returnCode = FixFileUtils.DoubleCheckDelete(fixZippedFile, out errorMessage); if (returnCode != ReturnCode.Good) { CloseZipFile(ref tempFixZip); CloseToSortGame(toSortGame, ref toSortZipOut); CloseToSortCorruptGame(toSortGame, ref toSortZipOut); return(returnCode); } } fixZippedFile.GotStatus = GotStatus.NotGot; break; #endregion // 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: { returnCode = FixAZipFunctions.CorrectZipFile(fixZip, fixZippedFile, ref tempFixZip, iRom, fileProcessQueue, out errorMessage); if (returnCode != ReturnCode.Good) { CloseZipFile(ref tempFixZip); CloseToSortGame(toSortGame, ref toSortZipOut); CloseToSortCorruptGame(toSortGame, ref toSortZipOut); return(returnCode); } break; } case RepStatus.CanBeFixed: case RepStatus.CorruptCanBeFixed: { returnCode = FixAZipFunctions.CanBeFixed(fixZip, fixZippedFile, ref tempFixZip, fileProcessQueue, ref totalFixed, out errorMessage); if (returnCode != ReturnCode.Good) { CloseZipFile(ref tempFixZip); CloseToSortGame(toSortGame, ref toSortZipOut); CloseToSortCorruptGame(toSortGame, ref toSortZipOut); return(returnCode); } break; } case RepStatus.MoveToSort: { returnCode = FixAZipFunctions.MovetoSort(fixZip, fixZippedFile, ref toSortGame, ref toSortZipOut, iRom); if (returnCode != ReturnCode.Good) { CloseZipFile(ref tempFixZip); CloseToSortGame(toSortGame, ref toSortZipOut); CloseToSortCorruptGame(toSortGame, ref toSortZipOut); return(returnCode); } break; } case RepStatus.MoveToCorrupt: FixAZipFunctions.MoveToCorrupt(fixZip, fixZippedFile, ref toSortCorruptGame, ref toSortCorruptOut, iRom); break; default: ReportError.UnhandledExceptionHandler( "Unknown file status found " + fixZippedFile.RepStatus + " while fixing file " + fixZip.Name + " Dat Status = " + fixZippedFile.DatStatus + " GotStatus " + fixZippedFile.GotStatus); break; } } //if ToSort Zip Made then close the zip and add this new zip to the Database CloseToSortGame(toSortGame, ref toSortZipOut); //if Corrupt Zip Made then close the zip and add this new zip to the Database CloseToSortCorruptGame(toSortCorruptGame, ref toSortCorruptOut); #region Process original Zip if (File.Exists(filename)) { if (!File.SetAttributes(filename, FileAttributes.Normal)) { int error = Error.GetLastError(); Report.ReportProgress(new bgwShowError(filename, "Error Setting File Attributes to Normal. Deleting Original Fix File. Code " + error)); } try { File.Delete(filename); } catch (Exception e) { errorMessage = "Error While trying to delete file " + filename + ". " + e.Message; if (tempFixZip != null && tempFixZip.ZipOpen != ZipOpenType.Closed) { tempFixZip.ZipFileClose(); tempFixZip = null; } return(ReturnCode.RescanNeeded); } } #endregion bool checkDelete = false; #region process the temp Zip rename it to the original Zip if (tempFixZip != null && tempFixZip.ZipOpen != ZipOpenType.Closed) { string tempFilename = tempFixZip.ZipFilename; tempFixZip.ZipFileClose(); if (tempFixZip.LocalFilesCount() > 0) { // now rename the temp fix file to the correct filename File.Move(tempFilename, filename); FileInfo nFile = new FileInfo(filename); RvFile tmpZip = new RvFile(FileType.Zip) { Name = Path.GetFileName(filename), FileModTimeStamp = nFile.LastWriteTime }; tmpZip.SetStatus(fixZip.DatStatus, GotStatus.Got); fixZip.FileAdd(tmpZip, false); fixZip.ZipStatus = tempFixZip.ZipStatus; } else { File.Delete(tempFilename); checkDelete = true; } tempFixZip = null; } 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) { FixFileUtils.CheckDeleteFile(fixZip); } ReportError.LogOut(""); ReportError.LogOut("Zip File Status After Fix:"); for (int intLoop = 0; intLoop < fixZip.ChildCount; intLoop++) { ReportError.LogOut(fixZip.Child(intLoop)); } ReportError.LogOut(""); return(ReturnCode.Good); } catch (ZipFileException ex) { tempFixZip?.ZipFileCloseFailed(); toSortZipOut?.ZipFileCloseFailed(); toSortCorruptOut?.ZipFileCloseFailed(); tempFixZip = null; toSortZipOut = null; toSortCorruptOut = null; errorMessage = ex.Message; return(ex.returnCode); } catch (Exception ex) { tempFixZip?.ZipFileCloseFailed(); toSortZipOut?.ZipFileCloseFailed(); toSortCorruptOut?.ZipFileCloseFailed(); tempFixZip = null; toSortZipOut = null; toSortCorruptOut = null; errorMessage = ex.Message; return(ReturnCode.LogicError); } finally { if (tempFixZip != null) { ReportError.UnhandledExceptionHandler($"{tempFixZip.ZipFilename} tempZipOut was left open, ZipFile= {fixZipFullName} , fileRepStatus= {fileRepStatus} , returnCode= {returnCode}"); } if (toSortZipOut != null) { ReportError.UnhandledExceptionHandler($"{toSortZipOut.ZipFilename} toSortZipOut was left open"); } if (toSortCorruptOut != null) { ReportError.UnhandledExceptionHandler($"{toSortCorruptOut.ZipFilename} toSortCorruptOut was left open"); } } }
public static ReturnCode MovetoSort(RvFile fixZip, RvFile fixZippedFile, ref RvFile toSortGame, ref ICompress toSortZipOut, int iRom, Dictionary <string, RvFile> filesUserForFix) { if (!(fixZippedFile.DatStatus == DatStatus.NotInDat && fixZippedFile.GotStatus == GotStatus.Got)) { ReportError.SendAndShow("Error in Fix Rom Status " + fixZippedFile.RepStatus + " : " + fixZippedFile.DatStatus + " : " + fixZippedFile.GotStatus); } ReportError.LogOut("MovetoSort:"); ReportError.LogOut(fixZippedFile); // move the rom out to the To Sort Directory string toSortFullName; if (toSortGame == null) { ReturnCode retCode = FixFileUtils.CreateToSortDirs(fixZip, out RvFile outDir, out string toSortFileName); if (retCode != ReturnCode.Good) { return(retCode); } toSortGame = new RvFile(fixZip.FileType) { Parent = outDir, Name = toSortFileName, DatStatus = DatStatus.InToSort, GotStatus = GotStatus.Got }; toSortFullName = Path.Combine(outDir.FullName, toSortGame.Name); } else { toSortFullName = toSortZipOut.ZipFilename; } // this needs header / alt info added. RvFile toSortRom = new RvFile(fixZippedFile.FileType) { Name = fixZippedFile.Name, Size = fixZippedFile.Size, CRC = fixZippedFile.CRC, SHA1 = fixZippedFile.SHA1, MD5 = fixZippedFile.MD5, HeaderFileType = fixZippedFile.HeaderFileType, AltSize = fixZippedFile.AltSize, AltCRC = fixZippedFile.AltCRC, AltSHA1 = fixZippedFile.AltSHA1, AltMD5 = fixZippedFile.AltMD5, FileGroup = fixZippedFile.FileGroup }; toSortRom.SetStatus(DatStatus.InToSort, GotStatus.Got); toSortRom.FileStatusSet( FileStatus.HeaderFileTypeFromHeader | FileStatus.SizeFromHeader | FileStatus.SizeVerified | FileStatus.CRCFromHeader | FileStatus.CRCVerified | FileStatus.SHA1FromHeader | FileStatus.SHA1Verified | FileStatus.MD5FromHeader | FileStatus.MD5Verified | FileStatus.AltSizeFromHeader | FileStatus.AltSizeVerified | FileStatus.AltCRCFromHeader | FileStatus.AltCRCVerified | FileStatus.AltSHA1FromHeader | FileStatus.AltSHA1Verified | FileStatus.AltMD5FromHeader | FileStatus.AltMD5Verified , fixZippedFile); ReturnCode returnCode; string errorMessage; if (toSortZipOut == null) { returnCode = FixAZipFunctions.OpenOutputZip(toSortGame, toSortFullName, out toSortZipOut, out errorMessage); if (returnCode != ReturnCode.Good) { throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } } RvFile fileIn = fixZip.Child(iRom); List <RvFile> lstFixRomTable = null; if (fileIn.FileType == FileType.SevenZipFile && fileIn.Size > 0) { lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); ReportError.LogOut("CorrectZipFile: picking from"); ReportError.ReportList(lstFixRomTable); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); if (fileIn.FileType == FileType.SevenZipFile) { ReturnCode returnCode1 = Decompress7ZipFile.DecompressSource7ZipFile(fixZip, true, out errorMessage); if (returnCode1 != ReturnCode.Good) { ReportError.LogOut($"DecompressSource7Zip: OutputOutput {fixZip.FileName} return {returnCode1}"); return(returnCode1); } lstFixRomTable = FindSourceFile.GetFixFileList(fixZippedFile); fileIn = FindSourceFile.FindSourceToUseForFix(fixZippedFile, lstFixRomTable); } } string fixZipFullName = fixZip.TreeFullName; Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixZipFullName), Path.GetFileName(fixZipFullName), fixZippedFile.Name, fixZippedFile.Size, "Raw-->", Path.GetDirectoryName(toSortFullName), Path.GetFileName(toSortFullName), toSortRom.Name)); returnCode = FixFileUtils.CopyFile(fileIn, toSortZipOut, null, toSortRom, true, out errorMessage); switch (returnCode) { case ReturnCode.Good: // correct reply to continue; break; default: throw new FixAZip.ZipFileException(returnCode, fixZippedFile.FullName + " " + fixZippedFile.RepStatus + " " + returnCode + Environment.NewLine + errorMessage); } fixZippedFile.GotStatus = GotStatus.NotGot; // Changes RepStatus to Deleted fixZippedFile.FileGroup.Files.Add(toSortRom); toSortGame.ChildAdd(toSortRom); if (lstFixRomTable != null) { foreach (RvFile f in lstFixRomTable) { string fn = f.TreeFullName; if (!filesUserForFix.ContainsKey(fn)) { filesUserForFix.Add(fn, f); } } } return(ReturnCode.Good); }