From 118b59fce3e214e2daf8703381ac02bc8bb6937b Mon Sep 17 00:00:00 2001 From: pvutov Date: Fri, 3 Feb 2017 20:38:08 +0100 Subject: [PATCH] bugfixes and polish for mod updating --- WargameModManager/Properties/AssemblyInfo.cs | 4 +- WargameModManager/src/Form1.cs | 43 ++++++++++++-------- WargameModManager/src/ModUpdater.cs | 6 +-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/WargameModManager/Properties/AssemblyInfo.cs b/WargameModManager/Properties/AssemblyInfo.cs index dad057b..b364b9f 100644 --- a/WargameModManager/Properties/AssemblyInfo.cs +++ b/WargameModManager/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.0")] -[assembly: AssemblyFileVersion("1.0.3.0")] +[assembly: AssemblyVersion("1.0.4.0")] +[assembly: AssemblyFileVersion("1.0.4.0")] diff --git a/WargameModManager/src/Form1.cs b/WargameModManager/src/Form1.cs index ca30882..b9f6ed7 100644 --- a/WargameModManager/src/Form1.cs +++ b/WargameModManager/src/Form1.cs @@ -51,12 +51,15 @@ private void launchButton_Click(object sender, EventArgs e) { private void updateButton_Click(object sender, EventArgs e) { // CHECK FOR MOD UPDATES + bool newest = true; ModUpdateInfo[] infos = directories.getModUpdateInfo(); foreach (ModUpdateInfo info in infos) { ModUpdater modUpdater = new ModUpdater(info); if (modUpdater.checkForUpdates()) { + newest = false; + // update ProgressBar progressBar = new ProgressBar(); progressBar.Name = "downloadProgressBar"; @@ -66,9 +69,6 @@ private void updateButton_Click(object sender, EventArgs e) { Panel container = new Panel(); container.Location = updateButton.Location; container.Controls.Add(progressBar); - - this.Controls.Remove(updateButton); - this.Controls.Add(container); string caption = "New version of " + info.getName() + " found!"; string message = "Changelog: \n" + modUpdater.getPatchNotes() + "\n\nApply update?'"; @@ -76,25 +76,31 @@ private void updateButton_Click(object sender, EventArgs e) { DialogResult decision = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (decision == DialogResult.Yes) { + this.Controls.Remove(updateButton); + this.Controls.Add(container); + modUpdater.applyUpdate((int val) => { progressBar.Value = val; }); + + // remove progress bar when it is done + var t = new Timer(); + t.Interval = 2000; + t.Tick += (s, _) => { + if (progressBar.Value == progressBar.Maximum) { + this.Controls.Remove(container); + this.Controls.Add(updateButton); + t.Stop(); + } + }; + t.Start(); } - // remove progress bar when it is done - var t = new Timer(); - t.Interval = 2000; - t.Tick += (s, _) => { - if (progressBar.Value == progressBar.Maximum) { - this.Controls.Remove(container); - this.Controls.Add(updateButton); - t.Stop(); - } - }; - t.Start(); } } + checkModManagerUpdates(newest); + } - // no mod updates were found, but mod manager can be updated + private void checkModManagerUpdates(bool newest) { ModManagerUpdater appUpdater = new ModManagerUpdater(); if (appUpdater.checkForUpdates()) { @@ -115,7 +121,7 @@ private void updateButton_Click(object sender, EventArgs e) { // remove progress bar when it is done var t = new Timer(); - t.Interval = 10000; + t.Interval = 2000; t.Tick += (s, _) => { if (progressBar.Value == progressBar.Maximum) { this.Controls.Remove(container); @@ -125,7 +131,7 @@ private void updateButton_Click(object sender, EventArgs e) { }; t.Start(); } - else { + else if (newest) { // remove button, show and disappear text Label updateMessageLabel = new Label(); updateMessageLabel.Name = "updateMessageLabel"; @@ -138,13 +144,14 @@ private void updateButton_Click(object sender, EventArgs e) { this.Controls.Add(updateMessageLabel); var t = new Timer(); - t.Interval = 4000; + t.Interval = 2000; t.Tick += (s, _) => { this.Controls.Remove(updateMessageLabel); t.Stop(); }; t.Start(); } + } } } diff --git a/WargameModManager/src/ModUpdater.cs b/WargameModManager/src/ModUpdater.cs index d893f08..a3612cc 100644 --- a/WargameModManager/src/ModUpdater.cs +++ b/WargameModManager/src/ModUpdater.cs @@ -25,7 +25,7 @@ public ModUpdater(ModUpdateInfo modInfo) { // specify API version to use for stability request.Accept = "application/vnd.github.v3.raw+json"; - request.UserAgent = "pvutov/WargameModManager"; + request.UserAgent = "pvutov/WargameModManagerMods"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) @@ -37,8 +37,8 @@ public ModUpdater(ModUpdateInfo modInfo) { patchNotes = getStringJsonField("body", responseJson); downloadUrl = getStringJsonField("browser_download_url", responseJson); - DirectoryInfo di = Directory.CreateDirectory(Path.GetTempPath() + "WargameModManager"); - downloadDir = Path.Combine(Path.GetTempPath(), "WargameModManager"); + DirectoryInfo di = Directory.CreateDirectory(Path.GetTempPath() + "WargameModManagerMods"); + downloadDir = Path.Combine(Path.GetTempPath(), "WargameModManagerMods"); zipPath = Path.Combine(downloadDir, "WargameModManagerUpdate.zip"); // make sure download dir is empty