diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 3693edf..7adb79d 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -31,6 +31,7 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.checkForAppUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.updateLogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.label1 = new System.Windows.Forms.Label(); @@ -56,23 +57,31 @@ private void InitializeComponent() // fileToolStripMenuItem // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.checkForAppUpdatesToolStripMenuItem, this.updateLogToolStripMenuItem, this.exitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 29); this.fileToolStripMenuItem.Text = "File"; // + // checkForAppUpdatesToolStripMenuItem + // + this.checkForAppUpdatesToolStripMenuItem.Name = "checkForAppUpdatesToolStripMenuItem"; + this.checkForAppUpdatesToolStripMenuItem.Size = new System.Drawing.Size(299, 34); + this.checkForAppUpdatesToolStripMenuItem.Text = "Check for App Updates"; + this.checkForAppUpdatesToolStripMenuItem.Click += new System.EventHandler(this.checkForAppUpdatesToolStripMenuItem_Click); + // // updateLogToolStripMenuItem // this.updateLogToolStripMenuItem.Name = "updateLogToolStripMenuItem"; - this.updateLogToolStripMenuItem.Size = new System.Drawing.Size(243, 34); + this.updateLogToolStripMenuItem.Size = new System.Drawing.Size(299, 34); this.updateLogToolStripMenuItem.Text = "Last Update Log"; this.updateLogToolStripMenuItem.Click += new System.EventHandler(this.updateLogToolStripMenuItem_Click); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(243, 34); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(299, 34); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -172,7 +181,7 @@ private void InitializeComponent() this.Name = "Form1"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Pocket Updater v1.2.1"; + this.Text = "Pocket Updater v1.3.0"; this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); @@ -192,5 +201,6 @@ private void InitializeComponent() private Label label2; private Button Button_Settings; private ToolStripMenuItem updateLogToolStripMenuItem; + private ToolStripMenuItem checkForAppUpdatesToolStripMenuItem; } } \ No newline at end of file diff --git a/Form1.cs b/Form1.cs index 676b7c1..017e219 100644 --- a/Form1.cs +++ b/Form1.cs @@ -1,12 +1,38 @@ +using pannella.analoguepocket; +using System.Diagnostics; +using System.Net; +using System.Net.Http.Headers; +using System.Security.Policy; +using System.Text.Json; using System.Windows.Forms; namespace Pocket_Updater { public partial class Form1 : Form { + private const string VERSION = "1.3.0"; + private const string API_URL = "https://api.github.com/repos/RetroDriven/Pocket_Updater/releases"; + private const string RELEASE_URL = "https://github.com/RetroDriven/Pocket_Updater/releases/latest"; + public Form1() { InitializeComponent(); + + //Check for Internet Connection and App Updates + try + { + using (WebClient client2 = new WebClient()) + { + using (client2.OpenRead("http://www.google.com/")) + { + _ = CheckVersion_Load(); + } + } + } + catch + { + MessageBox.Show("Failed to check for App Updates!", "No Internet Connection Detected", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { @@ -48,5 +74,108 @@ private void updateLogToolStripMenuItem_Click(object sender, EventArgs e) MessageBox.Show("Pocket Update Log Not Found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + public async Task CheckVersion_Load() + { + + if (await CheckVersion()) + { + try + { + using (WebClient client = new WebClient()) + { + using (client.OpenRead("http://www.google.com/")) + { + DialogResult dialogResult = MessageBox.Show("There is a New Version Available!\n\n Would you like to Download it?", "App Update", MessageBoxButtons.YesNo,MessageBoxIcon.Information); + if (dialogResult == DialogResult.Yes) + { + Process.Start("explorer", RELEASE_URL); + Close(); + + } + else if (dialogResult == DialogResult.No) + { + //do something else + } + } + } + } + catch + { + MessageBox.Show("No Internet Connection Detected!","Error",MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + async static Task CheckVersion() + { + try + { + var client = new HttpClient(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + var request = new HttpRequestMessage + { + Method = HttpMethod.Get, + RequestUri = new Uri(API_URL) + + }; + var agent = new ProductInfoHeaderValue("Pocket-Updater", "1.0"); + request.Headers.UserAgent.Add(agent); + var response = await client.SendAsync(request).ConfigureAwait(false); + response.EnsureSuccessStatusCode(); + + var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + List? releases = JsonSerializer.Deserialize>(responseBody); + + string tag_name = releases[0].tag_name; + string? v = SemverUtil.FindSemver(tag_name); + if (v != null) + { + return SemverUtil.SemverCompare(v, VERSION); + + } + return false; + } + catch (HttpRequestException e) + { + return false; + + } + } + + private async void checkForAppUpdatesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + using (WebClient client2 = new WebClient()) + { + using (client2.OpenRead("http://www.google.com/")) + { + + if (await CheckVersion()) + { + DialogResult dialogResult = MessageBox.Show("There is a New Version Available!\n\n Would you like to Download it?", "App Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (dialogResult == DialogResult.Yes) + { + Process.Start("explorer", RELEASE_URL); + Close(); + + } + else if (dialogResult == DialogResult.No) + { + //do something else + } + } + else + { + MessageBox.Show("You are using the most recent App (v" + VERSION + ")", "No Updates Found", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + } + catch + { + MessageBox.Show("Failed to check for App Updates!", "No Internet Connection Detected", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } \ No newline at end of file diff --git a/Pocket_Updater.csproj b/Pocket_Updater.csproj index 34357a0..cd6234e 100644 --- a/Pocket_Updater.csproj +++ b/Pocket_Updater.csproj @@ -3,7 +3,7 @@ WinExe net6.0-windows - 1.2.1 + 1.3.0 Pocket_Updater enable true