Beispiel #1
0
        /// <summary>
        /// Loads all databases. UnloadDBs must be called between calls to LoadDBs.
        /// </summary>
        public static void LoadDBs()
        {
            if (!Directory.Exists(FileSystem.DbPath))
            {
                Directory.CreateDirectory(FileSystem.DbPath);
            }

            var alldbs = Program.DatabaseConfig.Databases;

            for (int i = 0; i < alldbs.Count; i++)
            {
                var db = alldbs[i];
                try{
                    string path = db.Filename;
                    if (!Path.IsPathRooted(path))
                    {
                        path = System.IO.Path.Combine(FileSystem.DbPath, path);
                    }

                    if (!File.Exists(path))
                    {
                        MessageBox.Show("The database " + Path.GetFileName(path) + " was not found and can not be loaded.");
                    }
                    else
                    {
                        var loadedDB = ClrMameProParser.ParseDAT(db, File.ReadAllText(path), db.Platforms);
                        loadedDB.AssociatedConfigEntry = db;
                        DBs.Add(loadedDB);

                        for (int j = 0; j < db.MiscPlatforms.Count; j++)
                        {
                            var platformName = db.MiscPlatforms[j];
                            loadedDB.MiscPlatforms.Add(db.MiscPlatforms[j]);

                            // Only add unique strings. Case-insensitive
                            if (_AllMiscPlatforms.Find(s => platformName.Equals(s, StringComparison.OrdinalIgnoreCase)) == null)
                            {
                                _AllMiscPlatforms.Add(platformName);
                            }
                        }
                    }
                }catch (ClrMameProParser.CmpDocumentException ex) {
                    var rslt = MessageBox.Show("A database could not be loaded (" + db.Filename + "). Additional errors will be ignored. Show details?", "Error", MessageBoxButtons.YesNo);
                    if (rslt == DialogResult.Yes)
                    {
                        using (var frm = new frmError()) {
                            frm.SetError(ex);
                            frm.ShowDialog();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Parses a DAT and returns a RomDB object containing ROM information and hashes.
        /// </summary>
        /// <param name="info">Database parameters</param>
        /// <param name="document">Document to parse</param>
        /// <param name="platform">A modifiable list object. Platform IDs for the database's supported platforms will be added to this list.</param>
        /// <returns>A parsed ROM database</returns>
        public static RomDB ParseDAT(DBConfig.Database info, string document, IList <Platforms> platform)
        {
            var parser = new ClrMameProParser(info, document, platform);

            return(parser.Parse());
        }