Пример #1
0
        public static bool ReadMameDat(XmlDocument doc, string strFilename,long fileTimeStamp,out RvDat rvDat)
        {
            rvDat=new RvDat();
            string filename = IO.Path.GetFileName(strFilename);

            if (!LoadMameHeaderFromDat(doc, rvDat, filename,fileTimeStamp))
                return false;

            if (doc.DocumentElement == null)
                return false;

            XmlNodeList dirNodeList = doc.DocumentElement.SelectNodes("dir");
            if (dirNodeList != null)
            {
                for (int i = 0; i < dirNodeList.Count; i++)
                {
                    LoadDirFromDat(rvDat, dirNodeList[i], "");
                }
            }

            XmlNodeList gameNodeList = doc.DocumentElement.SelectNodes("game");

            if (gameNodeList != null)
            {
                for (int i = 0; i < gameNodeList.Count; i++)
                {
                    LoadGameFromDat(rvDat, gameNodeList[i], "");
                }
            }

            return true;
        }
Пример #2
0
        private static void LoadDirFromDat(RvDat rvDat, XmlNode dirNode, string rootDir)
        {
            if (dirNode.Attributes == null)
                return;

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

            XmlNodeList dirNodeList = dirNode.SelectNodes("dir");
            if (dirNodeList != null)
            {
                for (int i = 0; i < dirNodeList.Count; i++)
                {
                    LoadDirFromDat(rvDat, dirNodeList[i], IO.Path.Combine(rootDir, fullname));
                }
            }

            XmlNodeList gameNodeList = dirNode.SelectNodes("game");
            if (gameNodeList != null)
            {
                for (int i = 0; i < gameNodeList.Count; i++)
                {
                    LoadGameFromDat(rvDat, gameNodeList[i], IO.Path.Combine(rootDir, fullname));
                }
            }
        }
Пример #3
0
        private static void MakeDB()
        {
            ExecuteNonQuery(@"CREATE TABLE IF NOT EXISTS [VERSION] ([Version] INTEGER NOT NULL); INSERT INTO VERSION (version) VALUES (@Version);", "version", DBVersion);

            ExecuteNonQuery(@"
                                
                CREATE TABLE IF NOT EXISTS [DIR] (
                    [DirId] INTEGER PRIMARY KEY NOT NULL,
                    [ParentDirId] INTEGER NULL,
                    [name] NVARCHAR(300) NOT NULL,
                    [fullname] NVARCHAR(300) NOT NULL,
                    [expanded] BOOLEAN DEFAULT 1 NOT NULL,
                    [found] BOOLEAN DEFAULT 1,
                    [RomTotal] INTEGER NULL,
                    [RomGot] iNTEGER NULL,
                    [RomNoDump] INTEGER NULL
                );
             
        ");

            RvDat.MakeDB();
            RvGame.MakeDB();
            RvRom.MakeDB();
            RvFile.MakeDB();
        }
Пример #4
0
        public static bool ReadDat(string fullname, long fileTimeStamp, BackgroundWorker bgw, out RvDat rvDat)
        {
            _bgw = bgw;

            rvDat = null;

            Console.WriteLine("Reading " + fullname);

            Stream fs;
            int errorCode = IO.FileStream.OpenFileRead(fullname, out fs);
            if (errorCode != 0)
            {
                _bgw.ReportProgress(0, new bgwShowError(fullname, errorCode + ": " + new Win32Exception(errorCode).Message));
                return false;
            }

            StreamReader myfile = new StreamReader(fs, Program.Enc);
            string strLine = myfile.ReadLine();
            myfile.Close();
            fs.Close();
            fs.Dispose();

            if (strLine == null)
                return false;

            if (strLine.ToLower().IndexOf("xml", StringComparison.Ordinal) >= 0)
            {
                if (!ReadXMLDat(fullname, fileTimeStamp, out rvDat))
                    return false;
            }

            else if (strLine.ToLower().IndexOf("clrmamepro", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("romvault", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("game", StringComparison.Ordinal) >= 0)
            {
                if (!DatCmpReader.ReadDat(fullname, fileTimeStamp, out rvDat))
                    return false;
            }
            else if (strLine.ToLower().IndexOf("doscenter", StringComparison.Ordinal) >= 0)
            {
                //    if (!DatDOSReader.ReadDat(datFullName))
                //        return;
            }
            else
            {
                _bgw.ReportProgress(0, new bgwShowError(fullname, "Invalid DAT File"));
                return false;
            }

            return true;
        }
Пример #5
0
        private void MakeDB()
        {
            /******** Create Tables ***********/

            ExecuteNonQuery(@"
                CREATE TABLE IF NOT EXISTS [VERSION] (
                    [Version] INTEGER NOT NULL);
                INSERT INTO VERSION (version) VALUES (@Version);",
                            "version", DBVersion);

            RvDir.CreateTable();
            RvDat.CreateTable();
            RvGame.CreateTable();
            RvFile.CreateTable();
            RvRom.CreateTable();
        }
Пример #6
0
        private static bool ReadXMLDat(string fullname, long fileTimeStamp, out RvDat rvDat)
        {
            rvDat = null;
            Stream fs;
            int errorCode = IO.FileStream.OpenFileRead(fullname, out fs);
            if (errorCode != 0)
            {
                _bgw.ReportProgress(0, new bgwShowError(fullname, errorCode + ": " + new Win32Exception(errorCode).Message));
                return false;
            }

            XmlDocument doc = new XmlDocument { XmlResolver = null };
            try
            {
                doc.Load(fs);
            }
            catch (Exception e)
            {
                fs.Close();
                fs.Dispose();
                _bgw.ReportProgress(0, new bgwShowError(fullname, string.Format("Error Occured Reading Dat:\r\n{0}\r\n", e.Message)));
                return false;
            }
            fs.Close();
            fs.Dispose();

            if (doc.DocumentElement == null)
                return false;

            XmlNode mame = doc.SelectSingleNode("mame");
            if (mame != null)
                return DatXmlReader.ReadMameDat(doc, fullname, fileTimeStamp, out rvDat);

            if (doc.DocumentElement != null)
            {
                XmlNode head = doc.DocumentElement.SelectSingleNode("header");
                if (head != null)
                    return DatXmlReader.ReadDat(doc, fullname, fileTimeStamp, out rvDat);
            }

            XmlNodeList headList = doc.SelectNodes("softwarelist");
            if (headList != null)
                return DatMessXmlReader.ReadDat(doc, fullname, fileTimeStamp, out rvDat);

            return false;
        }
Пример #7
0
        private static void ExtractZips(uint datId, string outDir)
        {
            if (buffer == null)
                buffer = new byte[BufferSize];

            RvDat tDat = new RvDat();
            tDat.DBRead(datId, true);

            _bgw.ReportProgress(0, new bgwSetRange(tDat.Games.Count));

            for (int gIndex = 0; gIndex < tDat.Games.Count; gIndex++)
            {
                if (_bgw.CancellationPending)
                    return;

                RvGame tGame = tDat.Games[gIndex];
                _bgw.ReportProgress(gIndex);
                _bgw.ReportProgress(0, new bgwText("Creating zip : " + tGame.Name + ".zip"));

                ExtractGame(tGame, outDir);
            }
        }
Пример #8
0
        private static bool LoadHeaderFromDat(string Filename, long fileTimeStamp, RvDat rvDat)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat("( not found after clrmamepro", DatFileLoader.Filename);
                return false;
            }
            DatFileLoader.Gn();

            rvDat.Filename = Filename;
            rvDat.DatTimeStamp = fileTimeStamp;

            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": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "forcezipping": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "forcepacking": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; // incorrect usage
                    case "forcemerging": 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;
        }
Пример #9
0
        private static bool LoadGameFromDat(RvDat rvDat, string rootdir)
        {
            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());

            if (!String.IsNullOrEmpty(pathextra))
                name = pathextra + "/" + name;

            DatFileLoader.Gn();

            RvGame rvGame = new RvGame();
            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))
                            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;
        }
Пример #10
0
        public static bool ReadDat(string strFilename, long fileTimeStamp, out RvDat rvDat)
        {
            rvDat = new RvDat();
            int errorCode = DatFileLoader.LoadDat(strFilename);
            if (errorCode != 0)
            {
                DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename);
                return false;
            }

            string Filename = IO.Path.GetFileName(strFilename);

            DatFileLoader.Gn();
            if (DatFileLoader.EndOfStream())
                return false;
            if (DatFileLoader.Next.ToLower() == "clrmamepro")
            {
                DatFileLoader.Gn();
                if (!LoadHeaderFromDat(Filename, fileTimeStamp, rvDat))
                    return false;
                DatFileLoader.Gn();
            }
            if (DatFileLoader.Next.ToLower() == "romvault")
            {
                DatFileLoader.Gn();
                if (!LoadHeaderFromDat(Filename, fileTimeStamp, rvDat))
                    return false;
                DatFileLoader.Gn();
            }

            while (!DatFileLoader.EndOfStream())
            {
                switch (DatFileLoader.Next.ToLower())
                {
                    case "dir":
                        DatFileLoader.Gn();
                        if (!LoadDirFromDat(rvDat, ""))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    case "game":
                        DatFileLoader.Gn();
                        if (!LoadGameFromDat(rvDat, ""))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    case "resource":
                        DatFileLoader.Gn();
                        if (!LoadGameFromDat(rvDat, ""))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    case "emulator":
                        DatFileLoader.Gn();
                        if (!LoadEmulator())
                            return false;
                        DatFileLoader.Gn();
                        break;
                    default:
                        DatUpdate.SendAndShowDat("Error: key word '" + DatFileLoader.Next + "' not known", DatFileLoader.Filename);
                        DatFileLoader.Gn();
                        break;
                }
            }

            DatFileLoader.Close();

            return true;
        }
Пример #11
0
        private static bool LoadDirFromDat(RvDat rvDat, string rootDir)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat("( not found after game", DatFileLoader.Filename);
                return false;
            }
            DatFileLoader.Gn();

            if (DatFileLoader.Next.ToLower() != "name")
            {
                DatUpdate.SendAndShowDat("Name not found as first object in ( )", DatFileLoader.Filename);
                return false;
            }
            string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest());

            DatFileLoader.Gn();

            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                    case "dir":
                        DatFileLoader.Gn();
                        if (!LoadDirFromDat(rvDat, fullname))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    case "game":
                        DatFileLoader.Gn();
                        if (!LoadGameFromDat(rvDat, fullname))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    case "resource":
                        DatFileLoader.Gn();
                        if (!LoadGameFromDat(rvDat, fullname))
                            return false;
                        DatFileLoader.Gn();
                        break;
                    default:
                        DatUpdate.SendAndShowDat("Error Keyword " + DatFileLoader.Next + " not know in dir", DatFileLoader.Filename);
                        DatFileLoader.Gn();
                        break;
                }
            }
            return true;
        }
Пример #12
0
        private static bool LoadMameHeaderFromDat(XmlDocument doc, RvDat rvDat, string filename,long fileTimeStamp)
        {
            if (doc.DocumentElement == null)
                return false;
            XmlNode head = doc.SelectSingleNode("mame");

            if (head == null || head.Attributes == null)
                return false;

            rvDat.Filename = filename;
            rvDat.Name = VarFix.CleanFileName(head.Attributes.GetNamedItem("build"));
            rvDat.Description = VarFix.String(head.Attributes.GetNamedItem("build"));
            rvDat.DatTimeStamp = fileTimeStamp;

            return true;
        }
Пример #13
0
        private static bool LoadHeaderFromDat(XmlDocument doc, RvDat rvDat, string filename,long fileTimeStamp)
        {
            if (doc.DocumentElement == null)
                return false;
            XmlNode head = doc.DocumentElement.SelectSingleNode("header");

            rvDat.Filename = filename;
            rvDat.DatTimeStamp = fileTimeStamp;

            if (head == null)
                return false;
            rvDat.Name = VarFix.CleanFileName(head.SelectSingleNode("name"));
            rvDat.RootDir = VarFix.CleanFileName(head.SelectSingleNode("rootdir"));
            rvDat.Description = VarFix.String(head.SelectSingleNode("description"));
            rvDat.Category = VarFix.String(head.SelectSingleNode("category"));
            rvDat.Version = VarFix.String(head.SelectSingleNode("version"));
            rvDat.Date = VarFix.String(head.SelectSingleNode("date"));
            rvDat.Author = VarFix.String(head.SelectSingleNode("author"));
            rvDat.Email = VarFix.String(head.SelectSingleNode("email"));
            rvDat.Homepage = VarFix.String(head.SelectSingleNode("homepage"));
            rvDat.URL = VarFix.String(head.SelectSingleNode("url"));
            rvDat.Comment = VarFix.String(head.SelectSingleNode("comment"));

            return true;
        }
Пример #14
0
        private static void LoadGameFromDat(RvDat rvDat, XmlNode gameNode, string rootDir)
        {
            if (gameNode.Attributes == null)
                return;

            RvGame rvGame=new RvGame();
            rvGame.Name = VarFix.CleanFullFileName(gameNode.Attributes.GetNamedItem("name"));
            rvGame.RomOf = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("romof"));
            rvGame.CloneOf = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof"));
            rvGame.SampleOf = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("sampleof"));
            rvGame.Description = VarFix.String(gameNode.SelectSingleNode("description"));
            rvGame.SourceFile = VarFix.String(gameNode.Attributes.GetNamedItem("sourcefile"));
            rvGame.IsBios = VarFix.String(gameNode.Attributes.GetNamedItem("isbios"));
            rvGame.Board = VarFix.String(gameNode.Attributes.GetNamedItem("board"));
            rvGame.Year = VarFix.String(gameNode.SelectSingleNode("year"));
            rvGame.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 = IO.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]);

            XmlNodeList diskNodeList = gameNode.SelectNodes("disk");
            if (diskNodeList != null)
                for (int i = 0; i < diskNodeList.Count; i++)
                    LoadDiskFromDat(rvGame, diskNodeList[i]);
        }
Пример #15
0
        private void updateSelectedTreeRow(RvTreeRow tr)
        {
            lblDITName.Text = tr.datName;
            lblDITPath.Text = tr.dirFullName;

            if (tr.DatId != null)
            {
                RvDat tDat = new RvDat();
                tDat.DBRead((uint)tr.DatId);
                lblDITDescription.Text = tDat.Description;
                lblDITCategory.Text = tDat.Category;
                lblDITVersion.Text = tDat.Version;
                lblDITAuthor.Text = tDat.Author;
                lblDITDate.Text = tDat.Date;
            }
            else
            {
                lblDITDescription.Text = "";
                lblDITCategory.Text = "";
                lblDITVersion.Text = "";
                lblDITAuthor.Text = "";
                lblDITDate.Text = "";
            }
            lblDITRomsGot.Text = tr.RomGot.ToString("#,0");
            lblDITRomsMissing.Text = (tr.RomTotal - tr.RomGot - tr.RomNoDump).ToString("#,0");
            lblDITRomsTotal.Text = tr.RomTotal.ToString("#,0");
            lblDITRomsNoDump.Text = tr.RomNoDump.ToString("#,0");

            UpdateGameGrid(tr.DatId);
        }