Skip to content

Commit

Permalink
bugfixes and polish for mod updating
Browse files Browse the repository at this point in the history
  • Loading branch information
pvutov committed Feb 3, 2017
1 parent 6891cd1 commit 118b59f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions WargameModManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
43 changes: 25 additions & 18 deletions WargameModManager/src/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -66,35 +69,38 @@ 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?'";

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()) {
Expand All @@ -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);
Expand All @@ -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";
Expand All @@ -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();
}

}
}
}
6 changes: 3 additions & 3 deletions WargameModManager/src/ModUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit 118b59f

Please sign in to comment.