CategorizeGame() public abstract method

Applies this autocategorization scheme to the game with the given ID.
public abstract CategorizeGame ( GameInfo game, Depressurizer.Filter filter ) : AutoCatResult
game GameInfo The GameInfo object to process
filter Depressurizer.Filter
return AutoCatResult
        private void Autocategorize( bool selectedOnly, AutoCat autoCat )
        {
            if( autoCat == null ) return;

            // Get a list of games to update
            List<GameInfo> gamesToUpdate = new List<GameInfo>();

            if( selectedOnly ) {
                foreach( ListViewItem item in lstGames.SelectedItems ) {
                    GameInfo g = item.Tag as GameInfo;
                    if( ( g != null ) && ( g.Id > 0 ) ) {
                        gamesToUpdate.Add( g );
                    }
                }
            } else {
                foreach( GameInfo g in gameData.Games.Values ) {
                    if( ( g != null ) && ( g.Id > 0 ) ) {
                        gamesToUpdate.Add( g );
                    }
                }
            }

            int updated = 0;

            // List of games not found in database, so we can try to scrape data for them
            List<GameInfo> notFound = new List<GameInfo>();

            autoCat.PreProcess( currentProfile.GameData, Program.GameDB );

            foreach( GameInfo g in gamesToUpdate ) {
                AutoCatResult res = autoCat.CategorizeGame( g );
                if( res == AutoCatResult.Success ) {
                    updated++;
                } else if( res == AutoCatResult.NotInDatabase ) {
                    notFound.Add( g );
                }
            }

            if( notFound.Count > 0 ) {
                if( MessageBox.Show( string.Format( GlobalStrings.MainForm_GamesNotFoundInGameDB, notFound.Count ), GlobalStrings.DBEditDlg_Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 )
                        == System.Windows.Forms.DialogResult.Yes ) {

                    Queue<int> jobs = new Queue<int>();
                    foreach( GameInfo g in notFound ) jobs.Enqueue( g.Id );

                    DbScrapeDlg scrapeDlg = new DbScrapeDlg( jobs );
                    DialogResult scrapeRes = scrapeDlg.ShowDialog();

                    if( scrapeRes == System.Windows.Forms.DialogResult.Cancel ) {
                        AddStatus( string.Format( GlobalStrings.MainForm_CanceledDatabaseUpdate ) );
                    } else {
                        AddStatus( string.Format( GlobalStrings.MainForm_UpdatedDatabaseEntries, scrapeDlg.JobsCompleted ) );
                        foreach( GameInfo g in notFound ) {
                            AutoCatResult res = autoCat.CategorizeGame( g );
                            if( res == AutoCatResult.Success ) {
                                updated++;
                            }
                        }
                    }
                }
            }
            autoCat.DeProcess();
            AddStatus( string.Format( GlobalStrings.MainForm_UpdatedCategories, updated ) );
            if( gamesToUpdate.Count > updated ) AddStatus( string.Format( GlobalStrings.MainForm_FailedToUpdate, gamesToUpdate.Count - updated ) );
            if( updated > 0 ) MakeChange( true );
            FullListRefresh();
        }
Beispiel #2
0
        /// <summary>
        /// Autocategorizes a set of games.
        /// </summary>
        /// <param name="selectedOnly">If true, runs on the selected games, otherwise, runs on all games.</param>
        /// <param name="autoCat">The autocat object to use.</param>
        private void Autocategorize(bool selectedOnly, AutoCat autoCat, bool scrape = true, bool refresh = true)
        {
            if (autoCat == null) return;

            Cursor.Current = Cursors.WaitCursor;

            // Get a list of games to update
            List<GameInfo> gamesToUpdate = new List<GameInfo>();

            if (selectedOnly && (autoCat.Filter == null))
            {
                foreach (GameInfo g in tlstGames.SelectedObjects)
                {
                    if (g.Id > 0)
                    {
                        gamesToUpdate.Add(g);
                    }
                }
            }
            else if ((tlstGames.Objects.Count > 0) && (autoCat.Filter == null))
            {
                foreach (GameInfo g in tlstGames.Objects)
                {
                    if (g.Id > 0)
                    {
                        gamesToUpdate.Add(g);
                    }
                }
            }
            else
            {
                foreach (GameInfo g in currentProfile.GameData.Games.Values)
                {
                    if ((g != null) && (g.Id > 0))
                    {
                        gamesToUpdate.Add(g);
                    }
                }
            }

            int updated = 0;

            // List of games not found in database, so we can try to scrape data for them
            Queue<int> notInDb = new Queue<int>();
            foreach (GameInfo game in gamesToUpdate)
            {
                if (game.Id > 0 && (!Program.GameDB.Contains(game.Id) || Program.GameDB.Games[game.Id].LastStoreScrape == 0))
                {
                    notInDb.Enqueue(game.Id);
                }
            }

            if ((notInDb.Count > 0) && scrape)
            {
                Cursor.Current = Cursors.Default;
                if (MessageBox.Show(string.Format(GlobalStrings.MainForm_GamesNotFoundInGameDB, notInDb.Count), GlobalStrings.DBEditDlg_Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                        == System.Windows.Forms.DialogResult.Yes)
                {

                    DbScrapeDlg scrapeDlg = new DbScrapeDlg(notInDb);
                    DialogResult scrapeRes = scrapeDlg.ShowDialog();

                    if (scrapeRes == System.Windows.Forms.DialogResult.Cancel)
                    {
                        AddStatus(string.Format(GlobalStrings.MainForm_CanceledDatabaseUpdate));
                    }
                    else
                    {
                        AddStatus(string.Format(GlobalStrings.MainForm_UpdatedDatabaseEntries, scrapeDlg.JobsCompleted));
                        if (scrapeDlg.JobsCompleted > 0 && Settings.Instance.AutosaveDB)
                        {
                            SaveGameDB();
                        }
                    }
                }
                Cursor.Current = Cursors.WaitCursor;
            }

            autoCat.PreProcess(currentProfile.GameData, Program.GameDB);

            foreach (GameInfo g in gamesToUpdate)
            {
                AutoCatResult res = autoCat.CategorizeGame(g, currentProfile.GameData.GetFilter(autoCat.Filter));
                if (res == AutoCatResult.Success)
                {
                    updated++;
                }
            }

            autoCat.DeProcess();
            AddStatus(string.Format(GlobalStrings.MainForm_UpdatedCategories, updated));
            if (gamesToUpdate.Count > updated) AddStatus(string.Format(GlobalStrings.MainForm_FailedToUpdate, gamesToUpdate.Count - updated));
            if (updated > 0) MakeChange(true);
            if (refresh)
            {
                FillAllCategoryLists();
                FilterGamelist(true);
            }

            Cursor.Current = Cursors.Default;
        }