From 14b4bfb2f4bb21e0d2778b0b29e809f0c33c9b7e Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Tue, 30 Aug 2016 21:12:47 -0700 Subject: [PATCH] Add update available indication version.txt as a program resource -> check against online copy, if online has an earlier date then indicate that an update is available. When posting a new update, the version.txt has to be updated with a new yyyyMMdd. Ask me on IRC why I prefer to do things this way ;) --- PKHeX/MainWindow/Main.Designer.cs | 28 ++++++++++-------- PKHeX/MainWindow/Main.cs | 41 +++++++++++++++++++++++--- PKHeX/MainWindow/Main.resx | 6 ++-- PKHeX/PKHeX.csproj | 3 ++ PKHeX/Properties/Resources.Designer.cs | 9 ++++++ PKHeX/Properties/Resources.resx | 3 ++ PKHeX/Resources/text/version.txt | 1 + 7 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 PKHeX/Resources/text/version.txt diff --git a/PKHeX/MainWindow/Main.Designer.cs b/PKHeX/MainWindow/Main.Designer.cs index ed26d445d..b46c66d52 100644 --- a/PKHeX/MainWindow/Main.Designer.cs +++ b/PKHeX/MainWindow/Main.Designer.cs @@ -245,7 +245,6 @@ public void InitializeComponent() this.Menu_ModifyPKM = new System.Windows.Forms.ToolStripMenuItem(); this.Menu_Unicode = new System.Windows.Forms.ToolStripMenuItem(); this.Menu_About = new System.Windows.Forms.ToolStripMenuItem(); - this.L_Save = new System.Windows.Forms.Label(); this.tabBoxMulti = new System.Windows.Forms.TabControl(); this.Tab_Box = new System.Windows.Forms.TabPage(); this.PAN_Box = new System.Windows.Forms.Panel(); @@ -363,6 +362,7 @@ public void InitializeComponent() this.mnuLQR = new System.Windows.Forms.ToolStripMenuItem(); this.mnuLSave = new System.Windows.Forms.ToolStripMenuItem(); this.PB_Legal = new System.Windows.Forms.PictureBox(); + this.L_UpdateAvailable = new System.Windows.Forms.LinkLabel(); this.tabMain.SuspendLayout(); this.Tab_Main.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.Label_IsShiny)).BeginInit(); @@ -2985,16 +2985,6 @@ public void InitializeComponent() this.Menu_About.Text = "About &PKHeX"; this.Menu_About.Click += new System.EventHandler(this.mainMenuAbout); // - // L_Save - // - this.L_Save.AutoSize = true; - this.L_Save.Location = new System.Drawing.Point(300, 5); - this.L_Save.Name = "L_Save"; - this.L_Save.Size = new System.Drawing.Size(54, 13); - this.L_Save.TabIndex = 4; - this.L_Save.Text = "SAV: N/A"; - this.L_Save.Click += new System.EventHandler(this.clickSaveFileName); - // // tabBoxMulti // this.tabBoxMulti.Controls.Add(this.Tab_Box); @@ -4604,16 +4594,28 @@ public void InitializeComponent() this.PB_Legal.TabStop = false; this.PB_Legal.Click += new System.EventHandler(this.clickLegality); // + // L_UpdateAvailable + // + this.L_UpdateAvailable.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.L_UpdateAvailable.Location = new System.Drawing.Point(305, 5); + this.L_UpdateAvailable.Name = "L_UpdateAvailable"; + this.L_UpdateAvailable.Size = new System.Drawing.Size(300, 13); + this.L_UpdateAvailable.TabIndex = 102; + this.L_UpdateAvailable.TabStop = true; + this.L_UpdateAvailable.Text = "New Update Available!"; + this.L_UpdateAvailable.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.L_UpdateAvailable.Visible = false; + // // Main // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(614, 361); + this.Controls.Add(this.L_UpdateAvailable); this.Controls.Add(this.PB_Legal); this.Controls.Add(this.dragout); this.Controls.Add(this.tabBoxMulti); - this.Controls.Add(this.L_Save); this.Controls.Add(this.tabMain); this.Controls.Add(this.menuStrip1); this.Controls.Add(this.GB_SAVtools); @@ -4884,7 +4886,6 @@ public void InitializeComponent() private System.Windows.Forms.Label L_Characteristic; private System.Windows.Forms.TextBox TB_IVTotal; private System.Windows.Forms.Label L_Potential; - private System.Windows.Forms.Label L_Save; private System.Windows.Forms.TabControl tabBoxMulti; private System.Windows.Forms.TabPage Tab_Box; private System.Windows.Forms.TabPage Tab_PartyBattle; @@ -5085,6 +5086,7 @@ public void InitializeComponent() private System.Windows.Forms.FlowLayoutPanel FLP_PKMEditors; private System.Windows.Forms.Button B_LinkInfo; private System.Windows.Forms.Button B_CGearSkin; + private System.Windows.Forms.LinkLabel L_UpdateAvailable; } } diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index f91ed9125..817610a0c 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.Globalization; using System.IO; using System.Linq; using System.Media; @@ -19,6 +20,31 @@ public Main() new Thread(() => new SplashScreen().ShowDialog()).Start(); DragInfo.slotPkmSource = SAV.BlankPKM.EncryptedPartyData; InitializeComponent(); + + // Check for Updates + L_UpdateAvailable.Click += (sender, e) => { Process.Start(ThreadPath); }; + new Thread(() => + { + string data = Util.getStringFromURL(VersionPath); + if (data == null) + return; + try + { + DateTime upd = DateTime.ParseExact(data, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); + DateTime cur = DateTime.ParseExact(Properties.Resources.ProgramVersion, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); + + if (upd <= cur) + return; + + string message = $"New Update Available! {upd.ToString("d")}"; + if (InvokeRequired) + try { Invoke((MethodInvoker) delegate { L_UpdateAvailable.Visible = true; L_UpdateAvailable.Text = message; }); } + catch { L_UpdateAvailable.Visible = true; L_UpdateAvailable.Text = message; } + else { L_UpdateAvailable.Visible = true; L_UpdateAvailable.Text = message; } + } + catch { } + }).Start(); + CB_ExtraBytes.SelectedIndex = 0; SaveFile.SetUpdateDex = Menu_ModifyDex.Checked; SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked; @@ -184,6 +210,8 @@ public Main() public static string DatabasePath => Path.Combine(WorkingDirectory, "db"); private static string WC6DatabasePath => Path.Combine(WorkingDirectory, "wc6"); private static string BackupPath => Path.Combine(WorkingDirectory, "bak"); + private static string ThreadPath => @"https://projectpokemon.org/forums/showthread.php?36986"; + private static string VersionPath => @"https://raw.githubusercontent.com/kwsch/PKHeX/master/PKHeX/Resources/Text/version.txt"; #endregion @@ -756,7 +784,7 @@ private void loadSAV(SaveFile sav, string path) SAV.FileName = Path.GetExtension(path) == ".bak" ? Path.GetFileName(path).Split(new[] { " [" }, StringSplitOptions.None)[0] : Path.GetFileName(path); - L_Save.Text = $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}"; // more descriptive + Text = "PKHeX - " + $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}"; // more descriptive // If backup folder exists, save a backup. string backupName = Path.Combine(BackupPath, Util.CleanFileName(SAV.BAKName)); @@ -769,7 +797,7 @@ private void loadSAV(SaveFile sav, string path) { SAV.FilePath = null; SAV.FileName = "Blank Save File"; - L_Save.Text = $"SAV{SAV.Generation}: {SAV.FileName} [{SAV.OT} ({SAV.Version})]"; + Text = "PKHeX - " + $"SAV{SAV.Generation}: {SAV.FileName} [{SAV.OT} ({SAV.Version})]"; GB_SAVtools.Visible = false; } @@ -2622,7 +2650,7 @@ private void clickBoxLeft(object sender, EventArgs e) } private void clickBoxSort(object sender, EventArgs e) { - if (tabBoxMulti.SelectedIndex != 0) + if (tabBoxMulti.SelectedTab != Tab_Box) return; if (!SAV.HasBox) return; @@ -2665,7 +2693,12 @@ private void clickBoxSort(object sender, EventArgs e) } private void clickBoxDouble(object sender, MouseEventArgs e) { - if (tabBoxMulti.SelectedIndex != 0) + if (tabBoxMulti.SelectedTab == Tab_SAV) + { + clickSaveFileName(sender, e); + return; + } + if (tabBoxMulti.SelectedTab != Tab_Box) return; if (!SAV.HasBox) return; diff --git a/PKHeX/MainWindow/Main.resx b/PKHeX/MainWindow/Main.resx index 1d654adaa..df010947a 100644 --- a/PKHeX/MainWindow/Main.resx +++ b/PKHeX/MainWindow/Main.resx @@ -877,9 +877,6 @@ True - - True - True @@ -1332,6 +1329,9 @@ SiSLGvswRQAAAABJRU5ErkJggg== + + True + True diff --git a/PKHeX/PKHeX.csproj b/PKHeX/PKHeX.csproj index 8780ef3be..f4eab194c 100644 --- a/PKHeX/PKHeX.csproj +++ b/PKHeX/PKHeX.csproj @@ -2720,6 +2720,9 @@ + + +