Exemplo n.º 1
0
 private ClrMameProParser(DBConfig.Database info, string document, IList <Platforms> platform)
 {
     this.info     = info;
     this.reader   = new CmpReader(document);
     this.document = document;
     result        = new RomDB(platform, info.Name);
 }
Exemplo n.º 2
0
 internal static DialogResult EditEntry(DBConfig.Database dbEntry)
 {
     using (var editform = new DBEdit()) {
         editform.Database = dbEntry;
         return(editform.ShowDialog());
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the absolute path for the specified database
        /// </summary>
        /// <param name="db">Database</param>
        /// <returns>The path of the database</returns>
        internal static string GetDbFilePath(DBConfig.Database db)
        {
            if (Path.IsPathRooted(db.Filename))
            {
                return(db.Filename);
            }

            return(Path.Combine(DbPath, db.Filename));
        }
Exemplo n.º 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (dbOpenDlg.ShowDialog(this) == DialogResult.OK)
            {
                string filepath = dbOpenDlg.FileName;

                defaultSelection = null;


                AddDatabase(filepath);
            }
            toolStrip1.DeselectButtons();
        }
Exemplo n.º 5
0
        private void RemoveDatabase(DBConfig.Database database)
        {
            Program.DatabaseConfig.Databases.Remove(database);

            string  filepath = FileSystem.GetDbFilePath(database);
            FsError error;

            FileSystem.PerformFileAction(() => File.Delete(filepath), out error);
            if (error != null)
            {
                MessageBox.Show("An error occurred deleting the cached database file.");
            }
        }
Exemplo n.º 6
0
        private void EditDatabase(DBConfig.Database db)
        {
            defaultSelection = db;
            if (db != null)
            {
                DialogResult result = DBEdit.EditEntry(db);

                if (result == DialogResult.OK)
                {
                    PopulateList();
                    MakeDefaultSelection();
                }
            }
        }
Exemplo n.º 7
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (lstDbs.SelectedItems.Count == 1)
            {
                var selection = lstDbs.SelectedItems[0];

                if (MessageBox.Show("Remove entry and delete database from cache?", "Delete Database", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    RemoveDatabase(selection.Tag as DBConfig.Database);
                }
            }

            defaultSelection = null;
            PopulateList();
            toolStrip1.DeselectButtons();
        }
Exemplo n.º 8
0
 private string GetPlatformString(DBConfig.Database db)
 {
     if (db.Platforms.Count == 0)
     {
         return((db.MiscPlatforms.Count > 0) ? "{misc}" : "{none}");
     }
     else if (db.Platforms.Count == 1)
     {
         return(db.Platforms[0].ToString() + ((db.MiscPlatforms.Count > 0) ? " {more}" : string.Empty));
     }
     else if (db.Platforms.Count > 1 || db.MiscPlatforms.Count > 0)
     {
         return(db.Platforms[0].ToString() + " {more}");
     }
     else
     {
         return("{none}");
     }
 }
Exemplo n.º 9
0
        /// <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());
        }
Exemplo n.º 10
0
        private void AddDatabase(string filepath)
        {
            string filename    = Path.GetFileName(filepath);
            string newFilePath = Path.Combine(FileSystem.DbPath, filename);

            // If the DB is already loaded, let user reconfigure
            var fileAlreadyLoaded = CheckFileLoaded(filepath);

            if (fileAlreadyLoaded != null)
            {
                if (MessageBox.Show("This database is already loaded. Would you like to configure it?", "Database", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    EditDatabase(fileAlreadyLoaded);
                }
                return;
            }

            // If the DB is not loaded, but already in DB folder, we don't need to copy
            bool inDbFolder = CheckSameFile(filepath, newFilePath);

            if (!inDbFolder)
            {
                // Don't overwrite existing file
                if (File.Exists(newFilePath))
                {
                    if (MessageBox.Show("A database with the same filename is already exists. The new database file will be renamed.", "Database Notice", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        newFilePath = FileSystem.GetUniqueFilename(newFilePath);
                    }
                    else
                    {
                        return;
                    }
                }

                File.Copy(filepath, newFilePath);
            }

            // Set up some reasonable defaults
            var newDbEntry = new DBConfig.Database();

            newDbEntry.Format   = DBFormat.ClrMamePro;
            newDbEntry.Filename = FileSystem.MakePathRelative(FileSystem.DbPath, newFilePath);

            DialogResult result = DBEdit.EditEntry(newDbEntry);

            // If the user cancels, and the file was copied to DB folder, delete the folder.
            if (result == DialogResult.Cancel && !inDbFolder)
            {
                FileSystem.IgnoreFileErrors(() => File.Delete(newFilePath));
            }
            else
            {
                Program.DatabaseConfig.Databases.Add(newDbEntry);
                defaultSelection = newDbEntry;
            }

            // Re-populate list
            PopulateList();
            MakeDefaultSelection();
            return;
        }