From 39e77337785013fc3d10774e054637f3fe4f530d Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 8 Mar 2017 20:55:15 +0100 Subject: [PATCH] Little Update system and reworked versions --- Discord Media Loader/Helper/VersionHelper.cs | 21 ++++++++++++++- Discord Media Loader/MainForm.Designer.cs | 23 +++++----------- Discord Media Loader/MainForm.cs | 26 ++++++++++++++----- Discord Media Loader/Program.cs | 3 +-- .../Properties/AssemblyInfo.cs | 4 +-- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Discord Media Loader/Helper/VersionHelper.cs b/Discord Media Loader/Helper/VersionHelper.cs index 2edd7de..bbe1ab9 100644 --- a/Discord Media Loader/Helper/VersionHelper.cs +++ b/Discord Media Loader/Helper/VersionHelper.cs @@ -15,7 +15,7 @@ namespace Discord_Media_Loader.Helper { internal static Version CurrentVersion => Assembly.GetExecutingAssembly().GetName().Version; - internal static async Task GetLatestReleaseVersion(string owner, string repository) + internal static async Task GetLatestReleaseVersion() { var github = new GitHubClient(new ProductHeaderValue("DiscordMediaLoader")); var tag = @@ -23,5 +23,24 @@ namespace Discord_Media_Loader.Helper var version = new Version(tag); return version; } + + internal static async Task DownloadLatestReleaseVersion() + { + return await DownloadReleaseVersion(await GetLatestReleaseVersion()); + } + + internal static async Task DownloadReleaseVersion(Version version) + { + var github = new GitHubClient(new ProductHeaderValue("DiscordMediaLoader")); + var releaseVersion = (from release in (await github.Repository.Release.GetAll("Serraniel", "DiscordMediaLoader")) where release.TagName == $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}" select release).First(); + //where release.TagName == $"v{version.Major}.{version.Minor}.{version.Revision}.{version.Build}" + /*var r = releases.ElementAt(0); + if (r.TagName == $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}") + { + var releaseVersion = releases.First(); + return releaseVersion.Url; + }*/ + return releaseVersion.ZipballUrl; + } } } diff --git a/Discord Media Loader/MainForm.Designer.cs b/Discord Media Loader/MainForm.Designer.cs index d95e7f9..4c544dd 100644 --- a/Discord Media Loader/MainForm.Designer.cs +++ b/Discord Media Loader/MainForm.Designer.cs @@ -48,8 +48,7 @@ this.lbCopyright = new System.Windows.Forms.Label(); this.lbGithub = new System.Windows.Forms.LinkLabel(); this.lbAbout = new System.Windows.Forms.LinkLabel(); - this.lbVersion = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); + this.lbVersion = new System.Windows.Forms.LinkLabel(); ((System.ComponentModel.ISupportInitialize)(this.nupThreadCount)).BeginInit(); this.SuspendLayout(); // @@ -242,27 +241,18 @@ // this.lbVersion.Location = new System.Drawing.Point(328, 274); this.lbVersion.Name = "lbVersion"; - this.lbVersion.Size = new System.Drawing.Size(100, 13); - this.lbVersion.TabIndex = 25; + this.lbVersion.Size = new System.Drawing.Size(100, 15); + this.lbVersion.TabIndex = 26; + this.lbVersion.TabStop = true; this.lbVersion.Text = "version"; this.lbVersion.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(294, 256); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 26; - this.button1.Text = "button1"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.lbVersion.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lbVersion_LinkClicked); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(439, 296); - this.Controls.Add(this.button1); this.Controls.Add(this.lbVersion); this.Controls.Add(this.lbAbout); this.Controls.Add(this.lbGithub); @@ -317,7 +307,6 @@ private System.Windows.Forms.Label lbCopyright; private System.Windows.Forms.LinkLabel lbGithub; private System.Windows.Forms.LinkLabel lbAbout; - private System.Windows.Forms.Label lbVersion; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.LinkLabel lbVersion; } } \ No newline at end of file diff --git a/Discord Media Loader/MainForm.cs b/Discord Media Loader/MainForm.cs index 2f2bf0a..72b1dfe 100644 --- a/Discord Media Loader/MainForm.cs +++ b/Discord Media Loader/MainForm.cs @@ -87,9 +87,9 @@ namespace Discord_Media_Loader private async void MainForm_Shown(object sender, EventArgs e) { - lbVersion.Text = $"v{Assembly.GetExecutingAssembly().GetName().Version}"; - + lbVersion.Text = $"v{VersionHelper.CurrentVersion}"; SetEnabled(false); + await CheckForUpdates(); if (!await Login()) { @@ -120,7 +120,6 @@ namespace Discord_Media_Loader foreach (Control c in Controls) { SetControlPropertyThreadSafe(c, "Enabled", enabled); - //c.Enabled = enabled; } } @@ -260,7 +259,7 @@ namespace Discord_Media_Loader } msgScanCount++; - OnUpdateProgress(new UpdateProgessEventArgs() { Downloaded = downloadCount, Scanned = msgScanCount}); + OnUpdateProgress(new UpdateProgessEventArgs() { Downloaded = downloadCount, Scanned = msgScanCount }); } stop = stop || messages.Length < limit; @@ -289,9 +288,24 @@ namespace Discord_Media_Loader MessageBox.Show(Properties.Resources.AboutString); } - private async void button1_Click(object sender, EventArgs e) + private async Task CheckForUpdates(bool manually = false) { - await VersionHelper.GetLatestReleaseVersion("Serraniel", "DiscordMediaLoader"); + if (VersionHelper.CurrentVersion < await VersionHelper.GetLatestReleaseVersion()) + { + if (MessageBox.Show("A new version is available, do you want to update now?", "Update available", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + + Process.Start(await VersionHelper.DownloadLatestReleaseVersion()); + } + else if (manually) + { + MessageBox.Show("You already use the newest version."); + } + } + + private void lbVersion_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + CheckForUpdates(true); } } diff --git a/Discord Media Loader/Program.cs b/Discord Media Loader/Program.cs index d1db98e..bd15ed5 100644 --- a/Discord Media Loader/Program.cs +++ b/Discord Media Loader/Program.cs @@ -11,8 +11,7 @@ namespace Discord_Media_Loader /// [STAThread] static void Main() - { - var v = VersionHelper.GetLatestReleaseVersion("Serraniel", "DiscordMediaLoader"); + { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); diff --git a/Discord Media Loader/Properties/AssemblyInfo.cs b/Discord Media Loader/Properties/AssemblyInfo.cs index 72ed5ee..ff6dfd2 100644 --- a/Discord Media Loader/Properties/AssemblyInfo.cs +++ b/Discord Media Loader/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.1.78")] -[assembly: AssemblyFileVersion("0.1.1.78")] +[assembly: AssemblyVersion("0.1.98.0")] +[assembly: AssemblyFileVersion("0.1.98.0")]