Beispiel #1
0
        private static void NewFileFound(RvBase fileChild, RvDir dbDir, int dbIndex)
        {
            if (fileChild == null)
            {
                ReportError.SendAndShow(Resources.FileScanning_CheckADir_Error_in_File_Scanning_Code);
                return;
            }

            // 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((RvDir)fileChild, false);
                break;

            case FileType.Dir:
                dbDir.ChildAdd(fileChild, dbIndex);
                CheckADir((RvDir)fileChild, true);
                break;

            case FileType.File:

                RvFile tChild = (RvFile)fileChild;
                // if we have not read the files CRC in the checking code, we need to read it now.
                if (tChild.GotStatus != GotStatus.FileLocked)
                {
                    if (!IsDeepScanned(tChild))
                    {
                        DeepScanFile(dbDir.FullName, tChild);
                    }
                    if (!IschdmanScanned(tChild) && (EScanLevel == eScanLevel.Level2))
                    {
                        ChdManCheck(dbDir.FullName, tChild);
                    }
                }
                dbDir.ChildAdd(fileChild, dbIndex);
                break;

            case FileType.ZipFile:
            case FileType.SevenZipFile:
                dbDir.ChildAdd(fileChild, dbIndex);
                break;

            default:
                throw new Exception("Unsuported file type " + fileChild.FileType);
            }
        }
Beispiel #2
0
        private static void LoadDiskFromDat(ref RvDir tGame, XmlNode romNode)
        {
            if (romNode.Attributes == null)
            {
                return;
            }


            RvFile tRom = new RvFile(FileType.File)
            {
                Dat     = tGame.Dat,
                Name    = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")) + ".chd",
                SHA1CHD = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                MD5CHD  = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("md5"), 32),
                Merge   = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("merge")),
                Status  = VarFix.ToLower(romNode.Attributes.GetNamedItem("status"))
            };

            if (tRom.SHA1CHD != null)
            {
                tRom.FileStatusSet(FileStatus.SHA1CHDFromDAT);
            }
            if (tRom.MD5CHD != null)
            {
                tRom.FileStatusSet(FileStatus.MD5CHDFromDAT);
            }

            tGame.ChildAdd(tRom);
        }
Beispiel #3
0
        private static void DatSetRemoveGameDir(RvDir newDir)
        {
            if (newDir.ChildCount != 1)
            {
                return;
            }

            RvDir child = newDir.Child(0) as RvDir;

            if (child.FileType != FileType.Dir)
            {
                return;
            }

            if (child.Game == null)
            {
                return;
            }

            newDir.ChildRemove(0);
            newDir.Game = child.Game;
            for (int i = 0; i < child.ChildCount; i++)
            {
                newDir.ChildAdd(child.Child(i), i);
            }
        }
Beispiel #4
0
        private static bool LoadDiskFromDat(ref RvDir tGame)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadRomFromDat_not_found_after_rom, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            if (DatFileLoader.Next.ToLower() != "name")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename);
                return(false);
            }


            string filename = VarFix.CleanFullFileName(DatFileLoader.Gn());
            RvFile tRom     = new RvFile(FileType.File)
            {
                Name = filename
            };

            DatFileLoader.Gn();
            tRom.Dat = tGame.Dat;

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "sha1": tRom.SHA1CHD = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 40); DatFileLoader.Gn(); break;

                case "md5": tRom.MD5CHD = VarFix.CleanMD5SHA1(DatFileLoader.Gn(), 32); DatFileLoader.Gn(); break;

                case "merge": tRom.Merge = VarFix.CleanFullFileName(DatFileLoader.Gn()); DatFileLoader.Gn(); break;

                case "flags": tRom.Status = VarFix.ToLower(DatFileLoader.Gn()); DatFileLoader.Gn(); break;

                case "nodump": tRom.Status = "nodump"; DatFileLoader.Gn(); break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadRomFromDat_not_known_in_rom, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }

            if (tRom.SHA1CHD != null)
            {
                tRom.FileStatusSet(FileStatus.SHA1CHDFromDAT);
            }
            if (tRom.MD5CHD != null)
            {
                tRom.FileStatusSet(FileStatus.MD5CHDFromDAT);
            }

            tGame.ChildAdd(tRom);

            return(true);
        }
Beispiel #5
0
        private static bool UpdateDatFile(RvDat file, bool autoAddDirectory, RvDir thisDirectory)
        {
            // Read the new Dat File into newDatFile
            RvDir newDatFile = DatReader.ReadInDatFile(file, _bgw);

            // If we got a valid Dat File back
            if ((newDatFile == null) || (newDatFile.Dat == null))
            {
                ReportError.Show("Error reading Dat " + file.GetData(RvDat.DatData.DatFullName));
                return(false);
            }

            newDatFile.Dat.AutoAddDirectory = autoAddDirectory;

            if ((autoAddDirectory || !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))) && (newDatFile.Dat.GetData(RvDat.DatData.DirSetup) != "noautodir"))
            {
                // if we are auto adding extra directorys then create a new directory.

                newDatFile.Name = !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)) ?
                                  newDatFile.Dat.GetData(RvDat.DatData.RootDir) : newDatFile.Dat.GetData(RvDat.DatData.DatName);

                newDatFile.DatStatus = DatStatus.InDatCollect;
                newDatFile.Tree      = new RvTreeRow();

                RvDir newDirectory = new RvDir(FileType.Dir)
                {
                    Dat = newDatFile.Dat
                };

                // add the DAT into this directory
                newDirectory.ChildAdd(newDatFile);
                newDatFile = newDirectory;
            }

            if (thisDirectory.Tree == null)
            {
                thisDirectory.Tree = new RvTreeRow();
            }

            RvDat conflictDat;

            if (MergeInDat(thisDirectory, newDatFile, out conflictDat, true))
            {
                ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatFullName) + " is trying to use the same dirctory and so will be ignored.");
                return(false);
            }

            //SetInDat(thisDirectory);

            // Add the new Dat
            thisDirectory.DirDatAdd(newDatFile.Dat);

            // Merge the files/directories in the Dat
            MergeInDat(thisDirectory, newDatFile, out conflictDat, false);
            return(true);
        }
Beispiel #6
0
        private static bool LoadRomFromDat(ref RvDir tGame, FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadRomFromDat_not_found_after_rom, DatFileLoader.Filename);
                return(false);
            }
            string line   = DatFileLoader.GnRest();
            string linelc = line.ToLower();

            int posName = linelc.IndexOf("name ", StringComparison.Ordinal);
            int posSize = linelc.IndexOf(" size ", posName + 5, StringComparison.Ordinal);
            int posDate = linelc.IndexOf(" date ", posSize + 6, StringComparison.Ordinal);
            int posCrc  = linelc.IndexOf(" crc ", posDate + 6, StringComparison.Ordinal);
            int posEnd  = linelc.IndexOf(" )", posCrc + 5, StringComparison.Ordinal);

            if (posName < 0 || posSize < 0 || posDate < 0 || posCrc < 0 || posEnd < 0)
            {
                DatFileLoader.Gn();
                return(false);
            }

            string name = line.Substring(posName + 5, posSize - (posName + 5));
            string size = line.Substring(posSize + 6, posDate - (posSize + 6));
            //string date = line.Substring(posDate + 6, posCrc - (posDate + 6));
            string crc = line.Substring(posCrc + 5, posEnd - (posCrc + 5));

            RvFile tRom = new RvFile(thisFileType)
            {
                Dat  = tGame.Dat,
                Name = VarFix.CleanFullFileName(name.Trim()),
                Size = VarFix.ULong(size.Trim()),
                CRC  = VarFix.CleanMD5SHA1(crc.Trim(), 8)
            };


            if (tRom.Size != null)
            {
                tRom.FileStatusSet(FileStatus.SizeFromDAT);
            }
            if (tRom.CRC != null)
            {
                tRom.FileStatusSet(FileStatus.CRCFromDAT);
            }

            tGame.ChildAdd(tRom);

            return(true);
        }
Beispiel #7
0
        private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode, FileType thisFileType)
        {
            if (romNode.Attributes == null)
            {
                return;
            }

            XmlNode name     = romNode.Attributes.GetNamedItem("name");
            string  loadflag = VarFix.String(romNode.Attributes.GetNamedItem("loadflag"));

            if (name != null)
            {
                RvFile tRom = new RvFile(thisFileType) // changed
                {
                    Name   = VarFix.CleanFullFileName(name),
                    Size   = VarFix.ULong(romNode.Attributes.GetNamedItem("size")),
                    CRC    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8),
                    SHA1   = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                    Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")),

                    Dat = tGame.Dat
                };

                if (tRom.Size != null)
                {
                    tRom.FileStatusSet(FileStatus.SizeFromDAT);
                }
                if (tRom.CRC != null)
                {
                    tRom.FileStatusSet(FileStatus.CRCFromDAT);
                }
                if (tRom.SHA1 != null)
                {
                    tRom.FileStatusSet(FileStatus.SHA1FromDAT);
                }

                _indexContinue = tGame.ChildAdd(tRom);
            }
            else if (loadflag.ToLower() == "continue")
            {
                RvFile tZippedFile = (RvFile)tGame.Child(_indexContinue);
                tZippedFile.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size"));
            }
        }
Beispiel #8
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--;
                    }
                }
            }
        }
Beispiel #9
0
        private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode, FileType thisFileType)
        {
            if (romNode.Attributes == null)
            {
                return;
            }


            RvFile tRom = new RvFile(thisFileType)
            {
                Dat    = tGame.Dat,
                Size   = VarFix.ULong(romNode.Attributes.GetNamedItem("size")),
                Name   = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")),
                CRC    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8),
                SHA1   = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                MD5    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("md5"), 32),
                Merge  = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("merge")),
                Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status"))
            };

            if (tRom.Size != null)
            {
                tRom.FileStatusSet(FileStatus.SizeFromDAT);
            }
            if (tRom.CRC != null)
            {
                tRom.FileStatusSet(FileStatus.CRCFromDAT);
            }
            if (tRom.SHA1 != null)
            {
                tRom.FileStatusSet(FileStatus.SHA1FromDAT);
            }
            if (tRom.MD5 != null)
            {
                tRom.FileStatusSet(FileStatus.MD5FromDAT);
            }

            tGame.ChildAdd(tRom);
        }
Beispiel #10
0
        private static bool LoadDirFromDat(ref RvDir tDat, ref FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            if (DatFileLoader.Next.ToLower() != "name")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename);
                return(false);
            }

            RvDir parent = tDat;

            string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest());

            while (fullname.Contains("/"))
            {
                int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                string dir        = fullname.Substring(0, firstSlash);
                dir = VarFix.CleanFileName(dir);

                fullname = fullname.Substring(firstSlash + 1);
                if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                {
                    Name = dir
                }, out int index) == 0)
                {
                    parent = (RvDir)parent.Child(index);
                }
                else
                {
                    RvDir tpDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir,
                        DatStatus = DatStatus.InDatCollect,
                        Dat       = tDat.Dat,
                        Tree      = new RvTreeRow()
                    };
                    parent.ChildAdd(tpDir, index);
                    parent = tpDir;
                }
            }

            RvDir tDir = new RvDir(FileType.Dir)
            {
                Name = fullname
            };

            DatFileLoader.Gn();
            tDir.DatStatus = DatStatus.InDatCollect;
            tDir.Dat       = tDat.Dat;

            if (parent.ChildNameSearch(tDir, out int index1) == 0)
            {
                tDir = (RvDir)parent.Child(index1);
            }
            else
            {
                parent.ChildAdd(tDir, index1);
            }

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "dir":
                    DatFileLoader.Gn();
                    if (!LoadDirFromDat(ref tDir, ref thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                case "game":
                    DatFileLoader.Gn();
                    if (!LoadGameFromDat(ref tDir, false, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                case "resource":
                    DatFileLoader.Gn();
                    if (!LoadGameFromDat(ref tDir, true, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadDirFromDat_Error_Keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadDirFromDat_not_know_in_dir, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }
            return(true);
        }
Beispiel #11
0
        private static bool LoadGameFromDat(ref RvDir tDat, FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            string snext = DatFileLoader.Next.ToLower();

            if (snext != "name")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename);
                return(false);
            }

            RvDir parent = tDat;

            string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest());

            if (_cleanFileNames)
            {
                fullname = fullname.Replace("/", "-");
            }

            while (fullname.Contains("/"))
            {
                int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                string dir        = fullname.Substring(0, firstSlash);
                fullname = fullname.Substring(firstSlash + 1);
                int index;
                if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                {
                    Name = dir
                }, out index) == 0)
                {
                    parent = (RvDir)parent.Child(index);
                }
                else
                {
                    RvDir tpDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir,
                        DatStatus = DatStatus.InDatCollect,
                        Dat       = tDat.Dat,
                        Tree      = new RvTreeRow()
                    };
                    parent.ChildAdd(tpDir, index);
                    parent = tpDir;
                }
            }

            if (fullname.Length > 4 && fullname.ToLower().Substring(fullname.Length - 4, 4) == ".zip")
            {
                fullname = fullname.Substring(0, fullname.Length - 4);
            }

            RvDir tDir = new RvDir(thisFileType == FileType.File ? FileType.Dir : FileType.Zip)
            {
                Name = fullname
            };

            DatFileLoader.Gn();
            tDir.Game      = new RvGame();
            tDir.DatStatus = DatStatus.InDatCollect;
            tDir.Dat       = tDat.Dat;
            int index1;

            string testName  = tDir.Name;
            int    nameCount = 0;

            while (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir.Name = testName + "_" + nameCount;
                nameCount++;
            }
            parent.ChildAdd(tDir, index1);


            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "file":
                    DatFileLoader.Gn();
                    if (!LoadRomFromDat(ref tDir, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadGameFromDat_not_known_in_game, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }


            return(true);
        }
Beispiel #12
0
        private static void UpdateDirs(RvDir dbDir, RvDir fileDir)
        {
            int dbIndex   = 0;
            int scanIndex = 0;

            dbDir.DatStatus = DatStatus.InDatCollect;
            if (dbDir.Tree == null)
            {
                Debug.WriteLine("Adding Tree View to " + dbDir.Name);
                dbDir.Tree = new RvTreeRow();
            }


            Debug.WriteLine("");
            Debug.WriteLine("Now scanning dirs");

            while (dbIndex < dbDir.ChildCount || scanIndex < fileDir.ChildCount)
            {
                RvBase dbChild   = null;
                RvBase fileChild = null;
                int    res       = 0;

                if (dbIndex < dbDir.ChildCount && scanIndex < fileDir.ChildCount)
                {
                    dbChild   = dbDir.Child(dbIndex);
                    fileChild = fileDir.Child(scanIndex);
                    res       = DBHelper.CompareName(dbChild, fileChild);
                    Debug.WriteLine("Checking " + dbChild.Name + " : and " + fileChild.Name + " : " + res);
                }
                else if (scanIndex < fileDir.ChildCount)
                {
                    fileChild = fileDir.Child(scanIndex);
                    res       = 1;
                    Debug.WriteLine("Checking : and " + fileChild.Name + " : " + res);
                }
                else if (dbIndex < dbDir.ChildCount)
                {
                    dbChild = dbDir.Child(dbIndex);
                    res     = -1;
                }
                switch (res)
                {
                case 0:
                    // found a matching directory in DatRoot So recurse back into it

                    if (dbChild.GotStatus == GotStatus.Got)
                    {
                        if (dbChild.Name != fileChild.Name)              // check if the case of the Item in the DB is different from the Dat Root Actual filename
                        {
                            if (!string.IsNullOrEmpty(dbChild.FileName)) // if we do not already have a different case name stored
                            {
                                dbChild.FileName = dbChild.Name;         // copy the DB filename to the FileName
                            }
                            else                                         // We already have a different case filename found in RomRoot
                            {
                                if (dbChild.FileName == fileChild.Name)  // check if the Datroot name does now match the name in the DB Filename
                                {
                                    dbChild.FileName = null;             // if it does undo the BadCase Flag
                                }
                            }
                            dbChild.Name = fileChild.Name;     // Set the db Name to match the Datroot Name.
                        }
                    }
                    else
                    {
                        dbChild.Name = fileChild.Name;
                    }

                    UpdateDatList((RvDir)dbChild, (RvDir)fileChild);
                    dbIndex++;
                    scanIndex++;
                    break;

                case 1:
                    // found a new directory in Dat
                    RvDir tDir = new RvDir(FileType.Dir)
                    {
                        Name      = fileChild.Name,
                        Tree      = new RvTreeRow(),
                        DatStatus = DatStatus.InDatCollect,
                    };
                    dbDir.ChildAdd(tDir, dbIndex);
                    Debug.WriteLine("Adding new Dir and Calling back in to check this DIR " + tDir.Name);
                    UpdateDatList(tDir, (RvDir)fileChild);

                    dbIndex++;
                    scanIndex++;
                    break;

                case -1:
                    // all files
                    dbIndex++;
                    break;
                }
            }
        }
Beispiel #13
0
        /*
         * private static void SetInDat(RvDir tDir)
         * {
         *  tDir.DatStatus = DatStatus.InDatCollect;
         *  if (tDir.Parent != null)
         *      SetInDat(tDir.Parent);
         * }
         */

        private static Boolean MergeInDat(RvDir dbDat, RvDir newDat, out RvDat conflict, bool checkOnly)
        {
            conflict = null;
            int dbIndex  = 0;
            int newIndex = 0;

            while (dbIndex < dbDat.ChildCount || newIndex < newDat.ChildCount)
            {
                RvBase dbChild     = null;
                RvBase 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)
                    {
                        SendAndShowDat(Resources.DatUpdate_MergeInDat_Error_in_Logic, dbDat.FullName);
                        break;
                    }


                    List <RvBase> dbDats       = new List <RvBase>();
                    List <RvBase> newDats      = new List <RvBase>();
                    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);
                        }

                        SendAndShowDat(Resources.DatUpdate_MergeInDat_Unkown_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 = FullCompare(dbDats[indexDbDats], newDats[indexNewDats]);
                                if (!matched)
                                {
                                    continue;
                                }

                                dbDats[indexDbDats].DatAdd(newDats[indexNewDats]);

                                FileType ft = dbChild.FileType;

                                if (ft == FileType.Zip || ft == FileType.Dir)
                                {
                                    RvDir dChild    = (RvDir)dbChild;
                                    RvDir dNewChild = (RvDir)newDatChild;
                                    MergeInDat(dChild, dNewChild, out conflict, checkOnly);
                                }

                                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);
        }
Beispiel #14
0
        private static bool RecursiveDatTree(RvDir tDir, out int datCount)
        {
            datCount = 0;
            string strPath = tDir.DatFullName;

            if (!Directory.Exists(strPath))
            {
                ReportError.Show(Resources.DatUpdate_UpdateDatList_Path + strPath + Resources.DatUpdate_UpdateDatList_Not_Found);
                return(false);
            }

            DirectoryInfo oDir = new DirectoryInfo(strPath);

            FileInfo[] oFilesIn = oDir.GetFiles("*.dat", false);
            datCount += oFilesIn.Length;
            foreach (FileInfo file in oFilesIn)
            {
                RvDat tDat = new RvDat();
                tDat.AddData(RvDat.DatData.DatFullName, file.FullName);
                tDat.TimeStamp = file.LastWriteTime;
                tDir.DirDatAdd(tDat);
            }


            oFilesIn  = oDir.GetFiles("*.xml", false);
            datCount += oFilesIn.Length;
            foreach (FileInfo file in oFilesIn)
            {
                RvDat tDat = new RvDat();
                tDat.AddData(RvDat.DatData.DatFullName, file.FullName);
                tDat.TimeStamp = file.LastWriteTime;
                tDir.DirDatAdd(tDat);
            }

            if (tDir.DirDatCount > 1)
            {
                for (int i = 0; i < tDir.DirDatCount; i++)
                {
                    tDir.DirDat(i).AutoAddDirectory = true;
                }
            }

            DirectoryInfo[] oSubDir = oDir.GetDirectories(false);

            foreach (DirectoryInfo t in oSubDir)
            {
                RvDir cDir = new RvDir(FileType.Dir)
                {
                    Name = t.Name, DatStatus = DatStatus.InDatCollect
                };
                int index = tDir.ChildAdd(cDir);

                int retDatCount;

                RecursiveDatTree(cDir, out retDatCount);
                datCount += retDatCount;

                if (retDatCount == 0)
                {
                    tDir.ChildRemove(index);
                }
            }

            return(true);
        }
Beispiel #15
0
        private static void CheckADir(RvDir dbDir, bool report)
        {
            if (_cacheSaveTimer.Elapsed.TotalMinutes > Settings.CacheSaveTimePeriod)
            {
                _bgw.ReportProgress(0, "Saving Cache");
                DB.Write();
                _bgw.ReportProgress(0, "Saving Cache Complete");
                _cacheSaveTimer.Reset();
                _cacheSaveTimer.Start();
            }

            string fullDir = dbDir.FullName;

            if (report)
            {
                _bgw.ReportProgress(0, new bgwText2(fullDir));
            }

            DatStatus chechingDatStatus = dbDir.IsInToSort ? DatStatus.InToSort : DatStatus.NotInDat;

            // 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.
            RvDir 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:
            {
                fileDir = new RvDir(ft);

                // open the zip file
                ZipFile checkZ = new ZipFile();

                ZipReturn zr = checkZ.ZipFileOpen(fullDir, dbDir.TimeStamp, true);

                if (zr == ZipReturn.ZipGood)
                {
                    dbDir.ZipStatus = checkZ.ZipStatus;

                    // to be Scanning a ZIP file means it is either new or has changed.
                    // as the code below only calls back here if that is true.
                    //
                    // Level1: Only use header CRC's
                    // Just get the CRC for the ZIP headers.
                    //
                    // Level2: Fully checksum changed only files
                    // We know this file has been changed to do a full checksum scan.
                    //
                    // Level3: Fully checksum everything
                    // So do a full checksum scan.
                    if (EScanLevel == eScanLevel.Level2 || EScanLevel == eScanLevel.Level3)
                    {
                        checkZ.DeepScan();
                    }

                    // add all of the file information from the zip file into scanDir
                    for (int i = 0; i < checkZ.LocalFilesCount(); i++)
                    {
                        RvFile tFile = new RvFile(DBTypeGet.FileFromDir(ft))
                        {
                            Name                  = checkZ.Filename(i),
                            ZipFileIndex          = i,
                            ZipFileHeaderPosition = checkZ.LocalHeader(i),
                            Size                  = checkZ.UncompressedSize(i),
                            CRC = checkZ.CRC32(i)
                        };
                        // all 3 levels read the CRC from the ZIP header
                        tFile.SetStatus(chechingDatStatus, GotStatus.Got);
                        tFile.FileStatusSet(FileStatus.SizeFromHeader | FileStatus.CRCFromHeader);

                        // if we are in level 2 or level 3 then do a full CheckSum Scan.
                        if (EScanLevel == eScanLevel.Level2 || EScanLevel == eScanLevel.Level3)
                        {
                            // DeepScan will return ZipReturn.ZipCRCDecodeError if the headers CRC and
                            // the actual CRC do not match.
                            // So we just need to set the MD5 and SHA1 from the ZIP file.
                            zr = checkZ.FileStatus(i);
                            if (zr == ZipReturn.ZipUntested)
                            {
                                _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir + " : " + checkZ.Filename(i)));
                            }
                            else if (zr != ZipReturn.ZipGood)
                            {
                                _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir + " : " + checkZ.Filename(i)));
                                tFile.GotStatus = GotStatus.Corrupt;
                            }
                            else
                            {
                                tFile.MD5  = checkZ.MD5(i);
                                tFile.SHA1 = checkZ.SHA1(i);
                                tFile.FileStatusSet(FileStatus.SizeVerified | FileStatus.CRCVerified | FileStatus.SHA1Verified | FileStatus.MD5Verified);
                            }
                        }

                        fileDir.ChildAdd(tFile);
                    }
                }
                else if (zr == ZipReturn.ZipFileLocked)
                {
                    _bgw.ReportProgress(0, new bgwShowError(fullDir, "Zip File Locked"));
                    dbDir.TimeStamp = 0;
                    dbDir.GotStatus = GotStatus.FileLocked;
                }
                else
                {
                    _bgw.ReportProgress(0, new bgwShowCorrupt(zr, fullDir));
                    dbDir.GotStatus = GotStatus.Corrupt;
                }
                checkZ.ZipFileClose();
            }
            break;

            case FileType.Dir:
            {
                fileDir = new RvDir(FileType.Dir);


                DirectoryInfo   oDir   = new DirectoryInfo(fullDir);
                DirectoryInfo[] oDirs  = oDir.GetDirectories();
                FileInfo[]      oFiles = oDir.GetFiles();

                // add all the subdirectories into scanDir
                foreach (DirectoryInfo dir in oDirs)
                {
                    RvBase tDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir.Name,
                        TimeStamp = dir.LastWriteTime,
                    };
                    tDir.SetStatus(chechingDatStatus, GotStatus.Got);
                    fileDir.ChildAdd(tDir);
                }

                // add all the files into scanDir
                foreach (FileInfo oFile in oFiles)
                {
                    // if we find any zip files add them as zip files.
                    string fExt = Path.GetExtension(oFile.Name);
                    switch (fExt.ToLower())
                    {
                    case ".zip":
                    {
                        RvDir tGame = new RvDir(FileType.Zip)
                        {
                            Name      = Path.GetFileNameWithoutExtension(oFile.Name),
                            TimeStamp = oFile.LastWriteTime,
                        };
                        tGame.SetStatus(chechingDatStatus, GotStatus.Got);
                        fileDir.ChildAdd(tGame);
                    }
                    break;

                    default:
                    {
                        string fName = oFile.Name;
                        if (fName == "__RomVault.tmp")
                        {
                            File.Delete(oFile.FullName);
                            continue;
                        }

                        // Scanning a file
                        //
                        // Level1 & 2 : (are the same for files) Fully checksum changed only files
                        // Here we are just getting the TimeStamp of the File, and later
                        // if the TimeStamp was not matched we will have to read the files CRC, MD5 & SHA1
                        //
                        // Level3: Fully checksum everything
                        // Get everything about the file right here so
                        // read CRC, MD5 & SHA1


                        // add all the files in the sub-directory to scanDir
                        RvFile tFile = new RvFile(FileType.File)
                        {
                            Name      = fName,
                            Size      = (ulong)oFile.Length,
                            TimeStamp = oFile.LastWriteTime
                        };

                        tFile.FileStatusSet(FileStatus.SizeVerified);

                        int errorCode = CHD.CheckFile(oFile, out tFile.SHA1CHD, out tFile.MD5CHD, out tFile.CHDVersion);

                        if (errorCode == 0)
                        {
                            if (tFile.SHA1CHD != null)
                            {
                                tFile.FileStatusSet(FileStatus.SHA1CHDFromHeader);
                            }
                            if (tFile.MD5CHD != null)
                            {
                                tFile.FileStatusSet(FileStatus.MD5CHDFromHeader);
                            }

                            tFile.SetStatus(chechingDatStatus, GotStatus.Got);

                            // if we are scanning at Level3 then we get all the info here
                            if (EScanLevel == eScanLevel.Level3)
                            {
                                DeepScanFile(fullDir, tFile);
                                ChdManCheck(fullDir, tFile);
                            }
                        }
                        else if (errorCode == 32)
                        {
                            tFile.GotStatus = GotStatus.FileLocked;
                            _bgw.ReportProgress(0, new bgwShowError(fullDir, "File Locked"));
                        }
                        else
                        {
                            string filename = Path.Combine(fullDir, tFile.Name);
                            ReportError.Show("File: " + filename + " Error: " + new Win32Exception(errorCode).Message + ". Scan Aborted.");
                            _fileErrorAbort = true;
                            return;
                        }
                        fileDir.ChildAdd(tFile);
                    }
                    break;
                    }
                }
            }
            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)
            {
                _bgw.ReportProgress(0, new bgwSetRange2(fileDir.ChildCount - 1));

                _bgw.ReportProgress(0, new bgwRange2Visible(true));
            }

            if (!DBTypeGet.isCompressedDir(ft) && _bgw.CancellationPending)
            {
                return;
            }

            Compare(dbDir, fileDir, report, true);
        }
Beispiel #16
0
        private static void DatSetCreateSubDirs(RvDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                if (tDat.Child(g).FileType == FileType.Zip)
                {
                    continue;
                }

                RvDir datGame = (RvDir)tDat.Child(g);

                // first do a quick check to see if anything needs done.
                bool fixNeeded = false;
                for (int r = 0; r < datGame.ChildCount; r++)
                {
                    fixNeeded = datGame.Child(r).Name.Contains("/");

                    if (fixNeeded)
                    {
                        break;
                    }
                }
                // if nothing needs done skip to next game
                if (!fixNeeded)
                {
                    continue;
                }


                RvDir fixedGame = new RvDir(FileType.Dir);
                while (datGame.ChildCount > 0)
                {
                    RvBase nextChild = datGame.Child(0);
                    datGame.ChildRemove(0);
                    if (nextChild.GetType() == typeof(RvFile))
                    {
                        RvFile tFile = (RvFile)nextChild;
                        if (tFile.Name.Contains("/"))
                        {
                            RvDir tBase = fixedGame;
                            Debug.WriteLine("tFile " + tFile.TreeFullName);
                            while (tFile.Name.Contains("/"))
                            {
                                int    dirIndex = tFile.Name.IndexOf("/", StringComparison.Ordinal);
                                string dirName  = tFile.Name.Substring(0, dirIndex);
                                RvDir  tDir     = new RvDir(FileType.Dir)
                                {
                                    Name      = dirName,
                                    DatStatus = DatStatus.InDatCollect,
                                    Dat       = datGame.Dat
                                };
                                int index;
                                if (tBase.ChildNameSearch(tDir, out index) != 0)
                                {
                                    tBase.ChildAdd(tDir, index);
                                }
                                tBase      = (RvDir)tBase.Child(index);
                                tFile.Name = tFile.Name.Substring(tFile.Name.IndexOf("/", StringComparison.Ordinal) + 1);
                            }
                            tBase.ChildAdd(tFile);
                        }
                        else
                        {
                            fixedGame.ChildAdd(nextChild);
                        }
                    }
                    else
                    {
                        fixedGame.ChildAdd(nextChild);
                    }
                }

                for (int r = 0; r < fixedGame.ChildCount; r++)
                {
                    datGame.ChildAdd(fixedGame.Child(r), r);
                }
            }
        }
Beispiel #17
0
        private static void LoadGameFromDat(ref RvDir tDat, XmlNode gameNode, FileType thisFileType)
        {
            if (gameNode.Attributes == null)
            {
                return;
            }

            RvDir parent = tDat;

            RvDir tDir = new RvDir(DBTypeGet.DirFromFile(thisFileType))
            {
                Name      = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("name")),
                Game      = new RvGame(),
                Dat       = tDat.Dat,
                DatStatus = DatStatus.InDatCollect
            };


            tDir.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.Year, VarFix.CleanFileName(gameNode.SelectSingleNode("year")));
            tDir.Game.AddData(RvGame.GameData.Manufacturer, VarFix.CleanFileName(gameNode.SelectSingleNode("publisher")));



            RvDir tDirCHD = new RvDir(FileType.Dir)
            {
                Name      = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("name")),
                Game      = new RvGame(),
                Dat       = tDat.Dat,
                DatStatus = DatStatus.InDatCollect
            };

            tDirCHD.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDirCHD.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDirCHD.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDirCHD.Game.AddData(RvGame.GameData.Year, VarFix.CleanFileName(gameNode.SelectSingleNode("year")));
            tDirCHD.Game.AddData(RvGame.GameData.Manufacturer, VarFix.CleanFileName(gameNode.SelectSingleNode("publisher")));



            int    index1;
            string testName  = tDir.Name;
            int    nameCount = 0;

            while (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir.Name = testName + "_" + nameCount;
                nameCount++;
            }
            tDirCHD.Name = tDir.Name;


            XmlNodeList partNodeList = gameNode.SelectNodes("part");

            if (partNodeList == null)
            {
                return;
            }

            for (int iP = 0; iP < partNodeList.Count; iP++)
            {
                _indexContinue = -1;
                XmlNodeList dataAreaNodeList = partNodeList[iP].SelectNodes("dataarea");
                if (dataAreaNodeList != null)
                {
                    for (int iD = 0; iD < dataAreaNodeList.Count; iD++)
                    {
                        XmlNodeList romNodeList = dataAreaNodeList[iD].SelectNodes("rom");
                        if (romNodeList != null)
                        {
                            for (int iR = 0; iR < romNodeList.Count; iR++)
                            {
                                LoadRomFromDat(ref tDir, romNodeList[iR], thisFileType);
                            }
                        }
                    }
                }
            }
            for (int iP = 0; iP < partNodeList.Count; iP++)
            {
                XmlNodeList diskAreaNodeList = partNodeList[iP].SelectNodes("diskarea");
                if (diskAreaNodeList != null)
                {
                    for (int iD = 0; iD < diskAreaNodeList.Count; iD++)
                    {
                        XmlNodeList romNodeList = diskAreaNodeList[iD].SelectNodes("disk");
                        if (romNodeList != null)
                        {
                            for (int iR = 0; iR < romNodeList.Count; iR++)
                            {
                                LoadDiskFromDat(ref tDirCHD, romNodeList[iR]);
                            }
                        }
                    }
                }
            }

            if (tDir.ChildCount > 0)
            {
                parent.ChildAdd(tDir, index1);
            }
            if (tDirCHD.ChildCount > 0)
            {
                parent.ChildAdd(tDirCHD, index1);
            }
        }
Beispiel #18
0
        private static bool LoadGameFromDat(ref RvDir tDat, bool bolresource, FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            string snext = DatFileLoader.Next.ToLower();

            string pathextra = "";

            if (snext == "rebuildto")
            {
                pathextra = VarFix.CleanFullFileName(DatFileLoader.Gn());
                DatFileLoader.Gn();
                snext = DatFileLoader.Next.ToLower();
            }

            if (snext != "name")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename);
                return(false);
            }

            RvDir parent = tDat;

            string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest());

            if (_cleanFileNames)
            {
                fullname = fullname.Replace("/", "-");
            }

            if (!string.IsNullOrEmpty(pathextra))
            {
                fullname = pathextra + "/" + fullname;
            }

            while (fullname.Contains("/"))
            {
                int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                string dir        = fullname.Substring(0, firstSlash);
                fullname = fullname.Substring(firstSlash + 1);
                if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                {
                    Name = dir
                }, out int index) == 0)
                {
                    parent = (RvDir)parent.Child(index);
                }
                else
                {
                    RvDir tpDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir,
                        DatStatus = DatStatus.InDatCollect,
                        Dat       = tDat.Dat,
                        Tree      = new RvTreeRow()
                    };
                    parent.ChildAdd(tpDir, index);
                    parent = tpDir;
                }
            }

            RvDir tDir = new RvDir(thisFileType == FileType.File ? FileType.Dir : FileType.Zip)
            {
                Name      = fullname,
                DatStatus = DatStatus.InDatCollect,
                Dat       = tDat.Dat
            };

            string testName  = tDir.Name;
            int    nameCount = 0;
            int    index1;

            while (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir.Name = testName + "_" + nameCount;
                nameCount++;
            }

            DatFileLoader.Gn();
            tDir.Game = new RvGame();
            tDir.Game.AddData(RvGame.GameData.IsBios, bolresource ? "Yes" : "No");

            RvDir tDirCHD = new RvDir(FileType.Dir)
            {
                Name      = tDir.Name,
                DatStatus = tDir.DatStatus,
                Dat       = tDir.Dat,
                Game      = tDir.Game
            };

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "romof":
                    tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(DatFileLoader.GnRest()));
                    DatFileLoader.Gn();
                    break;

                case "description":
                    tDir.Game.AddData(RvGame.GameData.Description, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "sourcefile":
                    tDir.Game.AddData(RvGame.GameData.Sourcefile, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "cloneof":
                    tDir.Game.AddData(RvGame.GameData.CloneOf, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "sampleof":
                    tDir.Game.AddData(RvGame.GameData.SampleOf, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "board":
                    tDir.Game.AddData(RvGame.GameData.Board, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "year":
                    tDir.Game.AddData(RvGame.GameData.Year, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "manufacturer":
                    tDir.Game.AddData(RvGame.GameData.Manufacturer, DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "serial":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "rebuildto":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "sample":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "biosset":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "chip":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "video":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "sound":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "input":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "dipswitch":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "driver":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;


                case "rom":
                    DatFileLoader.Gn();
                    if (!LoadRomFromDat(ref tDir, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                case "disk":
                    DatFileLoader.Gn();
                    if (!LoadDiskFromDat(ref tDirCHD))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                case "archive":
                    DatFileLoader.Gn();
                    if (!LoadArchiveFromDat())
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadGameFromDat_not_known_in_game, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }

            if (tDir.ChildCount > 0)
            {
                parent.ChildAdd(tDir, index1);
            }
            if (tDirCHD.ChildCount > 0)
            {
                parent.ChildAdd(tDirCHD);
            }

            return(true);
        }
Beispiel #19
0
        private static void DatSetMergeSets(RvDir tDat)
        {
            for (int g = tDat.ChildCount - 1; g >= 0; g--)
            {
                RvDir mGame = (RvDir)tDat.Child(g);

                if (mGame.Game == null)
                {
                    DatSetMergeSets(mGame);
                    continue;
                }

                List <RvDir> lstParentGames = new List <RvDir>();
                FindParentSet(mGame, tDat, ref lstParentGames);
                while (lstParentGames.Count > 0 && lstParentGames[lstParentGames.Count - 1].Game.GetData(RvGame.GameData.IsBios).ToLower() == "yes")
                {
                    lstParentGames.RemoveAt(lstParentGames.Count - 1);
                }

                if (lstParentGames.Count <= 0)
                {
                    continue;
                }

                RvDir romofGame = lstParentGames[lstParentGames.Count - 1];

                bool founderror = false;
                for (int r = 0; r < mGame.ChildCount; r++)
                {
                    string name      = mGame.Child(r).Name;
                    string mergename = ((RvFile)mGame.Child(r)).Merge;

                    for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                    {
                        if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) &&
                            (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) != 0 ||
                             ((RvFile)mGame.Child(r)).Size != ((RvFile)romofGame.Child(r1)).Size))
                        {
                            founderror = true;
                        }
                    }
                }
                if (founderror)
                {
                    mGame.Game.DeleteData(RvGame.GameData.RomOf);
                    continue;
                }

                for (int r = 0; r < mGame.ChildCount; r++)
                {
                    string name      = mGame.Child(r).Name;
                    string mergename = ((RvFile)mGame.Child(r)).Merge;

                    bool found = false;
                    for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                    {
                        if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) &&
                            (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) == 0 &&
                             ((RvFile)mGame.Child(r)).Size == ((RvFile)romofGame.Child(r1)).Size))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        romofGame.ChildAdd(mGame.Child(r));
                    }
                }
                tDat.ChildRemove(g);
            }
        }
Beispiel #20
0
        private static void LoadDirFromDat(ref RvDir tDat, XmlNode dirNode, FileType thisFileType)
        {
            if (dirNode.Attributes == null)
            {
                return;
            }

            RvDir parent = tDat;

            string fullname = VarFix.CleanFullFileName(dirNode.Attributes.GetNamedItem("name"));

            while (fullname.Contains("/"))
            {
                int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                string dir        = fullname.Substring(0, firstSlash);
                dir = VarFix.CleanFileName(dir);

                fullname = fullname.Substring(firstSlash + 1);
                int index;
                if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                {
                    Name = dir
                }, out index) == 0)
                {
                    parent = (RvDir)parent.Child(index);
                }
                else
                {
                    RvDir tpDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir,
                        DatStatus = DatStatus.InDatCollect,
                        Dat       = tDat.Dat,
                        Tree      = new RvTreeRow()
                    };
                    parent.ChildAdd(tpDir, index);
                    parent = tpDir;
                }
            }

            RvDir tDir = new RvDir(FileType.Dir)
            {
                Name      = fullname,
                DatStatus = DatStatus.InDatCollect,
                Dat       = tDat.Dat,
                Tree      = new RvTreeRow()
            };

            int index1;

            if (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir = (RvDir)parent.Child(index1);
            }
            else
            {
                tDat.ChildAdd(tDir, index1);
            }

            XmlNodeList dirNodeList = dirNode.SelectNodes("dir");

            if (dirNodeList != null)
            {
                for (int i = 0; i < dirNodeList.Count; i++)
                {
                    LoadDirFromDat(ref tDir, dirNodeList[i], thisFileType);
                }
            }

            XmlNodeList gameNodeList = dirNode.SelectNodes("game");

            if (gameNodeList != null)
            {
                for (int i = 0; i < gameNodeList.Count; i++)
                {
                    LoadGameFromDat(ref tDir, gameNodeList[i], thisFileType);
                }
            }
        }
Beispiel #21
0
        private static void LoadGameFromDat(ref RvDir tDat, XmlNode gameNode, FileType thisFileType)
        {
            if (gameNode.Attributes == null)
            {
                return;
            }

            RvDir parent = tDat;
            RvDir tDir;
            int   index1 = 0;

            string fullname = VarFix.CleanFullFileName(gameNode.Attributes.GetNamedItem("name"));

            if (_cleanFileNames)
            {
                fullname = fullname.Replace("/", "-");
            }
            else
            {
                while (fullname.Contains("/"))
                {
                    int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                    string dir        = fullname.Substring(0, firstSlash);
                    dir = VarFix.CleanFileName(dir);

                    fullname = fullname.Substring(firstSlash + 1);
                    int index;
                    if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                    {
                        Name = dir
                    }, out index) == 0)
                    {
                        parent = (RvDir)parent.Child(index);
                    }
                    else
                    {
                        RvDir tpDir = new RvDir(FileType.Dir)
                        {
                            Name      = dir,
                            DatStatus = DatStatus.InDatCollect,
                            Dat       = tDat.Dat,
                            Tree      = new RvTreeRow()
                        };
                        parent.ChildAdd(tpDir, index);
                        parent = tpDir;
                    }
                }
            }

            tDir = new RvDir(DBTypeGet.DirFromFile(thisFileType))
            {
                Name      = fullname,
                DatStatus = DatStatus.InDatCollect,
                Dat       = tDat.Dat
            };

            string testName  = tDir.Name;
            int    nameCount = 0;

            while (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir.Name = testName + "_" + nameCount;
                nameCount++;
            }

            tDir.Game = new RvGame();
            tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("romof")));
            tDir.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDir.Game.AddData(RvGame.GameData.Sourcefile, VarFix.String(gameNode.Attributes.GetNamedItem("sourcefile")));
            tDir.Game.AddData(RvGame.GameData.IsBios, VarFix.String(gameNode.Attributes.GetNamedItem("isbios")));
            tDir.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.SampleOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("sampleof")));
            tDir.Game.AddData(RvGame.GameData.Board, VarFix.String(gameNode.Attributes.GetNamedItem("board")));
            tDir.Game.AddData(RvGame.GameData.Year, VarFix.String(gameNode.SelectSingleNode("year")));
            tDir.Game.AddData(RvGame.GameData.Manufacturer, VarFix.String(gameNode.SelectSingleNode("manufacturer")));

            XmlNode trurip = gameNode.SelectSingleNode("trurip");

            if (trurip != null)
            {
                tDir.Game.AddData(RvGame.GameData.Trurip, "yes");
                tDir.Game.AddData(RvGame.GameData.Year, VarFix.String(trurip.SelectSingleNode("year")));
                tDir.Game.AddData(RvGame.GameData.Publisher, VarFix.String(trurip.SelectSingleNode("publisher")));
                tDir.Game.AddData(RvGame.GameData.Developer, VarFix.String(trurip.SelectSingleNode("developer")));
                tDir.Game.AddData(RvGame.GameData.Edition, VarFix.String(trurip.SelectSingleNode("edition")));
                tDir.Game.AddData(RvGame.GameData.Version, VarFix.String(trurip.SelectSingleNode("version")));
                tDir.Game.AddData(RvGame.GameData.Type, VarFix.String(trurip.SelectSingleNode("type")));
                tDir.Game.AddData(RvGame.GameData.Media, VarFix.String(trurip.SelectSingleNode("media")));
                tDir.Game.AddData(RvGame.GameData.Language, VarFix.String(trurip.SelectSingleNode("language")));
                tDir.Game.AddData(RvGame.GameData.Players, VarFix.String(trurip.SelectSingleNode("players")));
                tDir.Game.AddData(RvGame.GameData.Ratings, VarFix.String(trurip.SelectSingleNode("ratings")));
                tDir.Game.AddData(RvGame.GameData.Peripheral, VarFix.String(trurip.SelectSingleNode("peripheral")));
                tDir.Game.AddData(RvGame.GameData.Genre, VarFix.String(trurip.SelectSingleNode("genre")));
                tDir.Game.AddData(RvGame.GameData.MediaCatalogNumber, VarFix.String(trurip.SelectSingleNode("mediacatalognumber")));
                tDir.Game.AddData(RvGame.GameData.BarCode, VarFix.String(trurip.SelectSingleNode("barcode")));
            }

            RvDir tDirCHD = new RvDir(FileType.Dir)
            {
                Name      = tDir.Name,
                DatStatus = tDir.DatStatus,
                Dat       = tDir.Dat,
                Game      = tDir.Game
            };

            XmlNodeList romNodeList = gameNode.SelectNodes("rom");

            if (romNodeList != null)
            {
                for (int i = 0; i < romNodeList.Count; i++)
                {
                    LoadRomFromDat(ref tDir, romNodeList[i], thisFileType);
                }
            }

            XmlNodeList diskNodeList = gameNode.SelectNodes("disk");

            if (diskNodeList != null)
            {
                for (int i = 0; i < diskNodeList.Count; i++)
                {
                    LoadDiskFromDat(ref tDirCHD, diskNodeList[i]);
                }
            }

            if (tDir.ChildCount > 0)
            {
                parent.ChildAdd(tDir, index1);
            }
            if (tDirCHD.ChildCount > 0)
            {
                parent.ChildAdd(tDirCHD);
            }
        }