예제 #1
0
 public DlgGame( GameData data, Game game = null )
     : this()
 {
     this.Data = data;
     Game = game;
     editMode = Game != null;
 }
예제 #2
0
 /// <summary>
 /// Launchs selected game
 /// <param name="g">Game to launch</param>
 /// </summary>
 void LaunchGame( Game g )
 {
     if (g != null)
     {
         string gameIdentifier;
         if (g.Id < 0)
         {   // External game
             ulong externalId = ((ulong)g.Id << 32) + 0X2000000;
             gameIdentifier = externalId.ToString();
         }
         else
         {
             // Steam game
             gameIdentifier = g.Id.ToString();
         }
         System.Diagnostics.Process.Start("steam://rungameid/" + gameIdentifier);
     }
 }
예제 #3
0
        /// <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( Game g )
        {
            string catName = ( g.Category == null ) ? CatUtil.CAT_UNC_NAME : g.Category.Name;

            // jpodadera. Change favorite column contents from Y-N to X or blank
            ListViewItem item;
            // jpodadera. Shortcut games do not show internal identifier
            string strId = (g.Id < 0) ? GlobalStrings.MainForm_External : g.Id.ToString();
            if (chkGroupCategory.Checked)
            {
                item = new ListViewItem(new string[] { strId, g.Name, g.Favorite ? "X" : String.Empty });
            }
            else
            {
                item = new ListViewItem(new string[] { strId, g.Name, catName, g.Favorite ? "X" : String.Empty });
            }
            item.Tag = g;
            // jpodadera. 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);
            AssignItemToGroup(item);
        }
예제 #4
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( Game g )
 {
     if( !gameData.Games.ContainsKey( g.Id ) ) {
         return false;
     }
     if( lstCategories.SelectedItem == null ) {
         return false;
     }
     if( lstCategories.SelectedItem is string ) {
         if( (string)lstCategories.SelectedItem == CatUtil.CAT_ALL_NAME ) {
             return true;
         }
         if( (string)lstCategories.SelectedItem == CatUtil.CAT_FAV_NAME ) {
             return g.Favorite;
         }
         if( (string)lstCategories.SelectedItem == CatUtil.CAT_UNC_NAME ) {
             return g.Category == null;
         }
     } else if( lstCategories.SelectedItem is Category ) {
         return g.Category == (Category)lstCategories.SelectedItem;
     }
     return false;
 }
예제 #5
0
        private static void AddGameFromXmlNode( XmlNode node, Profile profile ) {
            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 );
                Game game = new Game( id, name );
                profile.GameData.Games.Add( id, game );

                string catName;
                if( XmlUtil.TryGetStringFromNode( node["category"], out catName ) ) {
                    game.Category = profile.GameData.GetCategory( catName );
                }

                game.Favorite = ( node.SelectSingleNode( "favorite" ) != null );
            }
        }
예제 #6
0
        private void cmdOk_Click( object sender, EventArgs e ) {
            Category setCat = null;

            if( !CatUtil.StringToCategory( cmbCategory.Text, Data, out setCat ) ) {
                return;
            }
            
            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 Game(id, txtName.Text);
                    Data.Games.Add(id, Game);
                }
            }
            Game.Category = setCat;
            Game.Favorite = chkFavorite.Checked;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
예제 #7
0
        private int ImportNonSteamGames(long SteamId, SortedSet<int> ignore)
        {
            int result = 0;
            string filePath = string.Format(Properties.Resources.ShortCutsFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));
            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameData_OpeningSteamConfigFile, filePath);

            Dictionary<string, int> shortcutgames;
            if (LoadShortcutGames(SteamId, out shortcutgames))
            {
                FileStream fStream = null;
                BinaryReader binReader = null;
                BinaryVdfFileNode dataRoot = null;
                try
                {
                    fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    binReader = new BinaryReader(fStream);
                    dataRoot = BinaryVdfFileNode.Load(binReader);
                }
                finally
                {
                    if (binReader != null)
                    {
                        binReader.Close();
                    }
                    if (fStream != null)
                    {
                        fStream.Close();
                    }
                }
                if (dataRoot != null)
                {
                    VdfFileNode shortcutsNode = dataRoot.GetNodeAt(new string[] { "shortcuts" }, false);
                    foreach (KeyValuePair<string, VdfFileNode> shortcutPair in shortcutsNode.NodeArray)
                    {
                        string indexGame = shortcutPair.Key;

                        VdfFileNode attrGame = shortcutPair.Value;
                        VdfFileNode appGame = attrGame.GetNodeAt(new string[] { "appname" }, false);

                        string gameName = appGame.NodeString;

                        // Check if external game has identifier in screenshots.vdf file (this happens only if game has been launched before from Steam client)
                        if (shortcutgames.ContainsKey(gameName))
                        {
                            int gameIdInDB = shortcutgames[gameName];
                            if (!ignore.Contains(gameIdInDB))
                            {
                                Game gameDB;
                                if (Games.ContainsKey(gameIdInDB))
                                {
                                    gameDB = Games[gameIdInDB];
                                }
                                else
                                {
                                    gameDB = new Game(gameIdInDB, gameName);
                                }

                                string cat0 = null, cat1 = null;
                                VdfFileNode tagsGame = attrGame.GetNodeAt(new string[] { "tags" }, false);
                                if ((tagsGame != null) && (tagsGame.NodeType == ValueType.Array) &&
                                    (tagsGame.NodeArray.Count > 0) && (tagsGame.NodeArray.ContainsKey("0")))
                                {
                                    VdfFileNode vdfCat = tagsGame.NodeArray["0"];
                                    if (vdfCat.NodeType == ValueType.Value)
                                    {
                                        cat0 = vdfCat.NodeData.ToString();
                                    }
                                    if (tagsGame.NodeArray.ContainsKey("1"))
                                    {
                                        vdfCat = tagsGame.NodeArray["1"];
                                        if (vdfCat.NodeType == ValueType.Value)
                                        {
                                            cat1 = vdfCat.NodeData.ToString();
                                        }
                                    }
                                }
                                gameDB.Favorite = ((cat0 == "favorite") || (cat1 == "favorite"));
                                if (cat0 != "favorite")
                                {
                                    gameDB.Category = GetCategory(cat0);
                                }
                                else
                                {
                                    gameDB.Category = GetCategory(cat1);
                                }
                                result++;
                            }
                        }
                    }

                }
            }
            return result;
        }
예제 #8
0
        /// <summary>
        /// Loads in games from an node containing a list of games.
        /// </summary>
        /// <param name="appsNode">Node containing the game nodes</param>
        /// <param name="ignore">Set of games to ignore</param>
        /// <returns>Number of games loaded</returns>
        private int GetDataFromVdf(VdfFileNode appsNode, SortedSet<int> ignore, bool ignoreDlc )
        {
            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 ) ) || ( ignoreDlc && Program.GameDB.IsDlc( gameId ) ) ) {
                            Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_SkippedProcessingGame, gameId);
                            continue;
                        }
                        if( gameNodePair.Value != null && gameNodePair.Value.ContainsKey( "tags" ) ) {
                            Category cat = null;
                            bool fav = false;
                            loadedGames++;
                            VdfFileNode tagsNode = gameNodePair.Value["tags"];
                            Dictionary<string, VdfFileNode> tagArray = tagsNode.NodeArray;
                            if( tagArray != null ) {
                                foreach( VdfFileNode tag in tagArray.Values ) {
                                    string tagName = tag.NodeString;
                                    if( tagName != null ) {
                                        if( tagName == "favorite" ) {
                                            fav = true;
                                        } else {
                                            cat = GetCategory( tagName );
                                        }
                                    }
                                }
                            }

                            if( !Games.ContainsKey( gameId ) ) {
                                Game newGame = new Game( gameId, string.Empty );
                                Games.Add( gameId, newGame );
                                newGame.Name = Program.GameDB.GetName( gameId );
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_AddedNewGame, gameId, newGame.Name);
                            }
                            Games[gameId].Category = cat;
                            Games[gameId].Favorite = fav;
                            Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_ProcessedGame, gameId, (cat == null) ? "~none~" : cat.ToString(), fav);
                        }
                    }
                }
            }

            return loadedGames;
        }
예제 #9
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="oldShortcuts">List of un-matched non-steam games from the gamelist before the update</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, List<Game> oldShortcuts, StringDictionary launchIds, ref int newGames, bool preferSteamCategories = true ) {
            VdfFileNode nodeName = gameNode.GetNodeAt( new string[] { "appname" }, false );
            string gameName = ( nodeName != null ) ? nodeName.NodeString : null;
            int newId = -gameId;

            if( Games.ContainsKey( newId ) ) {
                return false;
            }

            Game game = new Game( newId, gameName );
            Games.Add( newId, game );

            game.LaunchString = launchIds[gameName];

            int oldShortcutId = FindMatchingShortcut( gameId, gameNode, oldShortcuts, launchIds );
            bool oldCatSet = ( oldShortcutId != -1 ) && oldShortcuts[oldShortcutId].Category != null;
            if( oldShortcutId == -1 ) newGames++;
            
            VdfFileNode tagsNode = gameNode.GetNodeAt( new string[] { "tags" }, false );
            bool steamCatSet = ( tagsNode != null && tagsNode.NodeType == ValueType.Array && tagsNode.NodeArray.Count > 0 );
            
            //fill in categories
            if( steamCatSet && (preferSteamCategories || !oldCatSet) )  {
                foreach( KeyValuePair<string, VdfFileNode> tag in tagsNode.NodeArray) {
                    string tagName = tag.Value.NodeString;
                    if( tagName != null ) {
                        if( tagName == "favorite" ) {
                            game.Favorite = true;
                        } else {
                            game.Category = this.GetCategory( tagName );
                        }
                    }
                }

            } else {
                game.Category = oldShortcuts[oldShortcutId].Category;
                game.Favorite = oldShortcuts[oldShortcutId].Favorite;
            }

            if( oldShortcutId != -1 ) oldShortcuts.RemoveAt( oldShortcutId );
            return true;
        }
예제 #10
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( Game 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_Favorite ) {
             return g.Favorite;
         }
         if( (string)lstCategories.SelectedItem == GlobalStrings.MainForm_Uncategorized ) {
             return g.Category == null;
         }
     } else if( lstCategories.SelectedItem is Category ) {
         return g.Category == (Category)lstCategories.SelectedItem;
     }
     return false;
 }