Represents a single game and its categories.
Exemple #1
0
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }
            if (db == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }
            if (game == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull);
                return AutoCatResult.Failure;
            }

            if (!db.Contains(game.Id)) return AutoCatResult.NotInDatabase;

            string cat = game.Name.Substring(0, 1);
            cat = cat.ToUpper();
            if (SkipThe && cat == "T" && game.Name.Substring(0, 4).ToUpper() == "THE ") cat = game.Name.Substring(4, 1).ToUpper();
            if (GroupNumbers && Char.IsDigit(cat[0])) cat = "#";
            if (Prefix!=null) cat = Prefix + cat;

            game.AddCategory(games.GetCategory(cat));

            return AutoCatResult.Success;
        }
Exemple #2
0
 public DlgGame( GameList data, GameInfo game = null )
     : this()
 {
     this.Data = data;
     Game = game;
     editMode = Game != null;
 }
        public override AutoCatResult CategorizeGame( GameInfo game, Filter filter ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) ) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            int year = db.GetReleaseYear( game.Id );
            if( year > 0 || IncludeUnknown ) {
                game.AddCategory( games.GetCategory( GetProcessedString( year ) ) );
            }

            return AutoCatResult.Success;
        }
Exemple #4
0
        private void cmdOk_Click( object sender, EventArgs e ) {
            if( editMode ) {
                Game.Name = txtName.Text;
                Game.Executable = txtExecutable.Text;
            } else {
                int id;
                if( !int.TryParse( txtId.Text, out id ) ) {
                    MessageBox.Show( GlobalStrings.DlgGameDBEntry_IDMustBeInteger, GlobalStrings.Gen_Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning );
                    return;
                }
                if( Data.Games.ContainsKey( id ) ) {
                    MessageBox.Show( GlobalStrings.DBEditDlg_GameIdAlreadyExists, GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error );
                    return;
                } else {
                    Game = new GameInfo( id, txtName.Text, Data, txtExecutable.Text );
                    Game.ApplySource( GameListingSource.Manual );
                    Data.Games.Add( id, Game );
                }
            }

            Game.SetFavorite( chkFavorite.Checked );

            Game.Hidden = chkHidden.Checked;

            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        public override AutoCatResult CategorizeGame( GameInfo game, Filter filter ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) || db.Games[game.Id].LastStoreScrape == 0 ) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            List<string> gameFlags = db.GetFlagList( game.Id );
            if( gameFlags == null ) gameFlags = new List<string>();
            IEnumerable<string> categories = gameFlags.Intersect( IncludedFlags );

            foreach( string catString in categories ) {
                Category c = games.GetCategory( GetProcessedString( catString ) );
                game.AddCategory( c );
            }
            return AutoCatResult.Success;
        }
        private void cmdOk_Click( object sender, EventArgs e )
        {
            if( editMode ) {
                Game.Name = txtName.Text;
            } else {
                int id;
                if( !int.TryParse( txtId.Text, out id ) ) {
                    MessageBox.Show(GlobalStrings.DlgGameDBEntry_IDMustBeInteger, GlobalStrings.DBEditDlg_Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                // jpodadera. Control if Game ID already exists to avoid exceptions
                if (Data.Games.ContainsKey(id))
                {
                    MessageBox.Show(GlobalStrings.DBEditDlg_GameIdAlreadyExists, GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    Game = new GameInfo(id, txtName.Text);
                    Data.Games.Add(id, Game);
                }
            }

            if( chkFavorite.Checked ) {
                Game.AddCategory( Data.FavoriteCategory );
            } else {
                Game.RemoveCategory( Data.FavoriteCategory );
            }
            Game.Hidden = chkHidden.Checked;

            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        public override AutoCatResult CategorizeGame( GameInfo game, Filter filter ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) ) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            return AutoCatResult.Success;
        }
        /// <summary>
        /// Adds an entry to the game list representing the given game.
        /// </summary>
        /// <param name="g">The game the new entry should represent.</param>
        private void AddGameToList( GameInfo g )
        {
            string catName = g.GetCatStringExcept( gameData.FavoriteCategory, GlobalStrings.MainForm_Uncategorized );

            ListViewItem item;

            // Shortcut games do not show internal identifier
            string strId = ( g.Id < 0 ) ? GlobalStrings.MainForm_External : g.Id.ToString();

            item = new ListViewItem( new string[] { strId, g.Name, catName, g.ContainsCategory( gameData.FavoriteCategory ) ? "X" : String.Empty, g.Hidden ? "X" : String.Empty } );

            item.Tag = g;

            // Shortcut games show with italic font.
            if( g.Id < 0 )
                item.Font = new Font( item.Font, item.Font.Style | FontStyle.Italic );
            lstGames.Items.Add( item );
        }
 void AddGameToCheckboxStates( GameInfo game, bool first )
 {
     ignoreCheckChanges = true;
     if( first ) {
         chkFavorite.CheckState = game.ContainsCategory( gameData.FavoriteCategory ) ? CheckState.Checked : CheckState.Unchecked;
         chkHidden.CheckState = game.Hidden ? CheckState.Checked : CheckState.Unchecked;
     } else {
         if( chkFavorite.CheckState != CheckState.Indeterminate ) {
             if( game.ContainsCategory( gameData.FavoriteCategory ) ) {
                 if( chkFavorite.CheckState == CheckState.Unchecked ) chkFavorite.CheckState = CheckState.Indeterminate;
             } else {
                 if( chkFavorite.CheckState == CheckState.Checked ) chkFavorite.CheckState = CheckState.Indeterminate;
             }
         }
         if( game.Hidden ) {
             if( chkHidden.CheckState == CheckState.Unchecked ) chkHidden.CheckState = CheckState.Indeterminate;
         } else {
             if( chkHidden.CheckState == CheckState.Checked ) chkHidden.CheckState = CheckState.Indeterminate;
         }
     }
     ignoreCheckChanges = false;
 }
 /// <summary>
 /// Checks to see if a game should currently be displayed, based on the state of the category list.
 /// </summary>
 /// <param name="g">Game to check</param>
 /// <returns>True if it should be displayed, false otherwise</returns>
 bool ShouldDisplayGame( GameInfo g )
 {
     if( !gameData.Games.ContainsKey( g.Id ) ) {
         return false;
     }
     if( lstCategories.SelectedItem == null ) {
         return false;
     }
     if( lstCategories.SelectedItem is string ) {
         if( (string)lstCategories.SelectedItem == GlobalStrings.MainForm_All ) {
             return true;
         }
         if( (string)lstCategories.SelectedItem == GlobalStrings.MainForm_Uncategorized ) {
             return !g.HasCategoriesExcept( gameData.FavoriteCategory );
         }
     } else if( lstCategories.SelectedItem is Category ) {
         return g.ContainsCategory( lstCategories.SelectedItem as Category );
     }
     return false;
 }
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }

            if (db == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }

            if (game == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull);
                return(AutoCatResult.Failure);
            }

            if (!db.Contains(game.Id) || db.Games[game.Id].LastStoreScrape == 0)
            {
                return(AutoCatResult.NotInDatabase);
            }

            if (!game.IncludeGame(filter))
            {
                return(AutoCatResult.Filtered);
            }

            List <string> devs = db.GetDevelopers(game.Id);

            if (devs != null)
            {
                for (int index = 0; index < devs.Count; index++)
                {
                    if (Developers.Contains(devs[index]) || AllDevelopers)
                    {
                        if (DevCount(devs[index]) >= MinCount)
                        {
                            game.AddCategory(games.GetCategory(GetProcessedString(devs[index])));
                        }
                    }
                }
            }

            List <string> pubs = db.GetPublishers(game.Id);

            if (pubs != null)
            {
                for (int index = 0; index < pubs.Count; index++)
                {
                    if (Publishers.Contains(pubs[index]) || AllPublishers)
                    {
                        if (PubCount(pubs[index]) >= MinCount)
                        {
                            game.AddCategory(games.GetCategory(GetProcessedString(pubs[index])));
                        }
                    }
                }
            }

            return(AutoCatResult.Success);
        }
Exemple #12
0
 /// <summary>
 /// Applies this autocategorization scheme to the game with the given ID.
 /// </summary>
 /// <param name="game">The GameInfo object to process</param>
 /// <returns>False if the game was not found in database. This allows the calling function to potentially re-scrape data and reattempt.</returns>
 public abstract AutoCatResult CategorizeGame( GameInfo game );
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_GamelistNull);

                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }

            if (db == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_DBNull);

                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }

            if (game == null)
            {
                Logger.Error(GlobalStrings.Log_AutoCat_GameNull);

                return(AutoCatResult.Failure);
            }

            if (!db.Contains(game.Id))
            {
                return(AutoCatResult.NotInDatabase);
            }

            if (!game.IncludeGame(filter))
            {
                return(AutoCatResult.Filtered);
            }

            int score   = db.Games[game.Id].ReviewPositivePercentage;
            int reviews = db.Games[game.Id].ReviewTotal;

            if (UseWilsonScore && (reviews > 0))
            {
                // calculate the lower bound of the Wilson interval for 95 % confidence
                // see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
                // $$ w^\pm = \frac{1}{1+\frac{z^2}{n}}
                // \left( \hat p + \frac{z^2}{2n} \pm z \sqrt{ \frac{\hat p (1 - \hat p)}{n} + \frac{z^2}{4n^2} } \right)$$
                // where
                // $\hat p$ is the observed fraction of positive ratings (proportion of successes),
                // $n$ is the total number of ratings (the sample size), and
                // $z$ is the $1-{\frac {\alpha}{2}}$ quantile of a standard normal distribution
                // for 95% confidence, the $z = 1.96$
                double z = 1.96;                 // normal distribution of (1-(1-confidence)/2), i.e. normal distribution of 0.975 for 95% confidence
                double p = score / 100.0;
                double n = reviews;
                p = Math.Round(100 * (((p + ((z * z) / (2 * n))) - (z * Math.Sqrt(((p * (1 - p)) + ((z * z) / (4 * n))) / n))) / (1 + ((z * z) / n))));
                // debug: System.Windows.Forms.MessageBox.Show("score " + score + " of " + reviews + " is\tp = " + p + "\n");
                score = Convert.ToInt32(p);
            }

            string result = null;

            foreach (UserScore_Rule rule in Rules)
            {
                if (CheckRule(rule, score, reviews))
                {
                    result = rule.Name;

                    break;
                }
            }

            if (result != null)
            {
                result = GetProcessedString(result);
                game.AddCategory(games.GetCategory(result));
            }

            return(AutoCatResult.Success);
        }
        public override AutoCatResult CategorizeGame( GameInfo game, Filter filter )
        {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) ) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            int score = db.Games[game.Id].ReviewPositivePercentage;
            int reviews = db.Games[game.Id].ReviewTotal;
            if( UseWilsonScore && reviews > 0 ) { // calculate the lower bound of the Wilson interval for 95 % confidence
                // see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
                // $$ w^\pm = \frac{1}{1+\frac{z^2}{n}}
                // \left( \hat p + \frac{z^2}{2n} \pm z \sqrt{ \frac{\hat p (1 - \hat p)}{n} + \frac{z^2}{4n^2} } \right)$$
                // where
                // $\hat p$ is the observed fraction of positive ratings (proportion of successes),
                // $n$ is the total number of ratings (the sample size), and
                // $z$ is the $1-{\frac {\alpha}{2}}$ quantile of a standard normal distribution
                // for 95% confidence, the $z = 1.96$
                double z = 1.96;    // normal distribution of (1-(1-confidence)/2), i.e. normal distribution of 0.975 for 95% confidence
                double p = score / 100.0;
                double n = reviews;
                p = Math.Round( 100 * ( (p + z*z/(2*n) - z * Math.Sqrt((p*(1-p) + z*z/(4*n)) / n)) / (1 + z*z/n) ) );
                // debug: System.Windows.Forms.MessageBox.Show("score " + score + " of " + reviews + " is\tp = " + p + "\n");
                score = Convert.ToInt32( p );
            }
            string result = null;
            foreach( UserScore_Rule rule in Rules ) {
                if( CheckRule( rule, score, reviews ) ) {
                    result = rule.Name;
                    break;
                }
            }

            if( result != null ) {
                result = GetProcessedString( result );
                game.AddCategory( games.GetCategory( result ) );
            }
            return AutoCatResult.Success;
        }
Exemple #15
0
        /// <summary>
        /// Adds a new game to the database, or updates an existing game with new information.
        /// </summary>
        /// <param name="appId">App ID to add or update</param>
        /// <param name="appName">Name of app to add, or update to</param>
        /// <param name="overwriteName">If true, will overwrite any existing games. If false, will fail if the game already exists.</param>
        /// <param name="ignore">Set of games to ignore. Can be null. If the game is in this list, no action will be taken.</param>
        /// <param name="forceInclude">If true, include the game even if it is of an ignored type.</param>
        /// <param name="src">The listing source that this request came from.</param>
        /// <param name="isNew">If true, a new game was added. If false, an existing game was updated, or the operation failed.</param>
        /// <returns>True if the game was integrated, false otherwise.</returns>
        private GameInfo IntegrateGame( int appId, string appName, bool overwriteName, SortedSet<int> ignore, AppTypes includedTypes, GameListingSource src, out bool isNew )
        {
            isNew = false;
            if( ( ignore != null && ignore.Contains( appId ) ) || !Program.GameDB.IncludeItemInGameList( appId, includedTypes ) ) {
                Program.Logger.Write( LoggerLevel.Verbose, GlobalStrings.GameData_SkippedIntegratingGame, appId, appName );
                return null;
            }

            GameInfo result = null;
            if( !Games.ContainsKey( appId ) ) {
                result = new GameInfo( appId, appName, this );
                Games.Add( appId, result );
                isNew = true;
            } else {
                result = Games[appId];
                if( overwriteName ) {
                    result.Name = appName;
                }
            }
            result.ApplySource( src );

            Program.Logger.Write( LoggerLevel.Verbose, GlobalStrings.GameData_IntegratedGameIntoGameList, appId, appName, isNew );
            return result;
        }
Exemple #16
0
        /// <summary>
        /// Adds a non-steam game to the gamelist.
        /// </summary>
        /// <param name="gameId">ID of the game in the steam config file</param>
        /// <param name="gameNode">Node for the game in the steam config file</param>
        /// <param name="launchIds">Dictionary of launch ids (name:launchId)</param>
        /// <param name="newGames">Number of NEW games that have been added to the list</param>
        /// <param name="preferSteamCategories">If true, prefers to use the categories from the steam config if there is a conflict. If false, prefers to use the categories from the existing gamelist.</param>
        /// <returns>True if the game was successfully added</returns>
        private bool IntegrateShortcut( int gameId, VdfFileNode gameNode, StringDictionary launchIds )
        {
            VdfFileNode nodeName = gameNode.GetNodeAt( new string[] { "appname" }, false );
            string gameName = ( nodeName != null ) ? nodeName.NodeString : null;
            // The ID of the created game must be negative
            int newId = -( gameId + 1 );

            // This should never happen, but just in case
            if( Games.ContainsKey( newId ) ) {
                return false;
            }

            //Create the new GameInfo
            GameInfo game = new GameInfo( newId, gameName, this );
            Games.Add( newId, game );

            // Fill in the LaunchString
            game.LaunchString = launchIds[gameName];

            // Fill in categories
            VdfFileNode tagsNode = gameNode.GetNodeAt( new string[] { "tags" }, false );
            foreach( KeyValuePair<string, VdfFileNode> tag in tagsNode.NodeArray ) {
                string tagName = tag.Value.NodeString;
                game.AddCategory( this.GetCategory( tagName ) );
            }

            // Fill in Hidden
            game.Hidden = false;
            if( gameNode.ContainsKey( "hidden" ) ) {
                VdfFileNode hiddenNode = gameNode["hidden"];
                game.Hidden = ( hiddenNode.NodeString == "1" || hiddenNode.NodeInt == 1 );
            }

            return true;
        }
Exemple #17
0
        /// <summary>
        /// Checks to see if a game should currently be displayed, based on the state of the category list.
        /// </summary>
        /// <param name="g">Game to check</param>
        /// <returns>True if it should be displayed, false otherwise</returns>
        bool ShouldDisplayGame( GameInfo g ) {
            if( currentProfile == null ) return false;
            if( txtSearch.Text != string.Empty && g.Name.IndexOf( txtSearch.Text, StringComparison.CurrentCultureIgnoreCase ) == -1 ) return false;
            if( !currentProfile.GameData.Games.ContainsKey( g.Id ) ) return false;
            if( g.Id < 0 && !currentProfile.IncludeShortcuts ) return false;

            if( lstCategories.SelectedItems.Count == 0 ) return false;


            if( AdvancedCategoryFilter ) {
                return ShouldDisplayGameAdvanced( g );
            }

            if (g.Hidden)
            {
                return (lstCategories.SelectedItems[0].Tag.ToString() == GlobalStrings.MainForm_Hidden);
            }


            if( lstCategories.SelectedItems[0].Tag is Category ) {
                return g.ContainsCategory( lstCategories.SelectedItems[0].Tag as Category );
            } else {
                if( lstCategories.SelectedItems[0].Tag.ToString() == GlobalStrings.MainForm_All ) {
                    return true;
                }
                if( lstCategories.SelectedItems[0].Tag.ToString() == GlobalStrings.MainForm_Uncategorized ) {
                    return !g.HasCategories();
                }
            }

            return false;
        }
Exemple #18
0
        bool ShouldDisplayGameAdvanced( GameInfo g ) {
            bool isCategorized = false;
            bool isHidden = false;
            if( advFilterUncatState != AdvancedFilterState.None ) isCategorized = g.HasCategories();
            if (advFilterHiddenState != AdvancedFilterState.None) isHidden = g.Hidden;

            if (advFilterUncatState == AdvancedFilterState.Require && isCategorized) return false;
            if (advFilterHiddenState == AdvancedFilterState.Require && !isHidden) return false;

            if (advFilterUncatState == AdvancedFilterState.Exclude && !isCategorized) return false;
            if (advFilterHiddenState == AdvancedFilterState.Exclude && isHidden) return false;

            if (advFilterUncatState == AdvancedFilterState.Allow || advFilterHiddenState == AdvancedFilterState.Allow || advFilterAllow.Count > 0)
            {
                if( advFilterUncatState != AdvancedFilterState.Allow || isCategorized ) {
                    if ( advFilterHiddenState != AdvancedFilterState.Allow || !isHidden )
                    {
                        if (!g.Categories.Overlaps(advFilterAllow)) return false;
                    }
                }
            }

            if( !g.Categories.IsSupersetOf( advFilterRequire ) ) return false;

            if( g.Categories.Overlaps( advFilterExclude ) ) return false;

            return true;
        }
Exemple #19
0
 private bool ShouldHideGame( GameInfo g ) {
     return !ShouldDisplayGame( g );
 }
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }
            if (db == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }
            if (game == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull);
                return AutoCatResult.Failure;
            }

            if (!db.Contains(game.Id) || db.Games[game.Id].LastStoreScrape == 0) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            List<string> devs = db.GetDevelopers(game.Id);

            if (devs != null)
            {
                for (int index = 0; index < devs.Count; index++)
                {
                    if (Developers.Contains(devs[index]) || AllDevelopers)
                    {
                        if (DevCount(devs[index]) >= MinCount) game.AddCategory(games.GetCategory(GetProcessedString(devs[index])));
                    }
                }
            }

            List<string> pubs = db.GetPublishers(game.Id);

            if (pubs != null)
            {
                for (int index = 0; index < pubs.Count; index++)
                {
                    if (Publishers.Contains(pubs[index]) || AllPublishers)
                    {
                        if (PubCount(pubs[index]) >= MinCount) game.AddCategory(games.GetCategory(GetProcessedString(pubs[index])));
                    }
                }
            }

            return AutoCatResult.Success;
        }
Exemple #21
0
 void AddRemoveCategoryContextMenu(GameInfo game)
 {
     foreach (Category c in game.Categories)
     {
         bool found = false;
         foreach (ToolStripItem i in contextGameRemCat.Items)
         {
             if (i.Text == c.Name) found = true;
         }
         if (!found)
         {
             ToolStripItem item = contextGameRemCat.Items.Add(c.Name);
             item.Tag = c;
             item.Click += contextGameRemCat_Category_Click;
         }
     }
 }
 void AddGameToMultiCatCheckStates( GameInfo game, bool first )
 {
     foreach( ListViewItem catItem in lstMultiCat.Items ) {
         if( catItem.StateImageIndex != 2 ) {
             Category cat = catItem.Tag as Category;
             if( cat != null ) {
                 if( first ) {
                     catItem.StateImageIndex = game.ContainsCategory( cat ) ? 1 : 0;
                 } else {
                     if( game.ContainsCategory( cat ) ) {
                         if( catItem.StateImageIndex == 0 ) catItem.StateImageIndex = 2;
                     } else {
                         if( catItem.StateImageIndex == 1 ) catItem.StateImageIndex = 2;
                     }
                 }
             }
         }
     }
 }
        public override AutoCatResult CategorizeGame( GameInfo game, Filter filter ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) || db.Games[game.Id].LastStoreScrape == 0 ) return AutoCatResult.NotInDatabase;

            if (!game.IncludeGame(filter)) return AutoCatResult.Filtered;

            List<string> gameTags = db.GetTagList( game.Id );

            if( gameTags != null ) {
                int added = 0;
                for( int index = 0; index < gameTags.Count && ( MaxTags == 0 || added < MaxTags ); index++ ) {
                    if( IncludedTags.Contains( gameTags[index] ) ) {
                        game.AddCategory( games.GetCategory( GetProcessedString( gameTags[index] ) ) );
                        added++;
                    }
                }
            }

            return AutoCatResult.Success;
        }
 /// <summary>
 /// Launchs selected game
 /// <param name="g">Game to launch</param>
 /// </summary>
 void LaunchGame( GameInfo g )
 {
     if( g != null ) {
         string gameIdentifier;
         if( g.Id < 0 ) {   // External game
             if( g.LaunchString == null ) {
                 MessageBox.Show( GlobalStrings.MainForm_LaunchFailed );
                 return;
             }
             gameIdentifier = g.LaunchString;
         } else {
             // Steam game
             gameIdentifier = g.Id.ToString();
         }
         System.Diagnostics.Process.Start( "steam://rungameid/" + gameIdentifier );
     }
 }
Exemple #25
0
 /// <summary>
 ///     Applies this autocategorization scheme to the game with the given ID.
 /// </summary>
 /// <param name="game">The GameInfo object to process</param>
 /// <returns>
 ///     False if the game was not found in database. This allows the calling function to potentially re-scrape data
 ///     and reattempt.
 /// </returns>
 public abstract AutoCatResult CategorizeGame(GameInfo game, Filter filter);
Exemple #26
0
 public DlgGame(GameList data, GameInfo game = null) : this()
 {
     Data     = data;
     Game     = game;
     editMode = Game != null;
 }
Exemple #27
0
 /// <summary>
 /// Applies this autocategorization scheme to the game with the given ID.
 /// </summary>
 /// <param name="game">The GameInfo object to process</param>
 /// <returns>False if the game was not found in database. This allows the calling function to potentially re-scrape data and reattempt.</returns>
 public abstract AutoCatResult CategorizeGame( GameInfo game, Filter filter );
Exemple #28
0
        /// <summary>
        /// Get LastPlayed date from a VDF node containing a list of games.
        /// Any games in the node not found in the game list will be added to the gamelist.
        /// </summary>
        /// <param name="appsNode">Node containing the game nodes</param>
        /// <param name="ignore">Set of games to ignore</param>
        /// <param name="forceInclude">Include games even if their type is not an included type</param>
        private void GetLastPlayedFromVdf(VdfFileNode appsNode, SortedSet<int> ignore, AppTypes includedTypes)
        {
            Dictionary<string, VdfFileNode> gameNodeArray = appsNode.NodeArray;
            if (gameNodeArray != null)
            {
                foreach (KeyValuePair<string, VdfFileNode> gameNodePair in gameNodeArray)
                {
                    int gameId;
                    if (int.TryParse(gameNodePair.Key, out gameId))
                    {
                        if ((ignore != null && ignore.Contains(gameId)) || !Program.GameDB.IncludeItemInGameList(gameId, includedTypes))
                        {
                            Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_SkippedProcessingGame, gameId);
                        }
                        else if (gameNodePair.Value != null && gameNodePair.Value.NodeType == ValueType.Array)
                        {
                            GameInfo game = null;

                            // Add the game to the list if it doesn't exist already
                            if (!Games.ContainsKey(gameId))
                            {
                                game = new GameInfo(gameId, Program.GameDB.GetName(gameId), this);
                                Games.Add(gameId, game);
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_AddedNewGame, gameId, game.Name);
                            }
                            else {
                                game = Games[gameId];
                            }

                            if (gameNodePair.Value.ContainsKey("LastPlayed") && gameNodePair.Value["LastPlayed"].NodeInt != 0)
                            {
                                DateTime dt = Utility.GetDTFromUTime(gameNodePair.Value["LastPlayed"].NodeInt);
                                if (dt > game.LastPlayed) game.LastPlayed = dt;
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_ProcessedGame, gameId, game.LastPlayed.ToString());
                            }
                        }
                    }
                }
            }
        }
        public override AutoCatResult CategorizeGame(GameInfo game, Filter filter)
        {
            if (games == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameList);
            }
            if (db == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull);
                throw new ApplicationException(GlobalStrings.AutoCatGenre_Exception_NoGameDB);
            }
            if (game == null)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull);
                return(AutoCatResult.Failure);
            }

            if (!db.Contains(game.Id) || db.Games[game.Id].LastStoreScrape == 0)
            {
                return(AutoCatResult.NotInDatabase);
            }

            if (!game.IncludeGame(filter))
            {
                return(AutoCatResult.Filtered);
            }

            if (RemoveAllCategories)
            {
                game.ClearCategories();
            }
            else if (RemoveCategories != null)
            {
                List <Category> removed = new List <Category>();

                foreach (string category in RemoveCategories)
                {
                    Category c = gamelist.GetCategory(category);
                    if (game.ContainsCategory(c))
                    {
                        game.RemoveCategory(c);
                        removed.Add(c);
                    }
                }

                foreach (Category c in removed)
                {
                    if (c.Count == 0)
                    {
                        gamelist.RemoveCategory(c);
                    }
                }
            }

            if (AddCategories != null)
            {
                foreach (string category in AddCategories)
                {
                    // add Category, or create it if it doesn't exist
                    game.AddCategory(gamelist.GetCategory(GetProcessedString(category)));
                }
            }

            return(AutoCatResult.Success);
        }
Exemple #30
0
        /// <summary>
        /// Loads in games from a VDF node containing a list of games.
        /// Any games in the node not found in the game list will be added to the gamelist.
        /// If a game in the node has a tags subnode, the "favorite" field will be overwritten.
        /// If a game in the node has a category set, it will overwrite any categories in the gamelist.
        /// If a game in the node does NOT have a category set, the category in the gamelist will NOT be cleared.
        /// </summary>
        /// <param name="appsNode">Node containing the game nodes</param>
        /// <param name="ignore">Set of games to ignore</param>
        /// <param name="forceInclude">Include games even if their type is not an included type</param>
        /// <returns>Number of games loaded</returns>
        private int IntegrateGamesFromVdf( VdfFileNode appsNode, SortedSet<int> ignore, AppTypes includedTypes )
        {
            int loadedGames = 0;

            Dictionary<string, VdfFileNode> gameNodeArray = appsNode.NodeArray;
            if( gameNodeArray != null ) {
                foreach( KeyValuePair<string, VdfFileNode> gameNodePair in gameNodeArray ) {
                    int gameId;
                    if( int.TryParse( gameNodePair.Key, out gameId ) ) {
                        if( ( ignore != null && ignore.Contains( gameId ) ) || !Program.GameDB.IncludeItemInGameList( gameId, includedTypes ) ) {
                            Program.Logger.Write( LoggerLevel.Verbose, GlobalStrings.GameData_SkippedProcessingGame, gameId );
                        } else if( gameNodePair.Value != null && gameNodePair.Value.NodeType == ValueType.Array ) {
                            GameInfo game = null;

                            // Add the game to the list if it doesn't exist already
                            if( !Games.ContainsKey( gameId ) ) {
                                game = new GameInfo( gameId, Program.GameDB.GetName( gameId ), this );
                                Games.Add( gameId, game );
                                Program.Logger.Write( LoggerLevel.Verbose, GlobalStrings.GameData_AddedNewGame, gameId, game.Name );
                            } else {
                                game = Games[gameId];
                            }

                            loadedGames++;

                            game.ApplySource( GameListingSource.SteamConfig );

                            game.Hidden = ( gameNodePair.Value.ContainsKey( "hidden" ) && gameNodePair.Value["hidden"].NodeInt != 0 );

                            VdfFileNode tagsNode = gameNodePair.Value["tags"];
                            if( tagsNode != null ) {
                                Dictionary<string, VdfFileNode> tagArray = tagsNode.NodeArray;
                                if( tagArray != null ) {
                                    List<Category> cats = new List<Category>( tagArray.Count );
                                    foreach( VdfFileNode tag in tagArray.Values ) {
                                        string tagName = tag.NodeString;
                                        if( tagName != null ) {
                                            Category c = GetCategory( tagName );
                                            if( c != null ) cats.Add( c );
                                        }
                                    }
                                    if( cats.Count > 0 ) {
                                        SetGameCategories( gameId, cats, false );
                                    }
                                }
                            }

                            Program.Logger.Write( LoggerLevel.Verbose, GlobalStrings.GameData_ProcessedGame, gameId, string.Join( ",", game.Categories ) );
                        }
                    }
                }
            }

            return loadedGames;
        }
Exemple #31
0
        private static void AddGameFromXmlNode( XmlNode node, Profile profile, int profileVersion ) {
            int id;
            if( XmlUtil.TryGetIntFromNode( node[XmlName_Game_Id], out id ) ) {
                GameListingSource source = XmlUtil.GetEnumFromNode<GameListingSource>( node[XmlName_Game_Source], GameListingSource.Unknown );

                if( source < GameListingSource.Manual && profile.IgnoreList.Contains( id ) ) {
                    return;
                }

                string name = XmlUtil.GetStringFromNode( node[XmlName_Game_Name], null );
                GameInfo game = new GameInfo( id, name, profile.GameData );
                game.Source = source;
                profile.GameData.Games.Add( id, game );

                game.Hidden = XmlUtil.GetBoolFromNode( node[XmlName_Game_Hidden], false );

                if( profileVersion < 1 ) {
                    string catName;
                    if( XmlUtil.TryGetStringFromNode( node[XmlName_Game_Category], out catName ) ) {
                        game.AddCategory( profile.GameData.GetCategory( catName ) );
                    }
                    if( ( node.SelectSingleNode( XmlName_Old_Game_Favorite ) != null ) ) {
                        game.SetFavorite( true );
                    }
                } else {
                    XmlNode catListNode = node.SelectSingleNode( XmlName_Game_CategoryList );
                    if( catListNode != null ) {
                        XmlNodeList catNodes = catListNode.SelectNodes( XmlName_Game_Category );
                        foreach( XmlNode cNode in catNodes ) {
                            string cat;
                            if( XmlUtil.TryGetStringFromNode( cNode, out cat ) ) {
                                game.AddCategory( profile.GameData.GetCategory( cat ) );
                            }
                        }
                    }
                }
            }
        }
        public override AutoCatResult CategorizeGame( GameInfo game ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) || db.Games[game.Id].LastStoreScrape == 0 ) return AutoCatResult.NotInDatabase;

            if( RemoveOtherGenres && genreCategories != null ) {
                game.RemoveCategory( genreCategories );
            }

            List<string> genreList = db.GetGenreList( game.Id, depth:MAX_PARENT_DEPTH, tagFallback:TagFallback );
            if( genreList != null && genreList.Count > 0 ) {
                List<Category> categories = new List<Category>();
                int max = MaxCategories;
                for( int i = 0; i < genreList.Count && ( MaxCategories == 0 || i < max ); i++ ) {
                    if( !IgnoredGenres.Contains( genreList[i] ) ) {
                        categories.Add( games.GetCategory( GetProcessedString( genreList[i] ) ) );
                    } else {
                        max++; // ignored genres don't contribute to max
                    }
                }

                game.AddCategory( categories );
            }
            return AutoCatResult.Success;
        }
        public override AutoCatResult CategorizeGame( GameInfo game ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) ) return AutoCatResult.NotInDatabase;

            int score = db.Games[game.Id].ReviewPositivePercentage;
            int reviews = db.Games[game.Id].ReviewTotal;
            string result = null;
            foreach( UserScore_Rule rule in Rules ) {
                if( CheckRule( rule, score, reviews ) ) {
                    result = rule.Name;
                    break;
                }
            }

            if( result != null ) {
                result = GetProcessedString( result );
                game.AddCategory( games.GetCategory( result ) );
            }
            return AutoCatResult.Success;
        }
Exemple #34
0
        public override AutoCatResult CategorizeGame( GameInfo game ) {
            if( games == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GamelistNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameList );
            }
            if( db == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_DBNull );
                throw new ApplicationException( GlobalStrings.AutoCatGenre_Exception_NoGameDB );
            }
            if( game == null ) {
                Program.Logger.Write( LoggerLevel.Error, GlobalStrings.Log_AutoCat_GameNull );
                return AutoCatResult.Failure;
            }

            if( !db.Contains( game.Id ) ) return AutoCatResult.NotInDatabase;

            string result = null;
            
            float hltbMain = db.Games[game.Id].HltbMain/60.0f;
            float hltbExtras = db.Games[game.Id].HltbExtras/60.0f;
            float hltbCompletionist = db.Games[game.Id].HltbCompletionist/60.0f;

            if (IncludeUnknown && hltbMain == 0.0f && hltbExtras == 0.0f && hltbCompletionist == 0.0f)
                result = UnknownText;
            else
            {
                foreach (Hltb_Rule rule in Rules)
                {
                    if (CheckRule(rule, hltbMain, hltbExtras, hltbCompletionist))
                    {
                        result = rule.Name;
                        break;
                    }
                }
            }

            if( result != null ) {
                result = GetProcessedString( result );
                game.AddCategory( games.GetCategory( result ) );
            }
            return AutoCatResult.Success;
        }
        private static void AddGameFromXmlNode( XmlNode node, Profile profile, int profileVersion )
        {
            int id;
            if( XmlUtil.TryGetIntFromNode( node["id"], out id ) ) {
                if( profile.IgnoreList.Contains( id ) || ( profile.IgnoreDlc && Program.GameDB.IsDlc( id ) ) ) {
                    return;
                }
                string name = XmlUtil.GetStringFromNode( node["name"], null );
                GameInfo game = new GameInfo( id, name );
                profile.GameData.Games.Add( id, game );

                game.Hidden = XmlUtil.GetBoolFromNode( node["hidden"], false );

                if( profileVersion < 1 ) {
                    string catName;
                    if( XmlUtil.TryGetStringFromNode( node["category"], out catName ) ) {
                        game.AddCategory( profile.GameData.GetCategory( catName ) );
                    }
                    if( ( node.SelectSingleNode( "favorite" ) != null ) ) {
                        game.AddCategory( profile.GameData.FavoriteCategory );
                    }
                } else {
                    XmlNode catListNode = node.SelectSingleNode( "categories" );
                    if( catListNode != null ) {
                        XmlNodeList catNodes = catListNode.SelectNodes( "category" );
                        foreach( XmlNode cNode in catNodes ) {
                            string cat;
                            if( XmlUtil.TryGetStringFromNode( cNode, out cat ) ) {
                                game.AddCategory( profile.GameData.GetCategory( cat ) );
                            }
                        }
                    }
                }
            }
        }