public DlgAutomaticModeHelper( Profile profile ) {
     InitializeComponent();
     this.profile = profile;
     ttHelp.Ext_SetToolTip( hlpExport, GlobalStrings.AutoMode_Help_Export );
     ttHelp.Ext_SetToolTip( hlpImportCats, GlobalStrings.AutoMode_Help_ImportCats );
     ttHelp.Ext_SetToolTip( hlpLaunch, GlobalStrings.AutoMode_Help_Launch );
     ttHelp.Ext_SetToolTip( hlpOutput, GlobalStrings.AutoMode_Help_Output );
     ttHelp.Ext_SetToolTip( hlpSaveDB, GlobalStrings.AutoMode_Help_SaveDB );
     ttHelp.Ext_SetToolTip( hlpSaveProfile, GlobalStrings.AutoMode_Help_SaveProfile );
     ttHelp.Ext_SetToolTip( hlpSteamCheck, GlobalStrings.AutoMode_Help_SteamCheck );
     ttHelp.Ext_SetToolTip( hlpTolerant, GlobalStrings.AutoMode_Help_Tolerant );
     ttHelp.Ext_SetToolTip( hlpUpdateAppInfo, GlobalStrings.AutoMode_Help_UpdateAppInfo );
     ttHelp.Ext_SetToolTip( hlpUpdateLib, GlobalStrings.AutoMode_Help_UpdateLib );
     ttHelp.Ext_SetToolTip( hlpUpdateWeb, GlobalStrings.AutoMode_Help_UpdateWeb );
     ttHelp.Ext_SetToolTip(hlpUpdateHltb, GlobalStrings.AutoMode_Help_UpdateHltb);
 }
Esempio n. 2
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 );
            }
        }
Esempio n. 3
0
        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 ) );
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Unloads the current profile or game list, making sure the user gets the option to save any changes.
 /// </summary>
 /// <returns>True if there is now no loaded profile, false otherwise.</returns>
 void Unload() {
     if( !CheckForUnsaved() ) return;
     AddStatus( GlobalStrings.MainForm_ClearedData );
     currentProfile = null;
     MakeChange( false );
     OnProfileChange();
     FullListRefresh();
 }
Esempio n. 5
0
        public static Profile Load( string path ) {
            Program.Logger.Write( LoggerLevel.Info, GlobalStrings.Profile_LoadingProfile, path );
            Profile profile = new Profile();

            profile.FilePath = path;

            XmlDocument doc = new XmlDocument();

            try {
                doc.Load( path );
            } catch( Exception e ) {
                Program.Logger.Write( LoggerLevel.Warning, GlobalStrings.Profile_FailedToLoadProfile, e.Message );
                throw new ApplicationException( GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e );
            }

            XmlNode profileNode = doc.SelectSingleNode( "/" + XmlName_Profile );

            if( profileNode != null ) {
                // Get the profile version that we're loading
                XmlAttribute versionAttr = profileNode.Attributes[XmlName_Version];
                int profileVersion = 0;
                if( versionAttr != null ) {
                    if( !int.TryParse( versionAttr.Value, out profileVersion ) ) {
                        profileVersion = 0;
                    }
                }
                // Get the 64-bit Steam ID
                Int64 accId = XmlUtil.GetInt64FromNode( profileNode[XmlName_SteamID], 0 );
                if( accId == 0 ) {
                    string oldAcc = XmlUtil.GetStringFromNode( profileNode[XmlName_Old_SteamIDShort], null );
                    if( oldAcc != null ) {
                        accId = DirNametoID64( oldAcc );
                    }
                }
                profile.SteamID64 = accId;

                // Get other attributes
                if( profileVersion < 3 ) {
                    profile.AutoUpdate = XmlUtil.GetBoolFromNode( profileNode[XmlName_Old_AutoDownload], profile.AutoUpdate );
                } else {
                    profile.AutoUpdate = XmlUtil.GetBoolFromNode( profileNode[XmlName_AutoUpdate], profile.AutoUpdate );
                }

                profile.AutoImport = XmlUtil.GetBoolFromNode( profileNode[XmlName_AutoImport], profile.AutoImport );
                profile.AutoExport = XmlUtil.GetBoolFromNode( profileNode[XmlName_AutoExport], profile.AutoExport );

                profile.LocalUpdate = XmlUtil.GetBoolFromNode( profileNode[XmlName_LocalUpdate], profile.LocalUpdate );
                profile.WebUpdate = XmlUtil.GetBoolFromNode( profileNode[XmlName_WebUpdate], profile.WebUpdate );

                profile.IncludeUnknown = XmlUtil.GetBoolFromNode( profileNode[XmlName_IncludeUnknown], profile.IncludeUnknown );
                profile.BypassIgnoreOnImport = XmlUtil.GetBoolFromNode( profileNode[XmlName_BypassIgnoreOnImport], profile.BypassIgnoreOnImport );

                profile.ExportDiscard = XmlUtil.GetBoolFromNode( profileNode[XmlName_ExportDiscard], profile.ExportDiscard );
                profile.AutoIgnore = XmlUtil.GetBoolFromNode( profileNode[XmlName_AutoIgnore], profile.AutoIgnore );
                profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode( profileNode[XmlName_OverwriteNames], profile.OverwriteOnDownload );

                if( profileVersion < 2 ) {
                    bool ignoreShortcuts = false;
                    if( XmlUtil.TryGetBoolFromNode( profileNode[XmlName_Old_IgnoreExternal], out ignoreShortcuts ) ) {
                        profile.IncludeShortcuts = !ignoreShortcuts;
                    }
                } else {
                    profile.IncludeShortcuts = XmlUtil.GetBoolFromNode( profileNode[XmlName_IncludeShortcuts], profile.IncludeShortcuts );
                }

                XmlNode exclusionListNode = profileNode.SelectSingleNode( XmlName_ExclusionList );
                if( exclusionListNode != null ) {
                    XmlNodeList exclusionNodes = exclusionListNode.SelectNodes( XmlName_Exclusion );
                    foreach( XmlNode node in exclusionNodes ) {
                        int id;
                        if( XmlUtil.TryGetIntFromNode( node, out id ) ) {
                            profile.IgnoreList.Add( id );
                        }
                    }
                }

                XmlNode gameListNode = profileNode.SelectSingleNode( XmlName_GameList );
                if( gameListNode != null ) {
                    XmlNodeList gameNodes = gameListNode.SelectNodes( XmlName_Game );
                    foreach( XmlNode node in gameNodes ) {
                        AddGameFromXmlNode( node, profile, profileVersion );
                    }
                }

                XmlNode autocatListNode = profileNode.SelectSingleNode( XmlName_AutoCatList );
                if( autocatListNode != null ) {
                    XmlNodeList autoCatNodes = autocatListNode.ChildNodes;
                    foreach( XmlNode node in autoCatNodes ) {
                        XmlElement autocatElement = node as XmlElement;
                        if( node != null ) {
                            AutoCat autocat = AutoCat.LoadACFromXmlElement( autocatElement );
                            if( autocat != null ) {
                                profile.AutoCats.Add( autocat );
                            }
                        }
                    }
                } else {
                    GenerateDefaultAutoCatSet( profile.AutoCats );
                }
                profile.AutoCats.Sort();
            }
            Program.Logger.Write( LoggerLevel.Info, GlobalStrings.MainForm_ProfileLoaded );
            return profile;
        }
Esempio n. 6
0
        /// <summary>
        /// Unloads the current profile or game list, making sure the user gets the option to save any changes.
        /// </summary>
        /// <param name="updateUI">If true, will redraw the UI. Otherwise, will leave it up to the caller to do so.</param>
        /// <returns>True if there is now no loaded profile, false otherwise.</returns>
        void Unload( bool updateUI = true )
        {
            if( !CheckForUnsaved() ) {
                return;
            }

            AddStatus( GlobalStrings.MainForm_ClearedData );
            currentProfile = null;
            gameData = new GameList();
            MakeChange( false );
            OnProfileChange();
            if( updateUI ) {
                FullListRefresh();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Prompts user to create a new profile.
        /// </summary>
        void CreateProfile() {
            DlgProfile dlg = new DlgProfile();
            DialogResult res = dlg.ShowDialog();
            if( res == System.Windows.Forms.DialogResult.OK ) {
                Cursor = Cursors.WaitCursor;
                currentProfile = dlg.Profile;
                AddStatus( GlobalStrings.MainForm_ProfileCreated );
                if( dlg.DownloadNow ) {
                    UpdateLibrary();
                }

                if( dlg.ImportNow ) {
                    ImportConfig();
                }
                if( dlg.SetStartup ) {
                    Settings.Instance.StartupAction = StartupAction.Load;
                    Settings.Instance.ProfileToLoad = currentProfile.FilePath;
                    Settings.Instance.Save();
                }

                FullListRefresh();

                Cursor = Cursors.Default;
            }
            OnProfileChange();
        }
Esempio n. 8
0
        /// <summary>
        /// Integrate external games defined by Steam user. Only external games with identifier in screenshot.vdf file are included in game DB.
        /// </summary>
        /// <param name="SteamId">Identifier of Steam user</param>
        /// <param name="overWrite">Overwrite actual contents of game DB</param>
        /// <param name="ignore">List of identifiers of games to be ignored</param>
        /// <param name="newItems">Returns number of new games integrated</param>
        /// <returns>Returns number of external games located</returns>
        public int IntegrateNonSteamGameList(long SteamId, bool overWrite, SortedSet <int> ignore, out int newItems, out int removedItems)
        {
            newItems     = 0;
            removedItems = 0;
            if (SteamId <= 0)
            {
                return(0);
            }
            int loadedGames = 0;

            Dictionary <string, int> shortcutgames;

            if (LoadShortcutGames(SteamId, out shortcutgames))
            {
                string       filePath  = string.Format(Properties.Resources.ShortCutsFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));
                FileStream   fStream   = null;
                BinaryReader binReader = null;
                try
                {
                    fStream   = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    binReader = new BinaryReader(fStream);

                    BinaryVdfFileNode dataRoot = BinaryVdfFileNode.Load(binReader);

                    VdfFileNode shortcutsNode = dataRoot.GetNodeAt(new string[] { "shortcuts" }, false);

                    if (shortcutsNode != null)
                    {
                        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))
                            {
                                bool isNew;
                                if (IntegrateGame(shortcutgames[gameName], gameName, overWrite, ignore, false, out isNew))
                                {
                                    loadedGames++;
                                    if (isNew)
                                    {
                                        newItems++;
                                    }
                                }
                                shortcutgames.Remove(gameName);
                            }
                        }
                    }
                    // Remove external games which have been deleted from Steam client
                    foreach (KeyValuePair <string, int> shortcutpair in shortcutgames)
                    {
                        if (RemoveGame(shortcutpair.Value))
                        {
                            removedItems++;
                        }
                    }
                }
                catch (FileNotFoundException e)
                {
                    Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorOpeningConfigFileParam, e.ToString());
                    //throw new ApplicationException(string.Format(GlobalStrings.GameData_ErrorOpeningConfigFileParam, filePath) + e.Message, e);
                }
                catch (IOException e)
                {
                    Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_LoadingErrorSteamConfig, e.ToString());
                }
                catch (ParseException e)
                {
                    Program.Logger.Write(LoggerLevel.Error, e.ToString());
                }
                finally
                {
                    if (binReader != null)
                    {
                        binReader.Close();
                    }
                    if (fStream != null)
                    {
                        fStream.Close();
                    }
                }
            }

            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameData_IntegratedShortCuts, loadedGames, newItems, removedItems);

            return(loadedGames);
        }
Esempio n. 9
0
        public static Profile Load(string path)
        {
            Program.Logger.Info(GlobalStrings.Profile_LoadingProfile, path);
            Profile profile = new Profile();

            profile.FilePath = path;

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(path);
            }
            catch (Exception e)
            {
                Program.Logger.Warn(GlobalStrings.Profile_FailedToLoadProfile, e.Message);
                throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e);
            }

            XmlNode profileNode = doc.SelectSingleNode("/" + XmlName_Profile);

            if (profileNode != null)
            {
                // Get the profile version that we're loading
                XmlAttribute versionAttr    = profileNode.Attributes[XmlName_Version];
                int          profileVersion = 0;
                if (versionAttr != null)
                {
                    if (!int.TryParse(versionAttr.Value, out profileVersion))
                    {
                        profileVersion = 0;
                    }
                }

                // Get the 64-bit Steam ID
                long accId = XmlUtil.GetInt64FromNode(profileNode[XmlName_SteamID], 0);
                if (accId == 0)
                {
                    string oldAcc = XmlUtil.GetStringFromNode(profileNode[XmlName_Old_SteamIDShort], null);
                    if (oldAcc != null)
                    {
                        accId = DirNametoID64(oldAcc);
                    }
                }

                profile.SteamID64 = accId;

                // Get other attributes
                profile.AutoUpdate = XmlUtil.GetBoolFromNode(profileVersion < 3 ? profileNode[XmlName_Old_AutoDownload] : profileNode[XmlName_AutoUpdate], profile.AutoUpdate);

                profile.AutoImport = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoImport], profile.AutoImport);
                profile.AutoExport = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoExport], profile.AutoExport);

                profile.LocalUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlName_LocalUpdate], profile.LocalUpdate);
                profile.WebUpdate   = XmlUtil.GetBoolFromNode(profileNode[XmlName_WebUpdate], profile.WebUpdate);

                profile.IncludeUnknown       = XmlUtil.GetBoolFromNode(profileNode[XmlName_IncludeUnknown], profile.IncludeUnknown);
                profile.BypassIgnoreOnImport = XmlUtil.GetBoolFromNode(profileNode[XmlName_BypassIgnoreOnImport], profile.BypassIgnoreOnImport);

                profile.ExportDiscard       = XmlUtil.GetBoolFromNode(profileNode[XmlName_ExportDiscard], profile.ExportDiscard);
                profile.AutoIgnore          = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoIgnore], profile.AutoIgnore);
                profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode(profileNode[XmlName_OverwriteNames], profile.OverwriteOnDownload);

                if (profileVersion < 2)
                {
                    bool ignoreShortcuts = false;
                    if (XmlUtil.TryGetBoolFromNode(profileNode[XmlName_Old_IgnoreExternal], out ignoreShortcuts))
                    {
                        profile.IncludeShortcuts = !ignoreShortcuts;
                    }
                }
                else
                {
                    profile.IncludeShortcuts = XmlUtil.GetBoolFromNode(profileNode[XmlName_IncludeShortcuts], profile.IncludeShortcuts);
                }

                XmlNode exclusionListNode = profileNode.SelectSingleNode(XmlName_ExclusionList);
                if (exclusionListNode != null)
                {
                    XmlNodeList exclusionNodes = exclusionListNode.SelectNodes(XmlName_Exclusion);
                    foreach (XmlNode node in exclusionNodes)
                    {
                        int id;
                        if (XmlUtil.TryGetIntFromNode(node, out id))
                        {
                            profile.IgnoreList.Add(id);
                        }
                    }
                }

                XmlNode gameListNode = profileNode.SelectSingleNode(XmlName_GameList);
                if (gameListNode != null)
                {
                    XmlNodeList gameNodes = gameListNode.SelectNodes(XmlName_Game);
                    foreach (XmlNode node in gameNodes)
                    {
                        AddGameFromXmlNode(node, profile, profileVersion);
                    }
                }

                XmlNode filterListNode = profileNode.SelectSingleNode(XmlName_FilterList);
                if (filterListNode != null)
                {
                    XmlNodeList filterNodes = filterListNode.SelectNodes(XmlName_Filter);
                    foreach (XmlNode node in filterNodes)
                    {
                        AddFilterFromXmlNode(node, profile);
                    }
                }

                XmlNode autocatListNode = profileNode.SelectSingleNode(XmlName_AutoCatList);
                if (autocatListNode != null)
                {
                    XmlNodeList autoCatNodes = autocatListNode.ChildNodes;
                    foreach (XmlNode node in autoCatNodes)
                    {
                        XmlElement autocatElement = node as XmlElement;
                        if (node != null)
                        {
                            AutoCat autocat = AutoCat.LoadACFromXmlElement(autocatElement);
                            if (autocat != null)
                            {
                                profile.AutoCats.Add(autocat);
                            }
                        }
                    }
                }
                else
                {
                    GenerateDefaultAutoCatSet(profile.AutoCats);
                }

                //profile.AutoCats.Sort();
            }

            Program.Logger.Info(GlobalStrings.MainForm_ProfileLoaded);
            return(profile);
        }
Esempio n. 10
0
        /// <summary>
        /// Writes category info for shortcut games to shortcuts.vdf config file for specified Steam user.
        /// </summary>
        /// <param name="SteamId">Identifier of Steam user to save information</param>
        /// <param name="discardMissing">If true, category information in shortcuts.vdf file is removed if game is not in Game list</param>
        private void SaveShortcutGames(long SteamId, bool discardMissing)
        {
            string screenshotsFilePath = string.Format(Properties.Resources.ScreenshotsFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));

            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameData_SavingSteamConfigFile, screenshotsFilePath);

            Dictionary <string, int> shortcutgames;

            if (LoadShortcutGames(SteamId, out shortcutgames))
            {
                string            filePath  = string.Format(Properties.Resources.ShortCutsFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));
                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);
                }
                catch (FileNotFoundException e)
                {
                    Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorOpeningConfigFileParam, e.ToString());
                }
                catch (IOException e)
                {
                    Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_LoadingErrorSteamConfig, e.ToString());
                }
                if (binReader != null)
                {
                    binReader.Close();
                }
                if (fStream != null)
                {
                    fStream.Close();
                }
                if (dataRoot != null)
                {
                    List <KeyValuePair <string, int>?> listShortCutGames = new List <KeyValuePair <string, int>?>();
                    VdfFileNode appsNode = dataRoot.GetNodeAt(new string[] { "shortcuts" }, false);
                    foreach (KeyValuePair <string, VdfFileNode> shortcutPair in appsNode.NodeArray)
                    {
                        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))
                        {
                            VdfFileNode tagsNode = attrGame.GetNodeAt(new string[] { "tags" }, false);
                            int         idGame   = shortcutgames[gameName];
                            if (Games.ContainsKey(idGame))
                            {
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_AddingGameToConfigFile, idGame);
                                tagsNode.NodeArray.Clear();
                                Game game = Games[idGame];
                                if ((game.Category != null) || (game.Favorite))
                                {
                                    int index = 0;
                                    if (game.Category != null)
                                    {
                                        tagsNode.NodeArray.Add(index.ToString(), new BinaryVdfFileNode(game.Category.Name));
                                        index++;
                                    }
                                    if (game.Favorite)
                                    {
                                        tagsNode.NodeArray.Add(index.ToString(), new BinaryVdfFileNode("favorite"));
                                    }
                                }
                            }
                            else if (discardMissing)
                            {
                                Program.Logger.Write(LoggerLevel.Verbose, GlobalStrings.GameData_RemovingGameCategoryFromSteamConfig, idGame);
                                tagsNode.NodeArray.Clear();
                            }
                        }
                    }
                    if (dataRoot.NodeType == ValueType.Array)
                    {
                        Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameData_SavingShortcutConfigFile, filePath);
                        BinaryWriter binWriter;
                        try
                        {
                            fStream   = new FileStream(filePath, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite);
                            binWriter = new BinaryWriter(fStream);
                            dataRoot.Save(binWriter);
                            binWriter.Close();
                            fStream.Close();
                        }
                        catch (ArgumentException e)
                        {
                            Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorSavingSteamConfigFile, e.ToString());
                            throw new ApplicationException(GlobalStrings.GameData_FailedToSaveSteamConfigBadPath, e);
                        }
                        catch (IOException e)
                        {
                            Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorSavingSteamConfigFile, e.ToString());
                            throw new ApplicationException(GlobalStrings.GameData_FailedToSaveSteamConfigFile + e.Message, e);
                        }
                        catch (UnauthorizedAccessException e)
                        {
                            Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorSavingSteamConfigFile, e.ToString());
                            throw new ApplicationException(GlobalStrings.GameData_AccessDeniedSteamConfigFile + e.Message, e);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Load identifiers for external games from screenshots.vdf
        /// </summary>
        /// <param name="SteamId">Steam user identifier</param>
        /// <param name="shortcutGames">Found games listed as pairs of {gameName, gameId} </param>
        /// <returns></returns>
        private bool LoadShortcutGames(long SteamId, out Dictionary <string, int> shortcutGames)
        {
            bool   result   = false;
            string filePath = string.Format(Properties.Resources.ScreenshotsFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));

            shortcutGames = new Dictionary <string, int>();

            StreamReader reader = null;

            try
            {
                reader = new StreamReader(filePath, false);
                TextVdfFileNode dataRoot = TextVdfFileNode.Load(reader, true);

                VdfFileNode appsNode = dataRoot.GetNodeAt(new string[] { "shortcutnames" }, false);

                foreach (KeyValuePair <string, VdfFileNode> shortcutPair in appsNode.NodeArray)
                {
                    string strId = shortcutPair.Key;

                    ulong ulongId;
                    if (ulong.TryParse(strId, out ulongId))
                    {
                        int    gameId   = (int)(ulongId >> 32);
                        string gameName = (string)shortcutPair.Value.NodeData;
                        shortcutGames.Add(gameName, gameId);
                    }
                    else
                    {
                        Program.Logger.Write(LoggerLevel.Warning, GlobalStrings.GameData_ErrorParsingScreenshots, (string)shortcutPair.Value.NodeData);
                    }
                }
                result = true;
            }
            catch (FileNotFoundException e)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_ErrorOpeningConfigFileParam, e.ToString());
            }
            catch (IOException e)
            {
                Program.Logger.Write(LoggerLevel.Error, GlobalStrings.GameData_LoadingErrorSteamConfig, e.ToString());
            }

            if (reader != null)
            {
                reader.Close();
            }

            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// Writes category information out Steam user config file for Steam games and external games.
        /// </summary>
        /// <param name="SteamId">Identifier of Steam user</param>
        /// <param name="discardMissing">Delete category information for games not present in game list</param>
        public void SaveSteamFile(long SteamId, bool discardMissing)
        {
            string filePath = string.Format(Properties.Resources.ConfigFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));

            SaveSteamFile(filePath, discardMissing);
            SaveShortcutGames(SteamId, discardMissing);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        /// <summary>
        /// Loads category info from the steam config file for the given Steam user.
        /// </summary>
        /// <param name="SteamId">Identifier of Steam user</param>
        /// <returns>The number of game entries found</returns>
        public int ImportSteamFile(long SteamId, SortedSet <int> ignore, bool ignoreDlc, bool ignoreExternal)
        {
            string filePath = string.Format(Properties.Resources.ConfigFilePath, Settings.Instance().SteamPath, Profile.ID64toDirName(SteamId));
            int    result   = ImportSteamFile(filePath, ignore, ignoreDlc);

            if (!ignoreExternal)
            {
                result += ImportNonSteamGames(SteamId, ignore);
            }
            return(result);
        }
Esempio n. 15
0
        void SaveModifiables( Profile p ) {
            p.SteamID64 = Int64.Parse( txtUserID.Text );

            p.AutoUpdate = chkAutoUpdate.Checked;
            p.AutoImport = chkAutoImport.Checked;
            p.LocalUpdate = chkLocalUpdate.Checked;
            p.WebUpdate = chkLocalUpdate.Checked;
            p.ExportDiscard = chkExportDiscard.Checked;
            p.IncludeShortcuts = chkIncludeShortcuts.Checked;
            p.OverwriteOnDownload = chkOverwriteNames.Checked;

            p.AutoIgnore = chkAutoIgnore.Checked;
            p.IncludeUnknown = chkIncludeUnknown.Checked;
            p.BypassIgnoreOnImport = chkBypassIgnoreOnImport.Checked;

            SortedSet<int> ignoreSet = new SortedSet<int>();
            foreach( ListViewItem item in lstIgnored.Items ) {
                int id;
                if( int.TryParse( item.Text, out id ) ) {
                    ignoreSet.Add( id );
                }
            }
            p.IgnoreList = ignoreSet;

        }
Esempio n. 16
0
        public static Profile Load(string path)
        {
            Logger.Info(GlobalStrings.Profile_LoadingProfile, path);
            Profile profile = new Profile
            {
                FilePath = path
            };

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(path);
            }
            catch (Exception e)
            {
                Logger.Warn(GlobalStrings.Profile_FailedToLoadProfile, e.Message);
                throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e);
            }

            XmlNode profileNode = doc.SelectSingleNode("/" + XmlNameProfile);

            if (profileNode != null)
            {
                // Get the 64-bit Steam ID
                long accId = XmlUtil.GetInt64FromNode(profileNode[XmlNameSteamId], 0);
                if (accId == 0)
                {
                    string oldAcc = XmlUtil.GetStringFromNode(profileNode[XmlNameOldSteamIdShort], null);
                    if (oldAcc != null)
                    {
                        accId = ToSteamId64(oldAcc);
                    }
                }

                profile.SteamID64 = accId;

                // Get other attributes
                profile.AutoUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoUpdate], profile.AutoUpdate);

                profile.AutoImport = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoImport], profile.AutoImport);
                profile.AutoExport = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoExport], profile.AutoExport);

                profile.LocalUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlNameLocalUpdate], profile.LocalUpdate);
                profile.WebUpdate   = XmlUtil.GetBoolFromNode(profileNode[XmlNameWebUpdate], profile.WebUpdate);

                profile.IncludeUnknown       = XmlUtil.GetBoolFromNode(profileNode[XmlNameIncludeUnknown], profile.IncludeUnknown);
                profile.BypassIgnoreOnImport = XmlUtil.GetBoolFromNode(profileNode[XmlNameBypassIgnoreOnImport], profile.BypassIgnoreOnImport);

                profile.ExportDiscard       = XmlUtil.GetBoolFromNode(profileNode[XmlNameExportDiscard], profile.ExportDiscard);
                profile.AutoIgnore          = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoIgnore], profile.AutoIgnore);
                profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode(profileNode[XmlNameOverwriteNames], profile.OverwriteOnDownload);

                profile.IncludeShortcuts = XmlUtil.GetBoolFromNode(profileNode[XmlNameIncludeShortcuts], profile.IncludeShortcuts);

                XmlNode     exclusionListNode = profileNode.SelectSingleNode(XmlNameExclusionList);
                XmlNodeList exclusionNodes    = exclusionListNode?.SelectNodes(XmlNameExclusion);
                if (exclusionNodes != null)
                {
                    foreach (XmlNode node in exclusionNodes)
                    {
                        if (XmlUtil.TryGetIntFromNode(node, out int id))
                        {
                            profile.IgnoreList.Add(id);
                        }
                    }
                }

                XmlNode     gameListNode = profileNode.SelectSingleNode(XmlNameGameList);
                XmlNodeList gameNodes    = gameListNode?.SelectNodes(XmlNameGame);
                if (gameNodes != null)
                {
                    foreach (XmlNode node in gameNodes)
                    {
                        AddGameFromNode(node, profile);
                    }
                }

                XmlNode     filterListNode = profileNode.SelectSingleNode(XmlNameFilterList);
                XmlNodeList filterNodes    = filterListNode?.SelectNodes(XmlNameFilter);
                if (filterNodes != null)
                {
                    foreach (XmlNode node in filterNodes)
                    {
                        AddFilterFromNode(node, profile);
                    }
                }

                XmlNode autocatListNode = profileNode.SelectSingleNode(XmlNameAutoCatList);
                if (autocatListNode != null)
                {
                    XmlNodeList autoCatNodes = autocatListNode.ChildNodes;
                    foreach (XmlNode node in autoCatNodes)
                    {
                        XmlElement autocatElement = node as XmlElement;
                        if (node == null)
                        {
                            continue;
                        }

                        AutoCat autocat = AutoCat.LoadACFromXmlElement(autocatElement);
                        if (autocat != null)
                        {
                            profile.AutoCats.Add(autocat);
                        }
                    }
                }
                else
                {
                    GenerateDefaultAutoCatSet(profile.AutoCats);
                }

                //profile.AutoCats.Sort();
            }

            Logger.Info(GlobalStrings.MainForm_ProfileLoaded);
            return(profile);
        }
Esempio n. 17
0
        /// <summary>
        /// Unloads the current profile or game list, making sure the user gets the option to save any changes.
        /// </summary>
        /// <param name="updateUI">If true, will redraw the UI. Otherwise, will leave it up to the caller to do so.</param>
        /// <returns>True if there is now no loaded profile, false otherwise.</returns>
        void Unload( bool updateUI = true )
        {
            if( !CheckForUnsaved() ) {
                return;
            }

            AddStatus(GlobalStrings.MainForm_ClearedData);
            currentProfile = null;
            gameData = new GameData();
            MakeChange( false );
            UpdateEnableStatesForProfileChange();
            if( updateUI ) {
                FillCategoryList();
                FillGameList();
            }
        }
Esempio n. 18
0
        private static void AddFilterFromNode(XmlNode node, Profile profile)
        {
            if (!XmlUtil.TryGetStringFromNode(node[XmlNameFilterName], out string name))
            {
                return;
            }

            Filter filter = profile.GameData.AddFilter(name);

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterSoftware], out int game))
            {
                filter.Game = game;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterSoftware], out int software))
            {
                filter.Software = software;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterUncategorized], out int uncategorized))
            {
                filter.Uncategorized = uncategorized;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterHidden], out int hidden))
            {
                filter.Hidden = hidden;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterVR], out int vr))
            {
                filter.VR = vr;
            }

            XmlNodeList filterNodes = node.SelectNodes(XmlNameFilterAllow);

            if (filterNodes != null)
            {
                foreach (XmlNode fNode in filterNodes)
                {
                    if (XmlUtil.TryGetStringFromNode(fNode, out string catName))
                    {
                        filter.Allow.Add(profile.GameData.GetCategory(catName));
                    }
                }
            }

            filterNodes = node.SelectNodes(XmlNameFilterRequire);
            if (filterNodes != null)
            {
                foreach (XmlNode fNode in filterNodes)
                {
                    if (XmlUtil.TryGetStringFromNode(fNode, out string catName))
                    {
                        filter.Require.Add(profile.GameData.GetCategory(catName));
                    }
                }
            }

            filterNodes = node.SelectNodes(XmlNameFilterExclude);
            if (filterNodes != null)
            {
                foreach (XmlNode fNode in filterNodes)
                {
                    if (XmlUtil.TryGetStringFromNode(fNode, out string catName))
                    {
                        filter.Exclude.Add(profile.GameData.GetCategory(catName));
                    }
                }
            }
        }
Esempio n. 19
0
 public DlgProfile(Profile profile)
     : this()
 {
     Profile  = profile;
     editMode = true;
 }
 private bool AutocatGames( Profile p, List<string> autocatStrings, bool doAll ) {
     WriteLine( "Starting autocategorization..." );
     bool success = false;
     try {
         List<AutoCat> acList = new List<AutoCat>();
         if( doAll ) {
             foreach( AutoCat a in p.AutoCats ) {
                 acList.Add( a );
             }
         } else {
             foreach( string s in autocatStrings ) {
                 foreach( AutoCat a in p.AutoCats ) {
                     if( a.Name == s && !acList.Contains( a ) ) {
                         acList.Add( a );
                     }
                 }
             }
         }
         RunAutoCats(p, acList);
         success = true;
     } catch( Exception e ) {
         WriteLine( "Error autocategorizing games: " + e.Message );
         Program.Logger.WriteException( "Automatic mode: Error autocategorizing games.", e );
     }
     if( success ) WriteLine( "Autocategorization complete." );
     return success;
 }
Esempio n. 21
0
        /// <summary>
        /// Loads the given profile file.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="checkForChanges"></param>
        void LoadProfile( string path, bool checkForChanges = true ) {
            if( checkForChanges && !CheckForUnsaved() ) return;

            try {
                currentProfile = Profile.Load( path );
                AddStatus( GlobalStrings.MainForm_ProfileLoaded );
            } catch( ApplicationException e ) {
                MessageBox.Show( string.Format( GlobalStrings.MainForm_Msg_ErrorLoadingProfile, e.Message ), GlobalStrings.Gen_Error, MessageBoxButtons.OK, MessageBoxIcon.Warning );
                Program.Logger.WriteException( GlobalStrings.MainForm_Log_ExceptionLoadingProfile, e );
                OnProfileChange();
                AddStatus( GlobalStrings.MainForm_FailedLoadProfile );
                return;
            }

            if( currentProfile.AutoUpdate ) {
                UpdateLibrary();
            }
            if( currentProfile.AutoImport ) {
                ImportConfig();
            }

            FullListRefresh();

            OnProfileChange();
        }
        private void RunAutoCats(Profile p, List<AutoCat> autocats)
        {
            foreach (AutoCat ac in autocats)
            {
                Write("Running autocat '" + ac.Name + "'...");
                ac.PreProcess(p.GameData, Program.GameDB);

                if (ac.AutoCatType == AutoCatType.Group)
                {
                    AutoCatGroup acg = (AutoCatGroup)ac;
                    RunAutoCats(p, p.CloneAutoCatList(acg.Autocats, p.GameData.GetFilter(acg.Filter)));
                }
                else
                {
                    foreach (GameInfo g in p.GameData.Games.Values)
                    {
                        if (g.Id > 0)
                        {
                            ac.CategorizeGame(g, p.GameData.GetFilter(ac.Filter));
                        }
                    }
                }
                ac.DeProcess();
                WriteLine(ac.Name + " complete.");
            }
        }
Esempio n. 23
0
        void SaveModifiables( Profile p )
        {
            p.SteamID64 = Int64.Parse( txtUserID.Text );

            p.AutoDownload = chkAutoDownload.Checked;
            p.AutoExport = chkAutoExport.Checked;
            p.AutoImport = chkAutoImport.Checked;
            p.ExportDiscard = chkExportDiscard.Checked;
            p.OverwriteOnDownload = chkOverwriteNames.Checked;

            p.AutoIgnore = chkAutoIgnore.Checked;
            p.IgnoreDlc = chkIgnoreDlc.Checked;

            // jpodadera. Ignored non-Steam games
            p.IgnoreExternal = chkIgnoreExternal.Checked;

            SortedSet<int> ignoreSet = new SortedSet<int>();
            foreach( ListViewItem item in lstIgnored.Items ) {
                int id;
                if( int.TryParse( item.Text, out id ) ) {
                    ignoreSet.Add( id );
                }
            }
            p.IgnoreList = ignoreSet;
        }
Esempio n. 24
0
 private bool UpdateGameList( Profile profile, bool doUpdate ) {
     if( !doUpdate ) {
         WriteLine( "Skipping updating game list." );
         return false;
     }
     Write( "Updating game list..." );
     bool success = false;
     if( profile.LocalUpdate ) {
         int newApps = 0;
         try {
             Write( "Trying local update..." );
             profile.GameData.UpdateGameListFromOwnedPackageInfo( profile.SteamID64, profile.IgnoreList, profile.IncludeUnknown ? AppTypes.InclusionUnknown : AppTypes.InclusionNormal, out newApps );
             success = true;
         } catch( Exception e ) {
             Write( "Local update failed. " );
             Program.Logger.WriteException( "Automatic mode: Error on local profile update.", e );
         }
     }
     if( !success && profile.WebUpdate ) {
         Write( "Trying web update..." );
         switch( Settings.Instance.ListSource ) {
             case GameListSource.XmlPreferred:
                 success = UpdateGameList_Web_Xml( profile );
                 if( !success ) {
                     success = UpdateGameList_Web_Html( profile );
                 }
                 break;
             case GameListSource.XmlOnly:
                 success = UpdateGameList_Web_Xml( profile );
                 break;
             case GameListSource.WebsiteOnly:
                 success = UpdateGameList_Web_Html( profile );
                 break;
         }
     }
     if( success ) {
         WriteLine( "Game list updated." );
     } else {
         WriteLine( "Update failed." );
     }
     return success;
 }
Esempio n. 25
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 ) );
                            }
                        }
                    }
                }
            }
        }
Esempio n. 26
0
 private bool UpdateGameList_Web_Html( Profile profile ) {
     try {
         string doc = GameList.FetchHtmlGameList( profile.SteamID64 );
         int newApps;
         profile.GameData.IntegrateHtmlGameList( doc, false, profile.IgnoreList, profile.IncludeUnknown ? AppTypes.InclusionUnknown : AppTypes.InclusionNormal, out newApps );
         return true;
     } catch( Exception e ) {
         Program.Logger.WriteException( "Automatic mode: Error on HTML web profile update.", e );
         return false;
     }
 }
Esempio n. 27
0
        public static Profile Load( string path ) {
            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.Profile_LoadingProfile, path);
            Profile profile = new Profile();

            profile.FilePath = path;

            XmlDocument doc = new XmlDocument();

            try {
                doc.Load( path );
            } catch( Exception e ) {
                Program.Logger.Write(LoggerLevel.Warning, GlobalStrings.Profile_FailedToLoadProfile, e.Message);
                throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e);
            }

            XmlNode profileNode = doc.SelectSingleNode( "/profile" );

            if( profileNode != null ) {

                Int64 accId = XmlUtil.GetInt64FromNode( profileNode["steam_id_64"], 0 );
                if( accId == 0 ) {
                    string oldAcc = XmlUtil.GetStringFromNode( profileNode["account_id"], null );
                    if( oldAcc != null ) {
                        accId = DirNametoID64( oldAcc );
                    }
                }

                profile.SteamID64 = accId;

                profile.AutoDownload = XmlUtil.GetBoolFromNode( profileNode["auto_download"], profile.AutoDownload );
                profile.AutoImport = XmlUtil.GetBoolFromNode( profileNode["auto_import"], profile.AutoImport );
                profile.AutoExport = XmlUtil.GetBoolFromNode( profileNode["auto_export"], profile.AutoExport );
                profile.ExportDiscard = XmlUtil.GetBoolFromNode( profileNode["export_discard"], profile.ExportDiscard );
                profile.AutoIgnore = XmlUtil.GetBoolFromNode( profileNode["auto_ignore"], profile.AutoIgnore );
                profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode( profileNode["overwrite_names"], profile.OverwriteOnDownload );
                profile.IgnoreDlc = XmlUtil.GetBoolFromNode( profileNode["ignore_dlc"], profile.IgnoreDlc );

                // jpodadera. Ignored non-Steam games
                profile.IgnoreExternal = XmlUtil.GetBoolFromNode(profileNode["ignore_external"], profile.IgnoreExternal);

                XmlNode exclusionListNode = profileNode.SelectSingleNode( "exclusions" );
                if( exclusionListNode != null ) {
                    XmlNodeList exclusionNodes = exclusionListNode.SelectNodes( "exclusion" );
                    foreach( XmlNode node in exclusionNodes ) {
                        int id;
                        if( XmlUtil.TryGetIntFromNode( node, out id ) ) {
                            profile.IgnoreList.Add( id );
                        }
                    }
                }

                XmlNode gameListNode = profileNode.SelectSingleNode( "games" );
                if( gameListNode != null ) {
                    XmlNodeList gameNodes = gameListNode.SelectNodes( "game" );
                    foreach( XmlNode node in gameNodes ) {
                        AddGameFromXmlNode( node, profile );
                    }
                }
            }
            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.MainForm_ProfileLoaded);
            return profile;
        }
Esempio n. 28
0
 private bool ImportSteamCategories( Profile p, bool doImport ) {
     if( !doImport ) {
         WriteLine( "Skipping Steam category import." );
         return true;
     }
     Write( "Importing Steam category data..." );
     bool success = false;
     try {
         p.ImportSteamData();
         success = true;
     } catch( Exception e ) {
         WriteLine( "Import failed: " + e.Message );
         Program.Logger.WriteException( "Automatic mode: Error on steam import.", e );
     }
     if( success ) WriteLine( "Import complete." );
     return success;
 }
Esempio n. 29
0
        public static Profile Load( string path )
        {
            Program.Logger.Write( LoggerLevel.Info, GlobalStrings.Profile_LoadingProfile, path );
            Profile profile = new Profile();

            profile.FilePath = path;

            XmlDocument doc = new XmlDocument();

            try {
                doc.Load( path );
            } catch( Exception e ) {
                Program.Logger.Write( LoggerLevel.Warning, GlobalStrings.Profile_FailedToLoadProfile, e.Message );
                throw new ApplicationException( GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e );
            }

            XmlNode profileNode = doc.SelectSingleNode( "/profile" );

            if( profileNode != null ) {

                XmlAttribute versionAttr = profileNode.Attributes["version"];
                int profileVersion = 0;
                if( versionAttr != null ) {
                    if( !int.TryParse( versionAttr.Value, out profileVersion ) ) {
                        profileVersion = 0;
                    }
                }

                Int64 accId = XmlUtil.GetInt64FromNode( profileNode["steam_id_64"], 0 );
                if( accId == 0 ) {
                    string oldAcc = XmlUtil.GetStringFromNode( profileNode["account_id"], null );
                    if( oldAcc != null ) {
                        accId = DirNametoID64( oldAcc );
                    }
                }

                profile.SteamID64 = accId;

                profile.AutoDownload = XmlUtil.GetBoolFromNode( profileNode["auto_download"], profile.AutoDownload );
                profile.AutoImport = XmlUtil.GetBoolFromNode( profileNode["auto_import"], profile.AutoImport );
                profile.AutoExport = XmlUtil.GetBoolFromNode( profileNode["auto_export"], profile.AutoExport );
                profile.ExportDiscard = XmlUtil.GetBoolFromNode( profileNode["export_discard"], profile.ExportDiscard );
                profile.AutoIgnore = XmlUtil.GetBoolFromNode( profileNode["auto_ignore"], profile.AutoIgnore );
                profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode( profileNode["overwrite_names"], profile.OverwriteOnDownload );
                profile.IgnoreDlc = XmlUtil.GetBoolFromNode( profileNode["ignore_dlc"], profile.IgnoreDlc );
                profile.IgnoreExternal = XmlUtil.GetBoolFromNode( profileNode["ignore_external"], profile.IgnoreExternal );

                XmlNode exclusionListNode = profileNode.SelectSingleNode( "exclusions" );
                if( exclusionListNode != null ) {
                    XmlNodeList exclusionNodes = exclusionListNode.SelectNodes( "exclusion" );
                    foreach( XmlNode node in exclusionNodes ) {
                        int id;
                        if( XmlUtil.TryGetIntFromNode( node, out id ) ) {
                            profile.IgnoreList.Add( id );
                        }
                    }
                }

                XmlNode gameListNode = profileNode.SelectSingleNode( "games" );
                if( gameListNode != null ) {
                    XmlNodeList gameNodes = gameListNode.SelectNodes( "game" );
                    foreach( XmlNode node in gameNodes ) {
                        AddGameFromXmlNode( node, profile, profileVersion );
                    }
                }

                XmlNode autocatListNode = profileNode.SelectSingleNode( "autocats" );
                if( autocatListNode != null ) {
                    XmlNodeList autoCatNodes = autocatListNode.ChildNodes;
                    foreach( XmlNode node in autoCatNodes ) {
                        XmlElement autocatElement = node as XmlElement;
                        if( node != null ) {
                            AutoCat autocat = AutoCat.LoadACFromXmlElement( autocatElement );
                            profile.AutoCats.Add( autocat );
                        }
                    }
                } else {
                    GenerateDefaultAutoCatSet( profile.AutoCats );
                }
            }
            Program.Logger.Write( LoggerLevel.Info, GlobalStrings.MainForm_ProfileLoaded );
            return profile;
        }
Esempio n. 30
0
        private bool ScrapeUnscrapedGames( Profile p, bool doScrape ) {
            if( !doScrape ) {
                WriteLine( "Skipping game scraping." );
                return true;
            }
            bool success = false;
            Write( "Scraping unscraped games..." );
            try {
                Queue<int> jobs = new Queue<int>();
                foreach( int id in p.GameData.Games.Keys ) {
                    if( id > 0 && !Program.GameDB.Contains( id ) || Program.GameDB.Games[id].LastStoreScrape == 0 ) {
                        jobs.Enqueue( id );
                    }
                }

                if( jobs.Count > 0 ) {

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

                    if( scrapeRes == System.Windows.Forms.DialogResult.Cancel ) {
                        WriteLine( "Scraping cancelled." );
                    } else {
                        WriteLine( "Scraping complete." );
                        if( scrapeDlg.JobsCompleted > 0 ) dbModified = true;
                    }
                } else {
                    WriteLine( "No unscraped games found." );
                }
                success = true;
            } catch( Exception e ) {
                WriteLine( "Error updating database from web: " + e.Message );
                Program.Logger.WriteException( "Automatic mode: Error updating db from web.", e );
            }
            return success;
        }
Esempio n. 31
0
        private bool CreateProfile() {
            if( !ValidateEntries() ) {
                return false;
            }

            FileInfo file;
            try {
                file = new FileInfo( txtFilePath.Text );
            } catch {
                MessageBox.Show( GlobalStrings.DlgProfile_YouMustEnterValidProfilePath, GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error );
                return false;
            }

            if( !file.Directory.Exists ) {
                try {
                    file.Directory.Create();
                } catch {
                    MessageBox.Show( GlobalStrings.DlgProfile_FailedToCreateParentDirectory, GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error );
                    return false;
                }
            }

            Profile profile = new Profile();

            SaveModifiables( profile );
            Profile.GenerateDefaultAutoCatSet( profile.AutoCats );

            try {
                profile.Save( file.FullName );
            } catch( ApplicationException e ) {
                MessageBox.Show( e.Message, GlobalStrings.DBEditDlg_Error, MessageBoxButtons.OK, MessageBoxIcon.Error );
                return false;
            }

            this.Profile = profile;
            return true;
        }
Esempio n. 32
0
        private bool AutocatGames( Profile p, List<string> autocatStrings, bool doAll ) {
            WriteLine( "Starting autocategorization..." );
            bool success = false;
            try {
                List<AutoCat> acList = new List<AutoCat>();
                if( doAll ) {
                    foreach( AutoCat a in p.AutoCats ) {
                        acList.Add( a );
                    }
                } else {
                    foreach( string s in autocatStrings ) {
                        foreach( AutoCat a in p.AutoCats ) {
                            if( a.Name == s && !acList.Contains( a ) ) {
                                acList.Add( a );
                            }
                        }
                    }
                }

                foreach( AutoCat ac in acList ) {
                    Write( "Running autocat '" + ac.Name + "'..." );
                    ac.PreProcess( p.GameData, Program.GameDB );


                    foreach( GameInfo g in p.GameData.Games.Values ) {
                        if( g.Id > 0 ) {
                            ac.CategorizeGame( g );
                        }
                    }

                    ac.DeProcess();
                    WriteLine( "Complete." );
                }
                success = true;
            } catch( Exception e ) {
                WriteLine( "Error autocategorizing games: " + e.Message );
                Program.Logger.WriteException( "Automatic mode: Error autocategorizing games.", e );
            }
            if( success ) WriteLine( "Autocategorization complete." );
            return success;
        }
Esempio n. 33
0
 public DlgProfile( Profile profile )
     : this() {
     Profile = profile;
     editMode = true;
 }
Esempio n. 34
0
 private bool SaveProfile( Profile p, bool doSave ) {
     if( !doSave ) {
         WriteLine( "Skipping profile save." );
         return true;
     }
     Write( "Saving profile..." );
     bool success = false;
     try {
         p.Save();
         success = true;
     } catch( Exception e ) {
         WriteLine( "Error saving profile: " + e.Message );
         Program.Logger.WriteException( "Automatic mode: Error saving profile.", e );
     }
     if( success ) WriteLine( "Saved." );
     return success;
 }
Esempio n. 35
0
        /// <summary>
        /// Loads the given profile file.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="checkForChanges"></param>
        void LoadProfile( string path, bool checkForChanges = true )
        {
            if( checkForChanges && !CheckForUnsaved() ) return;

            try {
                currentProfile = Profile.Load( path );
                AddStatus( GlobalStrings.MainForm_ProfileLoaded );
            } catch( ApplicationException e ) {
                MessageBox.Show( e.Message, GlobalStrings.MainForm_ErrorLoadingProfile, MessageBoxButtons.OK, MessageBoxIcon.Warning );
                AddStatus( GlobalStrings.MainForm_FailedLoadProfile );
                return;
            }

            gameData = currentProfile.GameData;

            if( currentProfile.AutoDownload ) {
                UpdateProfileDownload();
            }
            if( currentProfile.AutoImport ) {
                UpdateProfileImport();
            }

            FullListRefresh();

            OnProfileChange();
        }
Esempio n. 36
0
 private bool ExportToSteam( Profile p, bool doExport ) {
     if( !doExport ) {
         WriteLine( "Skipping Steam export." );
         return true;
     }
     Write( "Exporting to Steam..." );
     bool success = false;
     try {
         p.GameData.ExportSteamConfig( p.SteamID64, p.ExportDiscard, false );
         success = true;
     } catch( Exception e ) {
         WriteLine( "Error exporting Steam config: " + e.Message );
         Program.Logger.WriteException( "Automatic mode: Error exporting config.", e );
     }
     if( success ) WriteLine( "Export complete." );
     return success;
 }
Esempio n. 37
0
        /// <summary>
        /// Prompts user to create a new profile.
        /// </summary>
        void CreateProfile()
        {
            DlgProfile dlg = new DlgProfile();
            DialogResult res = dlg.ShowDialog();
            if( res == System.Windows.Forms.DialogResult.OK ) {
                Cursor = Cursors.WaitCursor;
                currentProfile = dlg.Profile;
                gameData = currentProfile.GameData;
                AddStatus( GlobalStrings.MainForm_ProfileCreated );
                if( dlg.DownloadNow ) {
                    UpdateProfileDownload( false );
                }

                if( dlg.ImportNow ) {
                    UpdateProfileImport( false );
                }
                if( dlg.SetStartup ) {
                    settings.StartupAction = StartupAction.Load;
                    settings.ProfileToLoad = currentProfile.FilePath;
                    settings.Save();
                }

                FullListRefresh();

                Cursor = Cursors.Default;
            }
            OnProfileChange();
        }
Esempio n. 38
0
 private static void AddFilterFromXmlNode(XmlNode node, Profile profile)
 {
     string name;
     if (XmlUtil.TryGetStringFromNode(node[XmlName_FilterName], out name))
     {
         Filter f = profile.GameData.AddFilter(name);
         if (!XmlUtil.TryGetIntFromNode(node[XmlName_FilterUncategorized], out f.Uncategorized))
         {
             f.Uncategorized = -1;
         }
         if (!XmlUtil.TryGetIntFromNode(node[XmlName_FilterHidden], out f.Hidden))
         {
             f.Hidden = -1;
         }
         XmlNodeList filterNodes = node.SelectNodes(XmlName_FilterAllow);
         foreach (XmlNode fNode in filterNodes)
         {
             string catName;
             if (XmlUtil.TryGetStringFromNode(fNode, out catName))
             {
                 f.Allow.Add(profile.GameData.GetCategory(catName));
             }
         }
         filterNodes = node.SelectNodes(XmlName_FilterRequire);
         foreach (XmlNode fNode in filterNodes)
         {
             string catName;
             if (XmlUtil.TryGetStringFromNode(fNode, out catName))
             {
                 f.Require.Add(profile.GameData.GetCategory(catName));
             }
         }
         filterNodes = node.SelectNodes(XmlName_FilterExclude);
         foreach (XmlNode fNode in filterNodes)
         {
             string catName;
             if (XmlUtil.TryGetStringFromNode(fNode, out catName))
             {
                 f.Exclude.Add(profile.GameData.GetCategory(catName));
             }
         }
     }                    
 }