/*
         * In the mame Dat:
         * status="nodump" has a size but no CRC
         * status="baddump" has a size and crc
         */


        private static void RomCheckCollect(DatFile tRom, bool merge)
        {
            if (merge)
            {
                if (string.IsNullOrEmpty(tRom.Merge))
                {
                    tRom.Merge = "(Auto Merged)";
                }
                tRom.DatStatus = DatFileStatus.InDatMerged;
                return;
            }

            if (!string.IsNullOrEmpty(tRom.Merge))
            {
                tRom.Merge = "(No-Merge) " + tRom.Merge;
            }

            if (tRom.Status == "nodump")
            {
                tRom.DatStatus = DatFileStatus.InDatBad;
                return;
            }

            if (ArrByte.bCompare(tRom.CRC, new byte[] { 0, 0, 0, 0 }) && (tRom.Size == 0))
            {
                tRom.DatStatus = DatFileStatus.InDatCollect;
                return;
            }

            tRom.DatStatus = DatFileStatus.InDatCollect;
        }
Exemple #2
0
        private static bool CompareAltHash(RvFile dbFile, RvFile testFile)
        {
            Debug.WriteLine("ComparingAlt Dat File " + dbFile.TreeFullName);
            Debug.WriteLine("ComparingAlt File     " + testFile.TreeFullName);

            if (!FileHeaderReader.FileHeaderReader.AltHeaderFile(testFile.HeaderFileType))
            {
                return(false);
            }

            if (dbFile.HeaderFileType != testFile.HeaderFileType)
            {
                return(false);
            }


            bool testFound = false;
            int  retv;

            if (dbFile.Size != null && testFile.AltSize != null)
            {
                retv = ULong.iCompare(dbFile.Size, testFile.AltSize);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFile.CRC != null && testFile.AltCRC != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.CRC, testFile.AltCRC);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFile.SHA1 != null && testFile.AltSHA1 != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.SHA1, testFile.AltSHA1);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFile.MD5 != null && testFile.AltMD5 != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.MD5, testFile.AltMD5);
                if (retv != 0)
                {
                    return(false);
                }
            }

            return(testFound);
        }
Exemple #3
0
        public static bool IsZeroLengthFile(RvFile tFile)
        {
            if (tFile.MD5 != null)
            {
                if (!ArrByte.bCompare(tFile.MD5, ZeroByteMD5))
                {
                    return(false);
                }
            }

            if (tFile.SHA1 != null)
            {
                if (!ArrByte.bCompare(tFile.SHA1, ZeroByteSHA1))
                {
                    return(false);
                }
            }

            if (tFile.CRC != null)
            {
                if (!ArrByte.bCompare(tFile.CRC, ZeroByteCRC))
                {
                    return(false);
                }
            }

            return(tFile.Size == 0);
        }
Exemple #4
0
        // we are adding got files so we can assume a few things:
        //  these got files may be level 1 or level 2 scanned.
        //
        //  If they are just level 1 then there may or may not be SHA1 / MD5 info, which is unvalidated.
        //  So: We will always have CRC & Size info at a minimum and may also have SHA1 / MD5
        //
        //  Next: Due to the possilibity of CRC hash collisions
        //  we could find matching CRC that have different SHA1 & MD5
        //  so we should seach for one or more matching CRC/Size sets.
        //  then check to see if we have anything else that matches and then either:
        //  add the rom to an existing set or make a new set.


        private static void MergeGotFiles(RvFile[] gotFilesSortedByCRC, out FileGroup[] fileGroups)
        {
            List <FileGroup> listFileGroupsOut = new List <FileGroup>();


            // insert a zero byte file.
            RvFile    fileZero     = MakeFileZero();
            FileGroup newFileGroup = new FileGroup(fileZero);

            List <FileGroup> lstFileWithSameCRC = new List <FileGroup>();

            byte[] crc = fileZero.CRC;


            lstFileWithSameCRC.Add(newFileGroup);
            listFileGroupsOut.Add(newFileGroup);

            foreach (RvFile file in gotFilesSortedByCRC)
            {
                if (file.CRC == null)
                {
                    continue;
                }

                if (crc != null && ArrByte.ICompare(crc, file.CRC) == 0)
                {
                    bool found = false;
                    foreach (FileGroup fileGroup in lstFileWithSameCRC)
                    {
                        if (!fileGroup.FindExactMatch(file))
                        {
                            continue;
                        }

                        fileGroup.MergeFileIntoGroup(file);
                        found = true;
                        break;
                    }

                    if (found)
                    {
                        continue;
                    }

                    // new File with the same CRC but different sha1/md5/size
                    newFileGroup = new FileGroup(file);
                    lstFileWithSameCRC.Add(newFileGroup);
                    listFileGroupsOut.Add(newFileGroup);
                    continue;
                }

                crc = file.CRC;
                lstFileWithSameCRC.Clear();
                newFileGroup = new FileGroup(file);
                lstFileWithSameCRC.Add(newFileGroup);
                listFileGroupsOut.Add(newFileGroup);
            }

            fileGroups = listFileGroupsOut.ToArray();
        }
Exemple #5
0
        private static void ReportMissing(RvDir dir, RvDat dat, ReportType rt)
        {
            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvBase b = dir.Child(i);
                if (b.Dat != null && b.Dat != dat)
                {
                    continue;
                }

                RvFile f = b as RvFile;

                if (f != null)
                {
                    if (
                        (rt == ReportType.PartialMissing && Partial.Contains(f.RepStatus)) ||
                        (rt == ReportType.Fixing && Fixing.Contains(f.RepStatus))
                        )
                    {
                        string filename = f.FileNameInsideGame();
                        string crc      = ArrByte.ToString(f.CRC);
                        _ts.WriteLine("| " + filename + new string(' ', _fileNameLength + 1 - filename.Length) + "| "
                                      + f.Size + new string(' ', _fileSizeLength + 1 - f.Size.ToString().Length) + "| "
                                      + crc + new string(' ', 9 - crc.Length) + "| "
                                      + f.RepStatus + new string(' ', _repStatusLength + 1 - f.RepStatus.ToString().Length) + "|");
                    }
                }
                RvDir d = b as RvDir;
                if (d != null)
                {
                    ReportMissing(d, dat, rt);
                }
            }
        }
Exemple #6
0
        private static void RomCheckCollect(RvRom tRom, bool merge)
        {
            if (merge)
            {
                if (string.IsNullOrEmpty(tRom.Merge))
                {
                    tRom.Merge = "(Auto Merged)";
                }

                tRom.PutInZip = false;
                return;
            }

            if (!string.IsNullOrEmpty(tRom.Merge))
            {
                tRom.Merge = "(No-Merge) " + tRom.Merge;
            }


            if (ArrByte.bCompare(tRom.CRC, new byte[] { 0, 0, 0, 0 }) && (tRom.Size == 0))
            {
                tRom.PutInZip = true;
                return;
            }


            tRom.PutInZip = true;
        }
Exemple #7
0
        private static ReturnCode CheckInputAndOutputFile(RvFile fileIn, RvFile fileOut, out string error)
        {
            // need to check for matching headers types here also.

            if (fileOut.FileStatusIs(FileStatus.SizeFromDAT) && fileOut.Size != null && fileIn.Size != fileOut.Size)
            {
                error = "Source and destination Size does not match. Logic Error.";
                return(ReturnCode.LogicError);
            }

            if (fileOut.FileStatusIs(FileStatus.CRCFromDAT) && fileOut.CRC != null && !ArrByte.BCompare(fileIn.CRC, fileOut.CRC))
            {
                error = "Source and destination CRC does not match. Logic Error.";
                return(ReturnCode.LogicError);
            }

            if (fileOut.FileStatusIs(FileStatus.SHA1FromDAT) && fileIn.FileStatusIs(FileStatus.SHA1Verified))
            {
                if (fileIn.SHA1 != null && fileOut.SHA1 != null && !ArrByte.BCompare(fileIn.SHA1, fileOut.SHA1))
                {
                    error = "Source and destination SHA1 does not match. Logic Error.";
                    return(ReturnCode.LogicError);
                }
            }
            if (fileOut.FileStatusIs(FileStatus.MD5FromDAT) && fileIn.FileStatusIs(FileStatus.MD5Verified))
            {
                if (fileIn.MD5 != null && fileOut.MD5 != null && !ArrByte.BCompare(fileIn.MD5, fileOut.MD5))
                {
                    error = "Source and destination SHA1 does not match. Logic Error.";
                    return(ReturnCode.LogicError);
                }
            }
            error = "";
            return(ReturnCode.Good);
        }
Exemple #8
0
        private static bool CompareHash(RvFile dbFile, RvFile testFile)
        {
            //Debug.WriteLine("Comparing Dat File " + dbFile.TreeFullName);
            //Debug.WriteLine("Comparing File     " + testFile.TreeFullName);

            bool testFound = false;
            int  retv;

            if (dbFile.Size != null && testFile.Size != null)
            {
                retv = ULong.iCompare(dbFile.Size, testFile.Size);
                if (retv != 0)
                {
                    return(false);
                }

                //special zero size test case, if the dat size is 0 and the testfile size is 0
                //and there are no other hash values in the dat, then assume it is a match.
                if (testFile.Size == 0 && dbFile.CRC == null && dbFile.SHA1 == null && dbFile.MD5 == null)
                {
                    return(true);
                }
            }


            if (dbFile.CRC != null && testFile.CRC != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.CRC, testFile.CRC);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFile.SHA1 != null && testFile.SHA1 != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.SHA1, testFile.SHA1);
                if (retv != 0)
                {
                    return(false);
                }
            }

            if (dbFile.MD5 != null && testFile.MD5 != null)
            {
                testFound = true;
                retv      = ArrByte.ICompare(dbFile.MD5, testFile.MD5);
                if (retv != 0)
                {
                    return(false);
                }
            }

            return(testFound);
        }
        public static void DatSetMakeNonMergeSet(DatDir tDat)
        {
            // look for merged roms, check if a rom exists in a parent set where the Name,Size and CRC all match.

            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    DatSetMakeNonMergeSet(mGame);
                }
                else
                {
                    DatGame dGame = mGame.DGame;

                    if (dGame?.device_ref == null)
                    {
                        continue;
                    }

                    List <DatDir> devices = new List <DatDir> {
                        mGame
                    };

                    foreach (string device in dGame.device_ref)
                    {
                        AddDevice(device, devices, tDat);
                    }
                    devices.RemoveAt(0);


                    foreach (DatDir device in devices)
                    {
                        for (int i = 0; i < device.ChildCount; i++)
                        {
                            DatFile df0      = (DatFile)device.Child(i);
                            bool    crcFound = false;
                            for (int j = 0; j < mGame.ChildCount; j++)
                            {
                                DatFile df1 = (DatFile)mGame.Child(j);
                                if (ArrByte.bCompare(df0.SHA1, df1.SHA1))
                                {
                                    crcFound = true;
                                    break;
                                }
                            }
                            if (!crcFound)
                            {
                                mGame.ChildAdd(device.Child(i));
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        private static int RomSortCRCSizeFunc(RvFile a, RvFile b)
        {
            int retv = ArrByte.iCompare(a.CRC, b.CRC);

            if (retv == 0)
            {
                retv = ULong.iCompare(a.Size, b.Size);
            }

            return(retv);
        }
Exemple #11
0
        public static bool IsZeroLengthFile(RvFile tFile)
        {
            bool foundOneMatching = false;

            if (tFile.MD5 != null)
            {
                if (!ArrByte.BCompare(tFile.MD5, ZeroByteMD5))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            if (tFile.SHA1 != null)
            {
                if (!ArrByte.BCompare(tFile.SHA1, ZeroByteSHA1))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            if (tFile.CRC != null)
            {
                if (!ArrByte.BCompare(tFile.CRC, ZeroByteCRC))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            if (tFile.Size != null)
            {
                if (tFile.Size != 0)
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            // if at least one hash,size matched. & nothing failed to match.
            if (foundOneMatching)
            {
                return(true);
            }

            // hashes and size are all null
            // see if we have a directory
            return(tFile.Name.Length > 1 && tFile.Name.Substring(tFile.Name.Length - 1, 1) == "/");
        }
Exemple #12
0
        /*
         * In the mame Dat:
         * status="nodump" has a size but no CRC
         * status="baddump" has a size and crc
         */


        private static void RomCheckCollect(RvFile tRom, bool merge)
        {
            if (merge)
            {
                if (string.IsNullOrEmpty(tRom.Merge))
                {
                    tRom.Merge = "(Auto Merged)";
                }

                tRom.DatStatus = DatStatus.InDatMerged;
                return;
            }

            if (!string.IsNullOrEmpty(tRom.Merge))
            {
                tRom.Merge = "(No-Merge) " + tRom.Merge;
            }

            if (tRom.Status == "nodump")
            {
                tRom.CRC       = null;
                tRom.DatStatus = DatStatus.InDatBad;
                return;
            }

            if (ArrByte.bCompare(tRom.CRC, new byte[] { 0, 0, 0, 0 }) && tRom.Size == 0)
            {
                tRom.DatStatus = DatStatus.InDatCollect;
                return;
            }

            /*
             * if (ArrByte.bCompare(tRom.CRC, new byte[] { 0, 0, 0, 0 }) || (tRom.CRC.Length != 8))
             * {
             *  tRom.CRC = null;
             *  tRom.DatStatus = DatStatus.InDatBad;
             *  return;
             * }
             */

            tRom.DatStatus = DatStatus.InDatCollect;
        }
Exemple #13
0
        public override void Read(BinaryReader br, List <RvDat> parentDirDats)
        {
            base.Read(br, parentDirDats);

            FileFlags fFlags = (FileFlags)br.ReadUInt16();

            Size                  = (fFlags & FileFlags.Size) > 0 ? (ulong?)br.ReadUInt64() : null;
            CRC                   = (fFlags & FileFlags.CRC) > 0 ? ArrByte.Read(br) : null;
            SHA1                  = (fFlags & FileFlags.SHA1) > 0 ? ArrByte.Read(br) : null;
            MD5                   = (fFlags & FileFlags.MD5) > 0 ? ArrByte.Read(br) : null;
            SHA1CHD               = (fFlags & FileFlags.SHA1CHD) > 0 ? ArrByte.Read(br) : null;
            MD5CHD                = (fFlags & FileFlags.MD5CHD) > 0 ? ArrByte.Read(br) : null;
            Merge                 = (fFlags & FileFlags.Merge) > 0 ? br.ReadString() : null;
            Status                = (fFlags & FileFlags.Status) > 0 ? br.ReadString() : null;
            ZipFileIndex          = (fFlags & FileFlags.ZipFileIndex) > 0 ? br.ReadInt32() : -1;
            ZipFileHeaderPosition = (fFlags & FileFlags.ZipFileHeader) > 0 ? (ulong?)br.ReadUInt64() : null;
            CHDVersion            = (fFlags & FileFlags.CHDVersion) > 0 ? (uint?)br.ReadInt32() : null;

            _fileStatus = (FileStatus)br.ReadUInt32();
        }
Exemple #14
0
        private static void DatSetRenameAndRemoveDups(RvDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                RvDir tDir = (RvDir)tDat.Child(g);
                if (tDir.Game == null)
                {
                    DatSetRenameAndRemoveDups(tDir);
                }
                else
                {
                    for (int r = 0; r < tDir.ChildCount - 1; r++)
                    {
                        RvFile f0 = (RvFile)tDir.Child(r);
                        RvFile f1 = (RvFile)tDir.Child(r + 1);

                        if (f0.Name != f1.Name)
                        {
                            continue;
                        }

                        if (f0.Size != f1.Size || !ArrByte.bCompare(f0.CRC, f1.CRC))
                        {
                            tDir.ChildRemove(r + 1);                            // remove F1
                            f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1;
                            int pos = tDir.ChildAdd(f1);
                            if (pos < r)
                            {
                                r = pos;
                            }
                            // if this rename moved the File back up the list, start checking again from that file.
                        }
                        else
                        {
                            tDir.ChildRemove(r + 1);
                        }
                        r--;
                    }
                }
            }
        }
Exemple #15
0
        public bool FindExactMatch(RvFile file)
        {
            if (!Equal(file.Size, Size))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.CRC, CRC))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.SHA1, SHA1))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.MD5, MD5))
            {
                return(false);
            }

            // should check header file type also.

            if (!Equal(file.AltSize, AltSize))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltCRC, AltCRC))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltSHA1, AltSHA1))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltMD5, AltMD5))
            {
                return(false);
            }

            return(true);
        }
Exemple #16
0
        public static bool IsZeroLengthFile(RvFile tFile)
        {
            bool foundOneMatching = false;

            if (tFile.MD5 != null)
            {
                if (!ArrByte.BCompare(tFile.MD5, ZeroByteMD5))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            if (tFile.SHA1 != null)
            {
                if (!ArrByte.BCompare(tFile.SHA1, ZeroByteSHA1))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            if (tFile.CRC != null)
            {
                if (!ArrByte.BCompare(tFile.CRC, ZeroByteCRC))
                {
                    return(false);
                }
                foundOneMatching = true;
            }

            // this will assume a null size with at least one matching hash is a zero length file.
            if (tFile.Size == null && foundOneMatching)
            {
                return(true);
            }

            return(tFile.Size == 0);
        }
Exemple #17
0
        private static void DatSetRenameAndRemoveDups(RvDat tDat)
        {
            if (tDat.Games == null)
            {
                return;
            }

            for (int g = 0; g < tDat.Games.Count; g++)
            {
                RvGame tGame = tDat.Games[g];
                for (int r = 0; r < tGame.RomCount - 1; r++)
                {
                    RvRom f0 = tGame.Roms[r];
                    RvRom f1 = tGame.Roms[r + 1];

                    if (f0.Name != f1.Name)
                    {
                        continue;
                    }

                    if ((f0.Size != f1.Size) || (ArrByte.iCompare(f0.CRC, f1.CRC) != 0))
                    {
                        tGame.Roms.RemoveAt(r + 1);                         // remove F1
                        f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1;
                        int pos = tGame.AddRom(f1);
                        // if this rename moved the File back up the list, start checking again from that file.
                        if (pos < r)
                        {
                            r = pos;
                        }
                    }
                    else
                    {
                        tGame.Roms.RemoveAt(r + 1);
                    }
                    r--;
                }
            }
        }
Exemple #18
0
        private bool FindAltExactMatch(RvFile file)
        {
            // should check header file type also.

            if (!Equal(file.AltSize, Size))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltCRC, CRC))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltSHA1, SHA1))
            {
                return(false);
            }
            if (!ArrByte.ECompare(file.AltMD5, MD5))
            {
                return(false);
            }

            return(true);
        }
Exemple #19
0
 private static int CompareAltMD5(RvFile file, FileGroup fileGroup)
 {
     return(ArrByte.ICompare(file.MD5, fileGroup.AltMD5));
 }
Exemple #20
0
        // find fix files, if the gotFile has been fully scanned check the SHA1/MD5, if not then just return true as the CRC/Size is all we have to go on.
        // this means that if the gotfile has not been fully scanned this will return true even with the source and destination SHA1/MD5 possibly different.
        public static bool CheckIfMissingFileCanBeFixedByGotFile(RvFile missingFile, RvFile gotFile)
        {
            // should probably be checking that the header type also match

            if (missingFile.FileStatusIs(FileStatus.SHA1FromDAT) && gotFile.FileStatusIs(FileStatus.SHA1Verified) && !ArrByte.BCompare(missingFile.SHA1, gotFile.SHA1))
            {
                if (missingFile.FileStatusIs(FileStatus.SHA1FromDAT) && gotFile.FileStatusIs(FileStatus.AltSHA1Verified) && !ArrByte.BCompare(missingFile.SHA1, gotFile.AltSHA1))
                {
                    return(false);
                }
            }

            if (missingFile.FileStatusIs(FileStatus.MD5FromDAT) && gotFile.FileStatusIs(FileStatus.MD5Verified) && !ArrByte.BCompare(missingFile.MD5, gotFile.MD5))
            {
                if (missingFile.FileStatusIs(FileStatus.MD5FromDAT) && gotFile.FileStatusIs(FileStatus.AltMD5Verified) && !ArrByte.BCompare(missingFile.MD5, gotFile.AltMD5))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #21
0
        public static bool CheckIfGotfileAndMatchingFileAreFullMatches(RvFile gotFile, RvFile matchingFile)
        {
            if (gotFile.FileStatusIs(FileStatus.SHA1Verified) && matchingFile.FileStatusIs(FileStatus.SHA1Verified) && !ArrByte.BCompare(gotFile.SHA1, matchingFile.SHA1))
            {
                return(false);
            }
            if (gotFile.FileStatusIs(FileStatus.MD5Verified) && matchingFile.FileStatusIs(FileStatus.MD5Verified) && !ArrByte.BCompare(gotFile.MD5, matchingFile.MD5))
            {
                return(false);
            }

            return(true);
        }
Exemple #22
0
        // CHDs as rom
        private static void PlainProcessDir(RvDir dir, int depth = 1)
        {
            string indent = new string('\t', depth);

            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvDir item = dir.Child(i) as RvDir;
                if ((item != null) && ((item.FileType == FileType.Zip) || (item.FileType == FileType.Dir)))
                {
                    WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">");
                    WriteLine(indent + "\t<description>" + clean(item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description)) + "</description>");

                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile file = item.Child(j) as RvFile;
                        if (file != null)
                        {
                            WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>");
                        }
                        RvDir aDir = item.Child(j) as RvDir;
                        if (aDir != null)
                        {
                            string dName = aDir.Name;
                            for (int k = 0; k < aDir.ChildCount; k++)
                            {
                                RvFile subFile = aDir.Child(k) as RvFile;
                                WriteLine(indent + "\t<rom name=\"" + dName + "\\" + clean(subFile.Name) + "\" size=\"" + subFile.Size + "\" crc=\"" + ArrByte.ToString(subFile.CRC) + "\" md5=\"" + ArrByte.ToString(subFile.MD5) + "\" sha1=\"" + ArrByte.ToString(subFile.SHA1) + "\"/>");
                            }
                        }
                    }
                    WriteLine(indent + "</game>");
                }
                // only recurse when grandchildren are not CHDs
                if ((item != null) && (item.FileType == FileType.Dir) && !hasChdGrandChildren(item))
                {
                    WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">");
                    PlainProcessDir(item, depth + 1);
                    WriteLine(indent + "</dir>");
                }
            }
        }
Exemple #23
0
        public override void Write(BinaryWriter bw)
        {
            base.Write(bw);

            FileFlags fFlags = 0;

            if (Size != null)
            {
                fFlags |= FileFlags.Size;
            }
            if (CRC != null)
            {
                fFlags |= FileFlags.CRC;
            }
            if (SHA1 != null)
            {
                fFlags |= FileFlags.SHA1;
            }
            if (MD5 != null)
            {
                fFlags |= FileFlags.MD5;
            }
            if (SHA1CHD != null)
            {
                fFlags |= FileFlags.SHA1CHD;
            }
            if (MD5CHD != null)
            {
                fFlags |= FileFlags.MD5CHD;
            }
            if (!String.IsNullOrEmpty(Merge))
            {
                fFlags |= FileFlags.Merge;
            }
            if (!String.IsNullOrEmpty(Status))
            {
                fFlags |= FileFlags.Status;
            }
            if (ZipFileIndex >= 0)
            {
                fFlags |= FileFlags.ZipFileIndex;
            }
            if (ZipFileHeaderPosition != null)
            {
                fFlags |= FileFlags.ZipFileHeader;
            }
            if (CHDVersion != null)
            {
                fFlags |= FileFlags.CHDVersion;
            }

            bw.Write((UInt16)fFlags);

            if (Size != null)
            {
                bw.Write((ulong)Size);
            }
            if (CRC != null)
            {
                ArrByte.Write(bw, CRC);
            }
            if (SHA1 != null)
            {
                ArrByte.Write(bw, SHA1);
            }
            if (MD5 != null)
            {
                ArrByte.Write(bw, MD5);
            }
            if (SHA1CHD != null)
            {
                ArrByte.Write(bw, SHA1CHD);
            }
            if (MD5CHD != null)
            {
                ArrByte.Write(bw, MD5CHD);
            }
            if (!String.IsNullOrEmpty(Merge))
            {
                bw.Write(Merge);
            }
            if (!String.IsNullOrEmpty(Status))
            {
                bw.Write(Status);
            }
            if (ZipFileIndex >= 0)
            {
                bw.Write(ZipFileIndex);
            }
            if (ZipFileHeaderPosition != null)
            {
                bw.Write((long)ZipFileHeaderPosition);
            }
            if (CHDVersion != null)
            {
                bw.Write((uint)CHDVersion);
            }

            bw.Write((uint)_fileStatus);
        }
Exemple #24
0
        // CHDs as disk
        private static void ProcessDir(RvDir dir, int depth = 1)
        {
            string        indent = new string('\t', depth); // recursive indent
            List <string> disks  = new List <string> {
                string.Empty
            };

            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvDir item = dir.Child(i) as RvDir;
                if ((item != null) && (item.FileType == FileType.Dir))
                {
                    if ((disks.Count > 2) && (item.Name != disks[0])) // flush the last one if there were only CHDs in it
                    {
                        justCHDs(indent, disks);
                        disks.Clear();
                    }
                    // tabulate next disk list, if any
                    disks = new List <string> {
                        item.Name, item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description)
                    };
                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile chd = item.Child(j) as RvFile;
                        if ((chd != null) && (chd.FileType == FileType.File) && chd.Name.EndsWith(".chd"))
                        {
                            if (!string.IsNullOrEmpty(ArrByte.ToString(chd.SHA1CHD)))
                            {
                                disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" sha1=\"" + ArrByte.ToString(chd.SHA1CHD) + "\"/>");
                            }
                            else
                            {
                                disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" status=\"nodump\"/>");
                            }
                        }
                    }
                }
                if ((item != null) && (item.FileType == FileType.Zip))
                {
                    WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">");
                    string desc = item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description);
                    WriteLine(indent + "\t<description>" + clean(desc) + "</description>");

                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile file = item.Child(j) as RvFile;
                        if (file != null)
                        {
                            WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>");
                        }
                    }

                    if (disks.Count > 2) // take care of previous list of CHDs now
                    {
                        for (int j = 2; j < disks.Count; j++)
                        {
                            WriteLine(disks[j]);
                        }
                        disks.Clear();
                    }

                    WriteLine(indent + "</game>");
                }

                if ((item != null) && (item.FileType == FileType.Dir))
                {
                    if (numDisks(item) == 0) // only recurse when children are not CHDs
                    {
                        WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">");
                        ProcessDir(item, depth + 1);
                        WriteLine(indent + "</dir>");
                    }
                }
            }
            // check for one last CHDs-only game
            if (disks.Count > 2)
            {
                justCHDs(indent, disks);
            }
        }
Exemple #25
0
        private static int RomSortSHA1CHDFunc(RvFile a, RvFile b)
        {
            int retv = ArrByte.iCompare(a.SHA1CHD, b.SHA1CHD);

            return(retv);
        }
Exemple #26
0
 private static int CompareAltCRC(RvFile file, FileGroup fileGroup)
 {
     return(ArrByte.ICompare(file.CRC, fileGroup.AltCRC));
 }
Exemple #27
0
        public static void RemoveDupes(DatDir tDat, bool testName = true, bool testWithMergeName = false)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveDupes(mGame, testName);
                }
                else
                {
                    bool found = true;
                    while (found)
                    {
                        found = false;


                        for (int r = 0; r < mGame.ChildCount; r++)
                        {
                            DatFile df0 = (DatFile)mGame.Child(r);
                            for (int t = r + 1; t < mGame.ChildCount; t++)
                            {
                                DatFile df1 = (DatFile)mGame.Child(t);

                                if (testName && df0.Name != df1.Name)
                                {
                                    continue;
                                }
                                bool hasCRC = df0.CRC != null && df1.CRC != null;
                                if (hasCRC && !ArrByte.bCompare(df0.CRC, df1.CRC))
                                {
                                    continue;
                                }
                                bool hasSHA1 = df0.SHA1 != null && df1.SHA1 != null;
                                if (hasSHA1 && !ArrByte.bCompare(df0.SHA1, df1.SHA1))
                                {
                                    continue;
                                }
                                bool hasMD5 = df0.MD5 != null && df1.MD5 != null;
                                if (hasMD5 && !ArrByte.bCompare(df0.MD5, df1.MD5))
                                {
                                    continue;
                                }
                                if (!hasCRC && !hasSHA1 && !hasMD5)
                                {
                                    continue;
                                }

                                found = true;

                                string name0 = df0.Name;
                                string name1 = df1.Name;

                                bool nS0 = name0.Contains("\\");
                                bool ns1 = name1.Contains("\\");

                                if (nS0 && !ns1)
                                {
                                    mGame.ChildRemove(df0);
                                }
                                else if (!nS0 && ns1)
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else if (nS0 && ns1)
                                {
                                    string s0 = name0.Substring(0, name0.IndexOf("\\", StringComparison.Ordinal));
                                    string s1 = name1.Substring(0, name1.IndexOf("\\", StringComparison.Ordinal));
                                    if (s0 != s1)
                                    {
                                        mGame.ChildRemove(df1);
                                    }
                                    else
                                    {
                                        int res = AlphanumComparatorFast.Compare(name0, name1);
                                        mGame.ChildRemove(res >= 0 ? df0 : df1);
                                    }
                                }
                                else if ((name0 == name1) || (testWithMergeName && (name0 == df1.Merge)))
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else
                                {
                                    found = false;
                                    continue;
                                }
                                r = mGame.ChildCount;
                                t = mGame.ChildCount;
                            }
                        }
                    }
                }
            }
        }
Exemple #28
0
 private static int CompareAltSHA1(RvFile file, FileGroup fileGroup)
 {
     return(ArrByte.ICompare(file.SHA1, fileGroup.AltSHA1));
 }
Exemple #29
0
 private static int FamilySortSHA1(FileGroup fileGroup1, FileGroup fileGroup2)
 {
     return(ArrByte.ICompare(fileGroup1.SHA1, fileGroup2.SHA1));
 }
Exemple #30
0
 private static int FamilySortAltMD5(FileGroup fileGroup1, FileGroup fileGroup2)
 {
     return(ArrByte.ICompare(fileGroup1.AltMD5, fileGroup2.AltMD5));
 }