public void UpdateRepStatusUpTree(RepStatus rStat, int dir) { DirStatus.UpdateRepStatus(rStat, dir); if (Parent != null) { Parent.UpdateRepStatusUpTree(rStat, dir); } }
public void RepStatusReset() { SearchFound = false; if ((RepStatus == RepStatus.UnSet || RepStatus == RepStatus.Unknown || RepStatus == RepStatus.Ignore) && FileType == FileType.File && GotStatus == GotStatus.Got && DatStatus == DatStatus.NotInDat) { foreach (string file in Program.rvSettings.IgnoreFiles) { if (Name == file) { RepStatus = RepStatus.Ignore; return; } } } List <RepStatus> rs = RepairStatus.StatusCheck[(int)FileType, (int)_datStatus, (int)_gotStatus]; RepStatus = rs == null ? RepStatus.Error : rs[0]; }
public void UpdateRepStatusUpTree(RepStatus rStat, int dir) { DirStatus.UpdateRepStatus(rStat, dir); if (Parent != null) Parent.UpdateRepStatusUpTree(rStat, dir); }
public void UpdateRepStatus(RepStatus rs, int dir) { _arrRepStatus[(int)rs] += dir; }
public int Get(RepStatus v) { return _arrRepStatus[(int)v]; }
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 void UpdateRepStatusUpTree(RepStatus rStat, int dir) { DirStatus.UpdateRepStatus(rStat, dir); Parent?.UpdateRepStatusUpTree(rStat, dir); }
public int Get(RepStatus v) { return(_arrRepStatus[(int)v]); }
public void RepStatusReset() { SearchFound = false; if ((RepStatus == RepStatus.UnSet || RepStatus == RepStatus.Unknown || RepStatus == RepStatus.Ignore) && FileType == FileType.File && GotStatus == GotStatus.Got && DatStatus==DatStatus.NotInDat) foreach (string file in Settings.IgnoreFiles) if (Name == file) { RepStatus = RepStatus.Ignore; return; } List<RepStatus> rs = RepairStatus.StatusCheck[(int)FileType, (int)_datStatus, (int)_gotStatus]; RepStatus = rs == null ? RepStatus.Error : rs[0]; }
/// <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"); } } }