From dac3bebc42b2e7551e7d383522180865c8d92833 Mon Sep 17 00:00:00 2001 From: EnemyWithin Date: Tue, 23 Feb 2016 17:11:17 -0500 Subject: [PATCH] Save LastPlayed information for non-steam games. Added Browser button for Game Executable. --- Depressurizer/DlgGame.Designer.cs | 10 ++++++ Depressurizer/DlgGame.cs | 22 ++++++++++++ Depressurizer/DlgGame.resx | 60 +++++++++++++++++++++++-------- Depressurizer/GameData.cs | 3 +- Depressurizer/MainForm.cs | 1 + Depressurizer/Profile.cs | 6 +++- 6 files changed, 85 insertions(+), 17 deletions(-) diff --git a/Depressurizer/DlgGame.Designer.cs b/Depressurizer/DlgGame.Designer.cs index 1078026..c02ded5 100644 --- a/Depressurizer/DlgGame.Designer.cs +++ b/Depressurizer/DlgGame.Designer.cs @@ -54,6 +54,7 @@ private void InitializeComponent() { this.chkHidden = new System.Windows.Forms.CheckBox(); this.txtExecutable = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); + this.btnBrowse = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtId @@ -124,6 +125,13 @@ private void InitializeComponent() { resources.ApplyResources(this.label1, "label1"); this.label1.Name = "label1"; // + // btnBrowse + // + resources.ApplyResources(this.btnBrowse, "btnBrowse"); + this.btnBrowse.Name = "btnBrowse"; + this.btnBrowse.UseVisualStyleBackColor = true; + this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click); + // // DlgGame // this.AcceptButton = this.cmdOk; @@ -131,6 +139,7 @@ private void InitializeComponent() { this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cmdCancel; this.ControlBox = false; + this.Controls.Add(this.btnBrowse); this.Controls.Add(this.txtExecutable); this.Controls.Add(this.label1); this.Controls.Add(this.chkHidden); @@ -166,5 +175,6 @@ private void InitializeComponent() { private System.Windows.Forms.CheckBox chkHidden; private System.Windows.Forms.TextBox txtExecutable; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnBrowse; } } \ No newline at end of file diff --git a/Depressurizer/DlgGame.cs b/Depressurizer/DlgGame.cs index 4033a17..adbfacd 100644 --- a/Depressurizer/DlgGame.cs +++ b/Depressurizer/DlgGame.cs @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with Depressurizer. If not, see . */ using System; +using System.IO; using System.Windows.Forms; namespace Depressurizer { @@ -84,5 +85,26 @@ private void cmdOk_Click( object sender, EventArgs e ) { DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } + + private void btnBrowse_Click(object sender, EventArgs e) + { + OpenFileDialog dlg = new OpenFileDialog(); + + try + { + FileInfo f = new FileInfo(txtExecutable.Text); + dlg.InitialDirectory = f.DirectoryName; + dlg.FileName = f.Name; + } + catch (ArgumentException) + { + } + + DialogResult res = dlg.ShowDialog(); + if (res == DialogResult.OK) + { + txtExecutable.Text = dlg.FileName; + } + } } } diff --git a/Depressurizer/DlgGame.resx b/Depressurizer/DlgGame.resx index e576de6..a777d82 100644 --- a/Depressurizer/DlgGame.resx +++ b/Depressurizer/DlgGame.resx @@ -138,7 +138,7 @@ $this - 11 + 12 True @@ -165,7 +165,7 @@ $this - 10 + 11 True @@ -192,7 +192,7 @@ $this - 9 + 10 @@ -217,7 +217,7 @@ $this - 8 + 9 True @@ -244,7 +244,7 @@ $this - 7 + 8 Top, Right @@ -274,13 +274,13 @@ $this - 6 + 7 Bottom, Right - 398, 120 + 285, 124 75, 23 @@ -301,13 +301,13 @@ $this - 5 + 6 Bottom, Right - 317, 120 + 148, 124 75, 23 @@ -328,7 +328,7 @@ $this - 4 + 5 70, 65 @@ -349,7 +349,7 @@ $this - 3 + 4 True @@ -376,13 +376,13 @@ $this - 2 + 3 70, 95 - 403, 20 + 321, 20 12 @@ -397,7 +397,7 @@ $this - 0 + 1 True @@ -427,7 +427,37 @@ $this - 1 + 2 + + + Bottom, Right + + + NoControl + + + 398, 94 + + + 75, 23 + + + 13 + + + Browse... + + + btnBrowse + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 True diff --git a/Depressurizer/GameData.cs b/Depressurizer/GameData.cs index 206e56d..51da3d1 100644 --- a/Depressurizer/GameData.cs +++ b/Depressurizer/GameData.cs @@ -1057,7 +1057,8 @@ private void GetLastPlayedFromVdf(VdfFileNode appsNode, SortedSet ignore, A if (gameNodePair.Value.ContainsKey("LastPlayed") && gameNodePair.Value["LastPlayed"].NodeInt != 0) { - game.LastPlayed = Utility.GetDTFromUTime(gameNodePair.Value["LastPlayed"].NodeInt); + 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()); } } diff --git a/Depressurizer/MainForm.cs b/Depressurizer/MainForm.cs index 9abbc00..da84b25 100644 --- a/Depressurizer/MainForm.cs +++ b/Depressurizer/MainForm.cs @@ -3560,6 +3560,7 @@ void LaunchGame( GameInfo g ) { // // Steam game // gameIdentifier = g.Id.ToString(); //} + g.LastPlayed = DateTime.Now; System.Diagnostics.Process.Start( g.Executable ); } } diff --git a/Depressurizer/Profile.cs b/Depressurizer/Profile.cs index e952e9b..b8a538d 100644 --- a/Depressurizer/Profile.cs +++ b/Depressurizer/Profile.cs @@ -59,7 +59,8 @@ private const string XmlName_Game_Hidden = "hidden", XmlName_Game_CategoryList = "categories", XmlName_Game_Category = "category", - XmlName_Game_Executable = "executable"; + XmlName_Game_Executable = "executable", + XmlName_Game_LastPlayed = "lastplayed"; // Old Xml names private const string XmlName_Old_SteamIDShort = "account_id", @@ -292,6 +293,7 @@ private static void AddGameFromXmlNode( XmlNode node, Profile profile, int profi game.Hidden = XmlUtil.GetBoolFromNode( node[XmlName_Game_Hidden], false ); game.Executable = XmlUtil.GetStringFromNode(node[XmlName_Game_Executable], null); + game.LastPlayed = Convert.ToDateTime(XmlUtil.GetStringFromNode(node[XmlName_Game_LastPlayed], null)); if ( profileVersion < 1 ) { string catName; @@ -374,6 +376,8 @@ public bool Save( string path ) { } writer.WriteElementString( XmlName_Game_Hidden, g.Hidden.ToString() ); + + if (g.LastPlayed != DateTime.MinValue) writer.WriteElementString(XmlName_Game_LastPlayed, g.LastPlayed.ToString()); if (!g.Executable.Contains("steam://")) writer.WriteElementString(XmlName_Game_Executable, g.Executable);