Esempio n. 1
0
        private static bool LoadNewDat(RvDat fileDat, RvFile thisDirectory)
        {
            // Read the new Dat File into newDatFile
            RvFile newDatFile = DatReader.ReadInDatFile(fileDat, _thWrk);

            // If we got a valid Dat File back
            if (newDatFile?.Dat == null)
            {
                ReportError.Show("Error reading Dat " + fileDat.GetData(RvDat.DatData.DatRootFullName));
                return(false);
            }
            if (newDatFile.ChildCount == 0)
            {
                return(false);
            }

            if (
                !fileDat.MultiDatOverride &&
                newDatFile.Dat.GetData(RvDat.DatData.DirSetup) != "noautodir" &&
                (
                    fileDat.MultiDatsInDirectory ||
                    !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))
                )
                )
            {
                // if we are auto adding extra directories then create a new directory.
                string dirName = "";
                if (string.IsNullOrEmpty(dirName) && fileDat.UseDescriptionAsDirName && !string.IsNullOrWhiteSpace(newDatFile.Dat.GetData(RvDat.DatData.Description)))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.Description);
                }
                if (string.IsNullOrEmpty(dirName) && !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.RootDir);
                }
                if (string.IsNullOrEmpty(dirName))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.DatName);
                }
                if (string.IsNullOrEmpty(dirName))
                {
                    dirName = Path.GetFileNameWithoutExtension(newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName));
                }

                newDatFile.Name = VarFix.CleanFileName(dirName);

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

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

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

                newDatFile.Dat.AutoAddedDirectory = true;
            }
            else
            {
                newDatFile.Dat.AutoAddedDirectory = false;
            }

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

            if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true))
            {
                ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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);
        }
Esempio n. 2
0
        public static RvFile ReadInDatFile(RvDat datFile, ThreadWorker thWrk)
        {
            try
            {
                _thWrk = thWrk;

                string datRootFullName = datFile.GetData(RvDat.DatData.DatRootFullName);
                string fullPath        = RvFile.GetDatPhysicalPath(datRootFullName);
                Debug.WriteLine("Reading Dat " + fullPath);

                DatRead dr = new DatRead {
                    ErrorReport = ReadError
                };
                dr.ReadDat(fullPath, out DatHeader dh);
                if (dh == null)
                {
                    return(null);
                }

                // if we are auto adding extra directories then create a new directory.
                string extraDirName = "";
                if (string.IsNullOrEmpty(extraDirName) && datFile.UseDescriptionAsDirName && !string.IsNullOrWhiteSpace(dh.Description))
                {
                    extraDirName = dh.Description;
                }
                if (string.IsNullOrEmpty(extraDirName))
                {
                    extraDirName = !string.IsNullOrEmpty(dh.RootDir) ? dh.RootDir : dh.Name;
                }

                string dirNameRule = Path.GetDirectoryName(datRootFullName) + Path.DirectorySeparatorChar + VarFix.CleanFileName(extraDirName) + Path.DirectorySeparatorChar;

                DatRule datRule = FindDatRule(dirNameRule);

                DatClean.CleanFilenames(dh.BaseDir);

                switch (datRule.Filter)
                {
                case FilterType.CHDsOnly:
                    DatClean.RemoveNonCHD(dh.BaseDir);
                    break;

                case FilterType.RomsOnly:
                    DatClean.RemoveCHD(dh.BaseDir);
                    break;
                }

                DatClean.RemoveNoDumps(dh.BaseDir);

                SetMergeType(datRule, dh);

                if (datFile.SingleArchive)
                {
                    DatClean.MakeDatSingleLevel(dh, datFile.UseDescriptionAsDirName);
                }

                DatClean.RemoveUnNeededDirectories(dh.BaseDir);

                SetCompressionMethod(datRule, dh);    // This sorts the files into the required dir order for the set compression type.

                DatClean.DirectoryExpand(dh.BaseDir); // this works because we only expand files, so the order inside the zip / 7z does not matter.

                DatClean.RemoveEmptyDirectories(dh.BaseDir);

                DatClean.CleanFilenamesFixDupes(dh.BaseDir); // you may get repeat filenames inside Zip's / 7Z's and they may not be sorted to find them by now.


                RvFile newDir = ExternalDatConverter.ConvertFromExternalDat(dh, datFile);
                return(newDir);
            }
            catch (Exception e)
            {
                string datRootFullName = datFile?.GetData(RvDat.DatData.DatRootFullName);

                Console.WriteLine(e);
                throw new Exception("Error is DAT " + datRootFullName + " " + e.Message);
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
                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(thisFileType == FileType.File ? FileType.Dir : FileType.Zip)
            {
                Name      = fullname,
                DatStatus = DatStatus.InDatCollect,
                Dat       = tDat.Dat
            };

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

            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);
        }
Esempio n. 6
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref XmlDocument doc, ref FileType thisFileType)
        {
            if (doc.DocumentElement == null)
            {
                return(false);
            }
            XmlNode head = doc.DocumentElement.SelectSingleNode("header");

            if (head == null)
            {
                return(false);
            }
            RvDat tDat = new RvDat();

            tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(head.SelectSingleNode("name")));
            tDat.AddData(RvDat.DatData.RootDir, VarFix.CleanFileName(head.SelectSingleNode("rootdir")));
            tDat.AddData(RvDat.DatData.Description, VarFix.String(head.SelectSingleNode("description")));
            tDat.AddData(RvDat.DatData.Category, VarFix.String(head.SelectSingleNode("category")));
            tDat.AddData(RvDat.DatData.Version, VarFix.String(head.SelectSingleNode("version")));
            tDat.AddData(RvDat.DatData.Date, VarFix.String(head.SelectSingleNode("date")));
            tDat.AddData(RvDat.DatData.Author, VarFix.String(head.SelectSingleNode("author")));
            tDat.AddData(RvDat.DatData.Email, VarFix.String(head.SelectSingleNode("email")));
            tDat.AddData(RvDat.DatData.HomePage, VarFix.String(head.SelectSingleNode("homepage")));
            tDat.AddData(RvDat.DatData.URL, VarFix.String(head.SelectSingleNode("url")));


            string superDAT = VarFix.String(head.SelectSingleNode("type"));

            _cleanFileNames = superDAT.ToLower() != "superdat" && superDAT.ToLower() != "gigadat";
            if (!_cleanFileNames)
            {
                tDat.AddData(RvDat.DatData.SuperDat, "superdat");
            }

            thisFileType = FileType.ZipFile;

            // Look for:   <romvault forcepacking="unzip"/>
            XmlNode packingNode = head.SelectSingleNode("romvault");

            if (packingNode == null)
            {
                // Look for:   <clrmamepro forcepacking="unzip"/>
                packingNode = head.SelectSingleNode("clrmamepro");
            }
            if (packingNode != null)
            {
                if (packingNode.Attributes != null)
                {
                    string val = VarFix.String(packingNode.Attributes.GetNamedItem("forcepacking")).ToLower();
                    switch (val.ToLower())
                    {
                    case "zip":
                        tDat.AddData(RvDat.DatData.FileType, "zip");
                        thisFileType = FileType.ZipFile;
                        break;

                    case "unzip":
                    case "file":
                        tDat.AddData(RvDat.DatData.FileType, "file");
                        thisFileType = FileType.File;
                        break;

                    default:
                        thisFileType = FileType.ZipFile;
                        break;
                    }

                    val = VarFix.String(packingNode.Attributes.GetNamedItem("forcemerging")).ToLower();
                    switch (val.ToLower())
                    {
                    case "split":
                        tDat.AddData(RvDat.DatData.MergeType, "split");
                        break;

                    case "full":
                        tDat.AddData(RvDat.DatData.MergeType, "full");
                        break;

                    default:
                        tDat.AddData(RvDat.DatData.MergeType, "split");
                        break;
                    }
                    val = VarFix.String(packingNode.Attributes.GetNamedItem("dir")).ToLower(); // noautodir , nogame
                    if (!String.IsNullOrEmpty(val))
                    {
                        tDat.AddData(RvDat.DatData.DirSetup, val);
                    }
                }
            }

            // Look for: <notzipped>true</notzipped>
            string notzipped = VarFix.String(head.SelectSingleNode("notzipped"));

            if (notzipped.ToLower() == "true" || notzipped.ToLower() == "yes")
            {
                thisFileType = FileType.File;
            }

            tDir.Dat = tDat;
            return(true);
        }
Esempio n. 7
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref XmlDocument doc, ref FileType thisFileType)
        {
            XmlNodeList head = doc.SelectNodes("softwarelist");

            if (head == null)
            {
                return(false);
            }

            if (head.Count == 0)
            {
                return(false);
            }

            if (head[0].Attributes == null)
            {
                return(false);
            }

            RvDat tDat = new RvDat();

            tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(head[0].Attributes.GetNamedItem("name")));
            tDat.AddData(RvDat.DatData.Description, VarFix.String(head[0].Attributes.GetNamedItem("description")));

            string val = VarFix.String(head[0].Attributes.GetNamedItem("forcemerging")).ToLower();

            switch (val.ToLower())
            {
            case "split":
                tDat.AddData(RvDat.DatData.MergeType, "split");
                break;

            case "full":
                tDat.AddData(RvDat.DatData.MergeType, "full");
                break;

            default:
                tDat.AddData(RvDat.DatData.MergeType, "split");
                break;
            }

            val = VarFix.String(head[0].Attributes.GetNamedItem("forcepacking")).ToLower();
            switch (val.ToLower())
            {
            case "zip":
                tDat.AddData(RvDat.DatData.FileType, "zip");
                thisFileType = FileType.ZipFile;
                break;

            case "unzip":
            case "file":
                tDat.AddData(RvDat.DatData.FileType, "file");
                thisFileType = FileType.File;
                break;

            default:
                thisFileType = FileType.ZipFile;
                break;
            }

            tDir.Dat = tDat;
            return(true);
        }
Esempio n. 8
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);
                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
            };

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

            int index1;

            if (parent.ChildNameSearch(tDir, out 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);
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        private static bool LoadGameFromDat(RvDat rvDat, string rootName, HeaderFileType datFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat("( 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("Name not found as first object in ( )", DatFileLoader.Filename);
                return(false);
            }


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

            name = Path.Combine(pathextra, name);
            name = Path.Combine(rootName, name);

            DatFileLoader.Gn();

            RvGame rvGame = new RvGame {
                Name = name
            };

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "romof":
                    rvGame.RomOf = VarFix.CleanFileName(DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "description":
                    rvGame.Description = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "sourcefile":
                    rvGame.SourceFile = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "cloneof":
                    rvGame.CloneOf = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "sampleof":
                    rvGame.SampleOf = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "board":
                    rvGame.Board = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "year":
                    rvGame.Year = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "manufacturer":
                    rvGame.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(rvGame, datFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

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

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

                default:
                    DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in game", DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }
            rvDat.AddGame(rvGame);
            return(true);
        }
Esempio n. 11
0
        private static bool LoadHeaderFromDat(string filename, RvDat rvDat, out HeaderFileType datFileType)
        {
            datFileType = HeaderFileType.Nothing;

            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat("( not found after clrmamepro", DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            rvDat.Filename = filename;

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "name":
                    rvDat.Name = VarFix.CleanFileName(DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

                case "description":
                    rvDat.Description = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "category":
                    rvDat.Category = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "version":
                    rvDat.Version = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "date":
                    rvDat.Date = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "author":
                    rvDat.Author = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "email":
                    rvDat.Email = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "homepage":
                    rvDat.Homepage = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "url":
                    rvDat.URL = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "comment":
                    rvDat.Comment = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

                case "header":
                    datFileType = FileHeaderReader.FileHeaderReader.GetFileTypeFromHeader(DatFileLoader.GnRest());
                    DatFileLoader.Gn();
                    break;

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

                case "forcepacking":
                    DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;     // incorrect usage

                case "forcemerging":
                    rvDat.MergeType = DatFileLoader.GnRest();
                    DatFileLoader.Gn();
                    break;

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

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

                default:
                    DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known in clrmamepro", DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }

            return(true);
        }
Esempio n. 12
0
        private static void LoadGameFromDat(RvDat rvDat, XmlNode gameNode, string rootDir, HeaderFileType datFileType)
        {
            if (gameNode.Attributes == null)
            {
                return;
            }

            RvGame rvGame = new RvGame
            {
                Name         = VarFix.CleanFullFileName(gameNode.Attributes.GetNamedItem("name")),
                RomOf        = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("romof")),
                CloneOf      = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")),
                SampleOf     = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("sampleof")),
                Description  = VarFix.String(gameNode.SelectSingleNode("description")),
                SourceFile   = VarFix.String(gameNode.Attributes.GetNamedItem("sourcefile")),
                IsBios       = VarFix.String(gameNode.Attributes.GetNamedItem("isbios")),
                Board        = VarFix.String(gameNode.Attributes.GetNamedItem("board")),
                Year         = VarFix.String(gameNode.SelectSingleNode("year")),
                Manufacturer = VarFix.String(gameNode.SelectSingleNode("manufacturer"))
            };

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

            if (trurip != null)
            {
                rvGame.IsTrurip           = true;
                rvGame.Publisher          = VarFix.String(trurip.SelectSingleNode("publisher"));
                rvGame.Developer          = VarFix.String(trurip.SelectSingleNode("developer"));
                rvGame.Edition            = VarFix.String(trurip.SelectSingleNode("edition"));
                rvGame.Version            = VarFix.String(trurip.SelectSingleNode("version"));
                rvGame.Type               = VarFix.String(trurip.SelectSingleNode("type"));
                rvGame.Media              = VarFix.String(trurip.SelectSingleNode("media"));
                rvGame.Language           = VarFix.String(trurip.SelectSingleNode("language"));
                rvGame.Players            = VarFix.String(trurip.SelectSingleNode("players"));
                rvGame.Ratings            = VarFix.String(trurip.SelectSingleNode("ratings"));
                rvGame.Peripheral         = VarFix.String(trurip.SelectSingleNode("peripheral"));
                rvGame.Genre              = VarFix.String(trurip.SelectSingleNode("genre"));
                rvGame.MediaCatalogNumber = VarFix.String(trurip.SelectSingleNode("mediacatalognumber"));
                rvGame.BarCode            = VarFix.String(trurip.SelectSingleNode("barcode"));
            }

            rvGame.Name = Path.Combine(rootDir, rvGame.Name);

            rvDat.AddGame(rvGame);

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

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

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

            if (diskNodeList != null)
            {
                for (int i = 0; i < diskNodeList.Count; i++)
                {
                    LoadDiskFromDat(rvGame, diskNodeList[i]);
                }
            }
        }
Esempio n. 13
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadHeaderFromDat_not_found_after_clrmamepro, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            RvDat tDat = new RvDat();

            while (DatFileLoader.Next != ")")
            {
                string nextstr = DatFileLoader.Next.ToLower();
                if ((nextstr.Length > 5) && (nextstr.Substring(0, 5) == "name:"))
                {
                    tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.Next.Substring(5) + " " + DatFileLoader.GnRest()).Trim());
                    DatFileLoader.Gn();
                }
                else
                {
                    switch (nextstr)
                    {
                    case "name:":
                        tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.GnRest()));
                        DatFileLoader.Gn();
                        break;

                    case "description:":
                        tDat.AddData(RvDat.DatData.Description, DatFileLoader.GnRest());
                        DatFileLoader.Gn();
                        break;

                    case "version:":
                        tDat.AddData(RvDat.DatData.Version, DatFileLoader.GnRest());
                        DatFileLoader.Gn();
                        break;

                    case "date:":
                        tDat.AddData(RvDat.DatData.Date, DatFileLoader.GnRest());
                        DatFileLoader.Gn();
                        break;

                    case "author:":
                        tDat.AddData(RvDat.DatData.Author, DatFileLoader.GnRest());
                        DatFileLoader.Gn();
                        break;

                    case "homepage:":
                        tDat.AddData(RvDat.DatData.HomePage, DatFileLoader.GnRest());
                        DatFileLoader.Gn();
                        break;

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

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

            thisFileType = FileType.ZipFile;
            tDir.Dat     = tDat;
            return(true);
        }