Ejemplo n.º 1
0
        private static ReturnCode FixFileMoveToSort(RvFile fixFile, out string errorMessage)
        {
            ReturnCode returnCode;

            returnCode = FixFileUtils.CreateToSortDirs(fixFile, out RvFile outDir, out string toSortFileName);
            if (returnCode != ReturnCode.Good)
            {
                errorMessage = "";
                return(returnCode);
            }

            string fixFileFullName = fixFile.FullName;
            string toSortFullName  = Path.Combine(outDir.FullName, toSortFileName);

            //create new tosort record
            // FileInfo toSortFile = new FileInfo(toSortFullName);
            RvFile toSortRom = new RvFile(FileType.File)
            {
                Name = toSortFileName,
                Size = fixFile.Size,
                CRC  = fixFile.CRC,
                //TimeStamp = toSortFile.LastWriteTime,
                DatStatus = DatStatus.InToSort
            };

            Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "-->", outDir.FullName, "", fixFileFullName));

            returnCode = FixFileUtils.MoveFile(fixFile, toSortRom, toSortFullName, out bool fileMoved, out errorMessage);
            if (returnCode != ReturnCode.Good)
            {
                return(returnCode);
            }

            if (!fileMoved)
            {
                returnCode = FixFileUtils.CopyFile(fixFile, null, toSortFullName, toSortRom, false, out errorMessage);
                if (returnCode != ReturnCode.Good)
                {
                    return(returnCode);
                }

                string fixFilePath = fixFile.FullName;
                if (!File.SetAttributes(fixFilePath, FileAttributes.Normal))
                {
                    int error = Error.GetLastError();
                    Report.ReportProgress(new bgwShowError(fixFilePath,
                                                           "Error Setting File Attributes to Normal. Before Delete Moving ToSort. Code " + error));
                }

                File.Delete(fixFilePath);

                // here we just deleted a file so also delete it from the DB,
                // and recurse up deleting unnedded DIR's
                FixFileUtils.CheckDeleteFile(fixFile);
            }

            outDir.ChildAdd(toSortRom);

            return(ReturnCode.Good);
        }
Ejemplo n.º 2
0
        private static ReturnCode FixFileCanBeFixed(RvFile fixFile, List <RvFile> fileProcessQueue, ref int totalFixed, out string errorMessage)
        {
            string fixFileFullName = fixFile.FullName;

            FixFileUtils.CheckCreateDirectories(fixFile.Parent);

            // check to see if there is already a file with the name of the fixFile, and move it out the way.
            ReturnCode rc = FixFilePreCheckFixFile(fixFile, out errorMessage);

            if (rc != ReturnCode.Good)
            {
                return(rc);
            }


            // now we can fix the file.
            ReturnCode returnCode;

            List <RvFile> lstFixRomTable = new List <RvFile>();
            List <RvFile> family         = fixFile.FileGroup.Files;

            foreach (RvFile file in family)
            {
                if (file.GotStatus == GotStatus.Got && DBHelper.CheckIfMissingFileCanBeFixedByGotFile(fixFile, file))
                {
                    lstFixRomTable.Add(file);
                }
            }

            if (DBHelper.IsZeroLengthFile(fixFile))
            {
                RvFile fileIn = new RvFile(FileType.File);
                returnCode = FixFileUtils.CopyFile(fileIn, null, fixFile.FullName, fixFile, false, out errorMessage);
                if (returnCode != ReturnCode.Good)
                {
                    errorMessage = fixFile.FullName + " " + fixFile.RepStatus + " " + returnCode + " : " + errorMessage;
                    return(returnCode);
                }
                // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted.
                FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true);

                totalFixed++;
                return(ReturnCode.Good);
            }

            RvFile fixingFile = FindSourceFile.FindSourceToUseForFix(fixFile, lstFixRomTable);

            string fts = fixingFile.FullName;

            Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "<--", Path.GetDirectoryName(fts), Path.GetFileName(fts), fixingFile.Name));

            fixFile.FileTestFix(fixingFile);


            returnCode = FixFileUtils.MoveFile(fixingFile, fixFile, null, out bool fileMoved, out errorMessage);
            if (returnCode != ReturnCode.Good)
            {
                return(returnCode);
            }
            if (fileMoved)
            {
                // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted.
                FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true);

                totalFixed++;
                return(ReturnCode.Good);
            }

            returnCode = FixFileUtils.CopyFile(fixingFile, null, fixFile.FullName, fixFile, false, out errorMessage);

            switch (returnCode)
            {
            case ReturnCode.Good:     // correct reply to continue;
                break;

            case ReturnCode.SourceDataStreamCorrupt:
            {
                Report.ReportProgress(new bgwShowFixError("CRC Error"));
                // the file we used for fix turns out to be corrupt

                // mark the source file as Corrupt
                fixingFile.GotStatus = GotStatus.Corrupt;

                return(returnCode);
            }

            default:
                Report.ReportProgress(new bgwShowFixError("Failed"));
                return(returnCode);
            }


            // Check the files that we found that where used to fix this file, and if they not listed as correct files, they can be set to be deleted.
            FixFileUtils.CheckFilesUsedForFix(lstFixRomTable, fileProcessQueue, true);

            totalFixed++;
            return(ReturnCode.Good);
        }
Ejemplo n.º 3
0
        private static ReturnCode FixFileMoveToCorrupt(RvFile fixFile, out string errorMessage)
        {
            string corruptDir = Path.Combine(DB.ToSort(), "Corrupt");

            if (!Directory.Exists(corruptDir))
            {
                Directory.CreateDirectory(corruptDir);
            }

            string fixFileFullName = fixFile.FullName;

            string toSortCorruptFullName = Path.Combine(corruptDir, fixFile.Name);
            string toSortCorruptFileName = fixFile.Name;
            int    fileC = 0;

            while (File.Exists(toSortCorruptFullName))
            {
                fileC++;
                toSortCorruptFileName = fixFile.Name + fileC;
                toSortCorruptFullName = Path.Combine(corruptDir, toSortCorruptFileName);
            }

            //create new tosort record
            // FileInfo toSortCorruptFile = new FileInfo(toSortCorruptFullName);
            RvFile toSortCorruptRom = new RvFile(FileType.File)
            {
                Name = toSortCorruptFileName,
                Size = fixFile.Size,
                CRC  = fixFile.CRC,
                //TimeStamp = toSortFile.LastWriteTime,
                DatStatus = DatStatus.InToSort
            };

            Report.ReportProgress(new bgwShowFix(Path.GetDirectoryName(fixFileFullName), "", Path.GetFileName(fixFileFullName), fixFile.Size, "-->", "Corrupt", "", fixFile.Name));

            ReturnCode returnCode = FixFileUtils.MoveFile(fixFile, toSortCorruptRom, toSortCorruptFullName, out bool fileMoved, out errorMessage);

            if (returnCode != ReturnCode.Good)
            {
                return(returnCode);
            }

            if (!fileMoved)
            {
                returnCode = FixFileUtils.CopyFile(fixFile, null, toSortCorruptFullName, toSortCorruptRom, false,
                                                   out errorMessage);
                if (returnCode != ReturnCode.Good)
                {
                    return(returnCode);
                }

                string fixFilePath = fixFile.FullName;
                if (!File.SetAttributes(fixFilePath, FileAttributes.Normal))
                {
                    int error = Error.GetLastError();
                    Report.ReportProgress(new bgwShowError(fixFilePath,
                                                           "Error Setting File Attributes to Normal. Before Delete Moving ToSort. Code " + error));
                }

                File.Delete(fixFilePath);

                // here we just deleted a file so also delete it from the DB,
                // and recurse up deleting unnedded DIR's
                FixFileUtils.CheckDeleteFile(fixFile);
            }

            RvFile toSort       = DB.RvFileToSort();
            RvFile rvCorruptDir = new RvFile(FileType.Dir)
            {
                Name = "Corrupt", DatStatus = DatStatus.InToSort
            };
            int found = toSort.ChildNameSearch(rvCorruptDir, out int indexCorrupt);

            if (found != 0)
            {
                rvCorruptDir.GotStatus = GotStatus.Got;
                indexCorrupt           = toSort.ChildAdd(rvCorruptDir);
            }

            toSort.Child(indexCorrupt).ChildAdd(toSortCorruptRom);

            errorMessage = "";
            return(ReturnCode.Good);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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
        }
Ejemplo n.º 6
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="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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }