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 ;)
This commit is contained in:
Kaphotics 2016-08-30 21:12:47 -07:00
parent b6b931220d
commit 14b4bfb2f4
7 changed files with 71 additions and 20 deletions

View file

@ -245,7 +245,6 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
}

View file

@ -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 @@ namespace PKHeX
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 @@ namespace PKHeX
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 @@ namespace PKHeX
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 @@ namespace PKHeX
{
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 @@ namespace PKHeX
}
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 @@ namespace PKHeX
}
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;

View file

@ -877,9 +877,6 @@
<metadata name="menuStrip1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="L_Save.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="tabBoxMulti.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -1332,6 +1329,9 @@
SiSLGvswRQAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="L_UpdateAvailable.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View file

@ -2720,6 +2720,9 @@
<ItemGroup>
<None Include="Resources\img\box\swapBox.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\text\version.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -15585,6 +15585,15 @@ namespace PKHeX.Properties {
}
}
/// <summary>
/// Looks up a localized string for the Program Version.
/// </summary>
internal static string ProgramVersion {
get {
return ResourceManager.GetString("ProgramVersion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -6391,4 +6391,7 @@
<data name="swapBox" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\img\box\swapBox.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ProgramVersion" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\text\version.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
</root>

View file

@ -0,0 +1 @@
20160830