private static void DBFileNotFound(RvFile dbChild, RvFile dbDir, ref int dbIndex) { if (dbChild == null) { ReportError.SendAndShow("Error in File Scanning Code."); return; } if (dbChild.FileRemove() == EFile.Delete) { dbDir.ChildRemove(dbIndex); } else { switch (dbChild.FileType) { case FileType.Zip: case FileType.SevenZip: MarkAsMissing(dbChild); break; case FileType.Dir: RvFile tDir = dbChild; if (tDir.Tree == null) { MarkAsMissing(tDir); } break; } dbIndex++; } }
public virtual void Read(BinaryReader br, List <RvDat> parentDirDats) { Name = br.ReadString(); FileName = br.ReadString(); TimeStamp = br.ReadInt64(); bool foundDat = br.ReadBoolean(); if (foundDat) { int index = br.ReadInt32(); if (index == -1) { ReportError.SendAndShow(Resources.RvBase_Read_Dat_found_without_an_index); } else { Dat = parentDirDats[index]; } } else { Dat = null; } _datStatus = (DatStatus)br.ReadByte(); _gotStatus = (GotStatus)br.ReadByte(); RepStatusReset(); }
public static int CompareName(RvFile var1, RvFile var2) { FileType f1 = var1.FileType; FileType f2 = var2.FileType; if (f1 == FileType.ZipFile || f2 == FileType.ZipFile) { if (f1 != f2) { ReportError.SendAndShow("Incompatible Compare type"); } return(Math.Sign(DatSort.TrrntZipStringCompare(var1.Name, var2.Name))); } if (f1 == FileType.SevenZipFile || f2 == FileType.SevenZipFile) { if (f1 != f2) { ReportError.SendAndShow("Incompatible Compare type"); } return(Math.Sign(DatSort.Trrnt7ZipStringCompare(var1.Name, var2.Name))); } int res = DatSort.TrrntZipStringCompare(var1.Name, var2.Name); if (res != 0) { return(res); } return(f1.CompareTo(f2)); }
public RvDir(FileType type) : base(type) { if ((type != FileType.Dir) && (type != FileType.Zip) && (type != FileType.SevenZip)) { ReportError.SendAndShow("Trying to set Dir type to " + type); } }
public RvFile(FileType type) : base(type) { if (type != FileType.File && type != FileType.ZipFile) { ReportError.SendAndShow("Trying to set file type to " + type); } }
public static int iCompare(ulong?a, ulong?b) { if (a == null || b == null) { ReportError.SendAndShow("comparing null ulong? "); return(-1); } return(Math.Sign(((ulong)a).CompareTo((ulong)b))); }
private static void ZeroListCheck(FileGroup family) { List <RvFile> files = family.Files; // set the found status of this file foreach (RvFile tFile in files) { if (treeType(tFile) == RvTreeRow.TreeSelect.Locked) { continue; } switch (tFile.RepStatus) { case RepStatus.UnScanned: break; case RepStatus.Missing: tFile.RepStatus = RepStatus.CanBeFixed; break; case RepStatus.Correct: break; case RepStatus.Corrupt: if (tFile.DatStatus == DatStatus.InDatCollect) { tFile.RepStatus = RepStatus.CanBeFixed; // corrupt files that are also InDatcollect are treated as missing files, and a fix should be found. } else { tFile.RepStatus = RepStatus.Delete; // all other corrupt files should be deleted or moved to tosort/corrupt } break; case RepStatus.UnNeeded: case RepStatus.Unknown: tFile.RepStatus = RepStatus.Delete; break; case RepStatus.NotCollected: break; case RepStatus.InToSort: tFile.RepStatus = RepStatus.Delete; break; case RepStatus.Ignore: break; // Ignore File default: ReportError.SendAndShow("Unknown test status " + tFile.FullName + "," + tFile.DatStatus + "," + tFile.RepStatus); break; } } }
public override void DatAdd(RvBase b) { Tree = ((RvDir)b).Tree; Game = ((RvDir)b).Game; if (_dirDats.Count > 0) { ReportError.SendAndShow(Resources.RvDir_SetDat_Setting_Dir_with_a_dat_list); } base.DatAdd(b); }
public virtual void FileAdd(RvBase file) { TimeStamp = file.TimeStamp; FileCheckName(file); if (file.GotStatus == GotStatus.NotGot) { ReportError.SendAndShow("Error setting got to a NotGot File"); } GotStatus = file.GotStatus; }
private static bool NewFileFound(RvFile fileChild, RvFile dbDir, int dbIndex) { if (fileChild == null) { ReportError.SendAndShow("Error in File Scanning Code."); return(true); } // this could be an unknown file, or dirctory. // if item is a directory add the directory and call back in again // add the newly found item switch (fileChild.FileType) { case FileType.Zip: case FileType.SevenZip: dbDir.ChildAdd(fileChild, dbIndex); CheckADir(fileChild, false); return(true); case FileType.Dir: dbDir.ChildAdd(fileChild, dbIndex); CheckADir(fileChild, true); return(true); case FileType.File: // if we have not read the files CRC in the checking code, we need to read it now. if (fileChild.GotStatus != GotStatus.FileLocked) { if (!Utils.IsDeepScanned(fileChild)) { Populate.FromAFile(fileChild, dbDir.FullName, EScanLevel, _thWrk, ref _fileErrorAbort); } } dbDir.ChildAdd(fileChild, dbIndex); return(true); case FileType.ZipFile: dbDir.ChildAdd(fileChild, dbIndex); return(true); case FileType.SevenZipFile: if (fileChild.Name.EndsWith("/")) { return(false); } dbDir.ChildAdd(fileChild, dbIndex); return(true); default: throw new Exception("Unsuported file type " + fileChild.FileType); } }
public void ChildAdd(RvBase child, int index) { if ( ((FileType == FileType.Dir) && (child.FileType == FileType.ZipFile)) || ((FileType == FileType.Zip) && (child.FileType != FileType.ZipFile)) ) { ReportError.SendAndShow("Typing to add a " + child.FileType + " to a " + FileType); } _children.Insert(index, child); child.Parent = this; UpdateRepStatusArrUpTree(child, 1); }
public override void FileAdd(RvBase file) { RvFile tFile = file as RvFile; if (tFile == null) { ReportError.SendAndShow("Error setting File Got"); return; } if (Size == null && tFile.Size != null) { Size = tFile.Size; } if (CRC == null && tFile.CRC != null) { CRC = tFile.CRC; } if (SHA1 == null && tFile.SHA1 != null) { SHA1 = tFile.SHA1; } if (MD5 == null && tFile.MD5 != null) { MD5 = tFile.MD5; } if (SHA1CHD == null && tFile.SHA1CHD != null) { SHA1CHD = tFile.SHA1CHD; } if (MD5CHD == null && tFile.MD5CHD != null) { MD5CHD = tFile.MD5CHD; } CHDVersion = tFile.CHDVersion; FileStatusSet( FileStatus.SizeFromHeader | FileStatus.CRCFromHeader | FileStatus.SHA1FromHeader | FileStatus.MD5FromHeader | FileStatus.SHA1CHDFromHeader | FileStatus.MD5CHDFromHeader | FileStatus.SizeVerified | FileStatus.CRCVerified | FileStatus.SHA1Verified | FileStatus.MD5Verified | FileStatus.SHA1CHDVerified | FileStatus.MD5CHDVerified, tFile); ZipFileIndex = tFile.ZipFileIndex; ZipFileHeaderPosition = tFile.ZipFileHeaderPosition; base.FileAdd(file); }
public override void DatAdd(RvBase file) { RvFile tFile = file as RvFile; if (tFile == null) { ReportError.SendAndShow("Error setting Dat Set Got"); return; } if (Size == null && tFile.Size != null) { Size = tFile.Size; } if (CRC == null && tFile.CRC != null) { CRC = tFile.CRC; } if (SHA1 == null && tFile.SHA1 != null) { SHA1 = tFile.SHA1; } if (MD5 == null && tFile.MD5 != null) { MD5 = tFile.MD5; } if (SHA1CHD == null && tFile.SHA1CHD != null) { SHA1CHD = tFile.SHA1CHD; } if (MD5CHD == null && tFile.MD5CHD != null) { MD5CHD = tFile.MD5CHD; } FileStatusSet( FileStatus.SizeFromDAT | FileStatus.CRCFromDAT | FileStatus.SHA1FromDAT | FileStatus.MD5FromDAT | FileStatus.SHA1CHDFromDAT | FileStatus.MD5CHDFromDAT, tFile); Merge = tFile.Merge; Status = tFile.Status; base.DatAdd(file); }
private static void SetMissingStatus(RvFile dbChild) { if (dbChild.FileRemove() == EFile.Delete) { ReportError.SendAndShow("Error is Set Missing Status in DatUpdate"); return; } FileType ft = dbChild.FileType; if (ft == FileType.Zip || ft == FileType.SevenZip || ft == FileType.Dir) { RvFile dbDir = dbChild; for (int i = 0; i < dbDir.ChildCount; i++) { SetMissingStatus(dbDir.Child(i)); } } }
public static int CompareName(RvFile var1, RvFile var2) { FileType f1 = var1.FileType; FileType f2 = var2.FileType; int res = 0; if (f1 == FileType.ZipFile || f2 == FileType.ZipFile) { if (f1 != f2) { ReportError.SendAndShow("Incompatible Compare type"); } res = Math.Sign(DatSort.TrrntZipStringCompare(var1.Name, var2.Name)); return(res != 0 ? res : Math.Sign(string.Compare(var1.Name, var2.Name, StringComparison.Ordinal))); } if (f1 == FileType.SevenZipFile || f2 == FileType.SevenZipFile) { if (f1 != f2) { ReportError.SendAndShow("Incompatible Compare type"); } return(Math.Sign(DatSort.Trrnt7ZipStringCompare(var1.Name, var2.Name))); } res = DatSort.TrrntZipStringCompare(var1.Name, var2.Name); if (res != 0) { return(res); } #if ZipFile if (f1 == FileType.File && f2 == FileType.Zip) { f2 = FileType.File; } #endif return(f1.CompareTo(f2)); }
public virtual EFile FileRemove() { TimeStamp = 0; FileName = null; GotStatus = (Parent.GotStatus == GotStatus.FileLocked) ? GotStatus.FileLocked : GotStatus.NotGot; switch (DatStatus) { case DatStatus.InDatCollect: case DatStatus.InDatMerged: case DatStatus.InDatBad: return(EFile.Keep); case DatStatus.NotInDat: case DatStatus.InToSort: return(EFile.Delete); // this item should be removed from the db. default: ReportError.SendAndShow(Resources.RvBase_SetGot_Unknown_Set_Got_Status + DatStatus); return(EFile.Keep); } }
public virtual void DatAdd(RvBase b) { // Parent , TimeStamp Should already be correct. if (GotStatus == GotStatus.NotGot) { ReportError.SendAndShow("Error Adding DAT to NotGot File " + b.GotStatus); } SetStatus(b.DatStatus, GotStatus.Got); if (Name == b.Name) // case match so all is good { FileName = null; } else { FileName = Name; Name = b.Name; } Dat = b.Dat; }
public static 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"); } } }
/// <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, 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); }
/// <summary> /// Add the new DAT's into the DAT list /// And merge in the new DAT data into the database /// </summary> /// <param name="dbDir">The Current database dir</param> /// <param name="tmpDir">A temp directory containing the DAT found in this directory in DatRoot</param> private static void AddNewDats(RvFile dbDir, RvFile tmpDir) { int dbIndex = 0; int scanIndex = 0; Debug.WriteLine(""); Debug.WriteLine("Scanning for Adding new DATS"); while (dbIndex < dbDir.DirDatCount || scanIndex < tmpDir.DirDatCount) { RvDat dbDat = null; RvDat fileDat = null; int res = 0; if (dbIndex < dbDir.DirDatCount && scanIndex < tmpDir.DirDatCount) { dbDat = dbDir.DirDat(dbIndex); fileDat = tmpDir.DirDat(scanIndex); res = DBHelper.DatCompare(dbDat, fileDat); Debug.WriteLine("Checking " + dbDat.GetData(RvDat.DatData.DatRootFullName) + " : and " + fileDat.GetData(RvDat.DatData.DatRootFullName) + " : " + res); } else if (scanIndex < tmpDir.DirDatCount) { fileDat = tmpDir.DirDat(scanIndex); res = 1; Debug.WriteLine("Checking : and " + fileDat.GetData(RvDat.DatData.DatRootFullName) + " : " + res); } else if (dbIndex < dbDir.DirDatCount) { dbDat = dbDir.DirDat(dbIndex); res = -1; Debug.WriteLine("Checking " + dbDat.GetData(RvDat.DatData.DatRootFullName) + " : and : " + res); } switch (res) { case 0: _datsProcessed++; _thWrk.Report(_datsProcessed); _thWrk.Report(new bgwText("Dat : " + Path.GetFileNameWithoutExtension(fileDat?.GetData(RvDat.DatData.DatRootFullName)))); Debug.WriteLine("Correct"); // Should already be set as correct above if (dbDat != null) { dbDat.Status = DatUpdateStatus.Correct; } dbIndex++; scanIndex++; break; case 1: _datsProcessed++; _thWrk.Report(_datsProcessed); _thWrk.Report(new bgwText("Scanning New Dat : " + Path.GetFileNameWithoutExtension(fileDat?.GetData(RvDat.DatData.DatRootFullName)))); Debug.WriteLine("Adding new DAT"); if (LoadNewDat(fileDat, dbDir)) { dbIndex++; } scanIndex++; break; case -1: // This should not happen as deleted dat have been removed above //dbIndex++; ReportError.SendAndShow("ERROR Deleting a DAT that should already be deleted."); break; } } }
/// <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 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); }
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); }
private void PaintTree(RvFile pTree, Graphics g, Rectangle t) { UiTree uTree = (UiTree)pTree.Tree.UiObject; int y = uTree.RTree.Top - _vScroll; if (uTree.RTree.IntersectsWith(t)) { Pen p = new Pen(Brushes.Gray, 1) { DashStyle = DashStyle.Dot }; string lTree = uTree.TreeBranches; for (int j = 0; j < lTree.Length; j++) { int x = j * 18 - _hScroll; string cTree = lTree.Substring(j, 1); switch (cTree) { case "│": g.DrawLine(p, x + 9, y, x + 9, y + uTree.RTree.Height); break; case "├": g.DrawLine(p, x + 9, y, x + 9, y + uTree.RTree.Height); g.DrawLine(p, x + 9, y + 8, x + 27, y + 8); break; case "└": g.DrawLine(p, x + 9, y, x + 9, y + 8); g.DrawLine(p, x + 9, y + 8, x + 27, y + 8); break; case "┐": g.DrawLine(p, x + 9, y + 8, x + 9, y + uTree.RTree.Height); break; } } } if (!uTree.RExpand.IsEmpty) { if (uTree.RExpand.IntersectsWith(t)) { g.DrawImage(pTree.Tree.TreeExpanded ? rvImages.ExpandBoxMinus : rvImages.ExpandBoxPlus, RSub(uTree.RExpand, _hScroll, _vScroll)); } } if (uTree.RChecked.IntersectsWith(t)) { switch (pTree.Tree.Checked) { case RvTreeRow.TreeSelect.Locked: g.DrawImage(rvImages.TickBoxLocked, RSub(uTree.RChecked, _hScroll, _vScroll)); break; case RvTreeRow.TreeSelect.UnSelected: g.DrawImage(rvImages.TickBoxUnTicked, RSub(uTree.RChecked, _hScroll, _vScroll)); break; case RvTreeRow.TreeSelect.Selected: g.DrawImage(rvImages.TickBoxTicked, RSub(uTree.RChecked, _hScroll, _vScroll)); break; } } if (uTree.RIcon.IntersectsWith(t)) { int icon = 2; if (pTree.DirStatus.HasInToSort()) { icon = 4; } else if (!pTree.DirStatus.HasCorrect() && pTree.DirStatus.HasMissing()) { icon = 1; } else if (!pTree.DirStatus.HasMissing()) { icon = 3; } Bitmap bm; if (pTree.Dat == null && pTree.DirDatCount == 0) // Directory above DAT's in Tree { bm = rvImages.GetBitmap("DirectoryTree" + icon); } else if (pTree.Dat == null && pTree.DirDatCount >= 1) // Directory that contains DAT's { bm = rvImages.GetBitmap("Tree" + icon); } else if (pTree.Dat != null && pTree.DirDatCount == 0) // Directories made by a DAT { bm = rvImages.GetBitmap("Tree" + icon); } else { ReportError.SendAndShow("Unknown Tree settings in DisplayTree."); bm = null; } if (bm != null) { g.DrawImage(bm, RSub(uTree.RIcon, _hScroll, _vScroll)); } } Rectangle recBackGround = new Rectangle(uTree.RText.X, uTree.RText.Y, Width - uTree.RText.X + _hScroll, uTree.RText.Height); if (recBackGround.IntersectsWith(t)) { string thistxt; List <string> datList = null; string subtxt = "( Have:" + pTree.DirStatus.CountCorrect() + " \\ Missing: " + pTree.DirStatus.CountMissing() + " )"; if (pTree.Dat == null && pTree.DirDatCount == 0) // Directory above DAT's in Tree { thistxt = pTree.Name; } else if (pTree.Dat == null && pTree.DirDatCount == 1) // Directory that contains DAT's { thistxt = pTree.Name + ": " + pTree.DirDat(0).GetData(RvDat.DatData.Description); } else if (pTree.Dat == null && pTree.DirDatCount > 1) // Directory above DAT's in Tree { thistxt = pTree.Name; if (pTree.Tree.TreeExpanded) { datList = new List <string>(); for (int i = 0; i < pTree.DirDatCount; i++) { if (!pTree.DirDat(i).AutoAddedDirectory) { string title = pTree.DirDat(i).GetData(RvDat.DatData.Description); if (string.IsNullOrWhiteSpace(title)) { title = pTree.DirDat(i).GetData(RvDat.DatData.DatName); } datList.Add(title); } } } } // pTree.Parent.DirDatCount>1: This should probably be a test like parent contains Dat else if (pTree.Dat != null && pTree.Dat.AutoAddedDirectory && pTree.Parent.DirDatCount > 1) { thistxt = pTree.Name + ": "; } else if (pTree.Dat != null && pTree.DirDatCount == 0) // Directories made by a DAT { thistxt = pTree.Name; } else { ReportError.SendAndShow("Unknown Tree settings in DisplayTree."); thistxt = ""; } if (pTree.IsInToSort) { subtxt = ""; } if (pTree.FileStatusIs(FileStatus.PrimaryToSort | FileStatus.CacheToSort)) { thistxt += " (Primary)"; } else if (pTree.FileStatusIs(FileStatus.PrimaryToSort)) { thistxt += " (Primary)"; } else if (pTree.FileStatusIs(FileStatus.CacheToSort)) { thistxt += " (Cache)"; } Brush textBrush; if (Selected != null && pTree.TreeFullName == Selected.TreeFullName) { g.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), RSub(recBackGround, _hScroll, _vScroll)); textBrush = Brushes.Wheat; } else { textBrush = Brushes.Black; } thistxt += " " + subtxt; g.DrawString(thistxt, tFont, textBrush, uTree.RText.Left - _hScroll, uTree.RText.Top + 1 - _vScroll); if (datList != null) { for (int i = 0; i < datList.Count; i++) { g.DrawString(datList[i], tFont1, textBrush, ((UiTree)pTree.Tree.UiObject).RText.Left + 20 - _hScroll, ((UiTree)pTree.Tree.UiObject).RText.Top + 14 + i * 12 - _vScroll); } } } if (!pTree.Tree.TreeExpanded) { return; } for (int i = 0; i < pTree.ChildCount; i++) { RvFile tDir = pTree.Child(i); if (tDir.IsDir && tDir.Tree?.UiObject != null) { PaintTree(tDir, g, t); } } }
private static bool MergeInDat(RvFile dbDat, RvFile newDat, out RvDat conflict, bool checkOnly) { conflict = null; int dbIndex = 0; int newIndex = 0; while (dbIndex < dbDat.ChildCount || newIndex < newDat.ChildCount) { RvFile dbChild = null; RvFile newDatChild = null; int res = 0; if (dbIndex < dbDat.ChildCount && newIndex < newDat.ChildCount) { dbChild = dbDat.Child(dbIndex); // are files newDatChild = newDat.Child(newIndex); // is from a dat item res = DBHelper.CompareName(dbChild, newDatChild); } else if (newIndex < newDat.ChildCount) { newDatChild = newDat.Child(newIndex); res = 1; } else if (dbIndex < dbDat.ChildCount) { dbChild = dbDat.Child(dbIndex); res = -1; } if (res == 0) { if (dbChild == null || newDatChild == null) { ShowDat("Error in Logic", dbDat.FullName); break; } List <RvFile> dbDats = new List <RvFile>(); List <RvFile> newDats = new List <RvFile>(); int dbDatsCount = 1; int newDatsCount = 1; dbDats.Add(dbChild); newDats.Add(newDatChild); while (dbIndex + dbDatsCount < dbDat.ChildCount && DBHelper.CompareName(dbChild, dbDat.Child(dbIndex + dbDatsCount)) == 0) { dbDats.Add(dbDat.Child(dbIndex + dbDatsCount)); dbDatsCount += 1; } while (newIndex + newDatsCount < newDat.ChildCount && DBHelper.CompareName(newDatChild, newDat.Child(newIndex + newDatsCount)) == 0) { newDats.Add(newDat.Child(newIndex + newDatsCount)); newDatsCount += 1; } if (dbDatsCount > 1 || newDatsCount > 1) { ReportError.SendAndShow("Double Name Found"); } for (int indexdb = 0; indexdb < dbDatsCount; indexdb++) { if (dbDats[indexdb].DatStatus == DatStatus.NotInDat) { continue; } if (checkOnly) { conflict = dbChild.Dat; return(true); } ShowDat("Unknown Update Dat Status " + dbChild.DatStatus, dbDat.FullName); break; } if (!checkOnly) { for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++) { if (newDats[indexNewDats].SearchFound) { continue; } for (int indexDbDats = 0; indexDbDats < dbDatsCount; indexDbDats++) { if (dbDats[indexDbDats].SearchFound) { continue; } bool matched = Compare.DatMergeCompare(dbDats[indexDbDats], newDats[indexNewDats], out bool altMatch); if (!matched) { continue; } dbDats[indexDbDats].DatAdd(newDats[indexNewDats], altMatch); FileType ft = dbChild.FileType; if (ft == FileType.Zip || ft == FileType.SevenZip || ft == FileType.Dir) { RvFile dChild = dbChild; RvFile dNewChild = newDatChild; MergeInDat(dChild, dNewChild, out conflict, false); } dbDats[indexDbDats].SearchFound = true; newDats[indexNewDats].SearchFound = true; } } for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++) { if (newDats[indexNewDats].SearchFound) { continue; } dbDat.ChildAdd(newDats[indexNewDats], dbIndex); dbChild = dbDat.Child(dbIndex); SetMissingStatus(dbChild); dbIndex++; } } dbIndex += dbDatsCount; newIndex += newDatsCount; } if (res == 1) { if (!checkOnly) { dbDat.ChildAdd(newDatChild, dbIndex); dbChild = dbDat.Child(dbIndex); SetMissingStatus(dbChild); dbIndex++; } newIndex++; } if (res == -1) { dbIndex++; } } return(false); }
/// <summary> /// Called from 5 places: /// 1: ScanFiles: main top level loop. /// 2: MatchFound: called after a ZIP/SevenZip is matched to an item in the DB, where the zip has either changed or never been scanned or level 3 scanning /// 3: MatchFound: called when an directory is matched to an item in the DB that is not from a DAT. (This is a directory not found in the main tree, as main tree dir's are processes in top level loop /// 4: NewFileFound: called after a new unmatched ZIP/SevenZip is found. /// 5: NewFileFound: called after a new unmatched DIR is found. /// </summary> /// <param name="dbDir"></param> /// <param name="report"></param> private static void CheckADir(RvFile dbDir, bool report) { if (_cacheSaveTimer.Elapsed.TotalMinutes > Settings.rvSettings.CacheSaveTimePeriod) { _thWrk.Report("Saving Cache"); DB.Write(); _thWrk.Report("Saving Cache Complete"); _cacheSaveTimer.Reset(); _cacheSaveTimer.Start(); } string fullDir = dbDir.FullName; if (report) { _thWrk.Report(new bgwText2(fullDir)); } // this is a temporary rvDir structure to store the data about the actual directory/files we are scanning // we will first populate this variable with the real file data from the directory, and then compare it // with the data in dbDir. RvFile fileDir = null; Debug.WriteLine(fullDir); FileType ft = dbDir.FileType; #region "Populate fileDir" // if we are scanning a ZIP file then populate scanDir from the ZIP file switch (ft) { case FileType.Zip: case FileType.SevenZip: fileDir = Populate.FromAZipFile(dbDir, EScanLevel, _thWrk); break; case FileType.Dir: fileDir = Populate.FromADir(dbDir, EScanLevel, _thWrk, ref _fileErrorAbort); break; default: ReportError.SendAndShow("Un supported file type in CheckADir " + ft); break; } #endregion if (fileDir == null) { ReportError.SendAndShow("Unknown Reading File Type in Dir Scanner"); return; } if (report) { _thWrk.Report(new bgwSetRange2(fileDir.ChildCount)); _thWrk.Report(new bgwRange2Visible(true)); } if (!DBTypeGet.isCompressedDir(ft) && _thWrk.CancellationPending) { return; } Compare(dbDir, fileDir, report, true); }
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 Compare(RvFile dbDir, RvFile fileDir, bool report, bool enableCancel) { string fullDir = dbDir.FullName; FileType ft = dbDir.FileType; // now we scan down the dbDir and the scanDir, comparing them. // if we find a match we mark dbDir as found. // if we are missing a file in fileDir we mark that file in dbDir as missing. // if we find extra files in fileDir we add it to dbDir and mark it as unknown. // we also recurse into any sub directories. int dbIndex = 0; int fileIndex = 0; while (dbIndex < dbDir.ChildCount || fileIndex < fileDir.ChildCount) { RvFile dbChild = null; RvFile fileChild = null; int res = 0; if (dbIndex < dbDir.ChildCount && fileIndex < fileDir.ChildCount) { dbChild = dbDir.Child(dbIndex); fileChild = fileDir.Child(fileIndex); //Debug.WriteLine($@"{dbChild.Name} , {fileChild.Name}"); res = DBHelper.CompareName(dbChild, fileChild); } else if (fileIndex < fileDir.ChildCount) { //Get any remaining filedir's fileChild = fileDir.Child(fileIndex); res = 1; } else if (dbIndex < dbDir.ChildCount) { //Get any remaining dbDir's dbChild = dbDir.Child(dbIndex); res = -1; } if (report) { if (fileChild != null) { long timenow = DateTime.Now.Ticks; if (timenow - _lastUpdateTime > TimeSpan.TicksPerSecond / 10) { _lastUpdateTime = timenow; _thWrk.Report(new bgwValue2(fileIndex + 1)); _thWrk.Report(new bgwText2(Path.Combine(fullDir, fileChild.Name))); } } } // if this file was found in the DB switch (res) { case 0: if (dbChild == null || fileChild == null) { ReportError.SendAndShow("Error in File Scanning Code."); break; } //Complete MultiName Compare List <RvFile> dbs = new List <RvFile>(); List <RvFile> files = new List <RvFile>(); int dbsCount = 1; int filesCount = 1; dbs.Add(dbChild); files.Add(fileChild); while (dbIndex + dbsCount < dbDir.ChildCount && DBHelper.CompareName(dbChild, dbDir.Child(dbIndex + dbsCount)) == 0) { dbs.Add(dbDir.Child(dbIndex + dbsCount)); dbsCount += 1; } while (fileIndex + filesCount < fileDir.ChildCount && DBHelper.CompareName(fileChild, fileDir.Child(fileIndex + filesCount)) == 0) { files.Add(fileDir.Child(fileIndex + filesCount)); filesCount += 1; } bool caseTest = files.Count > 1; // if we only have one file, we don't need to test twice. // so we need to do a case sensitive match first and then a case insensitive match // indexCase=0 means do full case filename test // indexCase=1 means do case insensitive test for (int indexCase = (caseTest ? 0 : 1); indexCase < 2; indexCase += 1) { for (int indexfile = 0; indexfile < filesCount; indexfile++) { if (files[indexfile].SearchFound) { continue; } for (int indexdb = 0; indexdb < dbsCount; indexdb++) { if (dbs[indexdb].SearchFound) { continue; } bool matched = Scanner.Compare.Phase1Test(dbs[indexdb], files[indexfile], EScanLevel, indexCase, out bool matchedAlt); if (!matched) { continue; } MatchFound(dbs[indexdb], files[indexfile], matchedAlt); dbs[indexdb].SearchFound = true; files[indexfile].SearchFound = true; } if (files[indexfile].SearchFound) { continue; } for (int indexdb = 0; indexdb < dbsCount; indexdb++) { if (dbs[indexdb].SearchFound) { continue; } bool matched = Scanner.Compare.Phase2Test(dbs[indexdb], files[indexfile], EScanLevel, indexCase, fullDir, _thWrk, ref _fileErrorAbort, out bool matchedAlt); if (!matched) { continue; } MatchFound(dbs[indexdb], files[indexfile], matchedAlt); dbs[indexdb].SearchFound = true; files[indexfile].SearchFound = true; } } } for (int indexdb = 0; indexdb < dbsCount; indexdb++) { if (dbs[indexdb].SearchFound) { dbIndex++; continue; } DBFileNotFound(dbs[indexdb], dbDir, ref dbIndex); } for (int indexfile = 0; indexfile < filesCount; indexfile++) { if (files[indexfile].SearchFound) { continue; } if (NewFileFound(files[indexfile], dbDir, dbIndex)) { dbIndex++; } } fileIndex += filesCount; break; case 1: if (NewFileFound(fileChild, dbDir, dbIndex)) { dbIndex++; } fileIndex++; break; case -1: DBFileNotFound(dbChild, dbDir, ref dbIndex); break; } if (_fileErrorAbort) { return; } if (enableCancel && !DBTypeGet.isCompressedDir(ft) && _thWrk.CancellationPending) { return; } } }