-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dropbox/blake/versionCheck
Add version check during app initialization.
- Loading branch information
Showing
7 changed files
with
680 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using RestSharp; | ||
using Newtonsoft.Json; | ||
|
||
namespace DfBAdminToolkit.Services | ||
{ | ||
public class GitHubService | ||
{ | ||
|
||
private readonly RestClient _client; | ||
|
||
public GitHubService() | ||
{ | ||
|
||
_client = new RestClient(@"https://api.github.com/"); | ||
} | ||
|
||
public async Task<GitHubRelease> LatestRelease() | ||
{ | ||
GitHubRelease release = new GitHubRelease(); | ||
string releasesPath = @"repos/dropbox/DropboxBusinessAdminTool/releases"; | ||
RestRequest request = new RestRequest(releasesPath, Method.GET); | ||
IRestResponse response = await _client.ExecuteTaskAsync(request); | ||
if (response.StatusCode == System.Net.HttpStatusCode.OK) | ||
{ | ||
dynamic jsonData = JsonConvert.DeserializeObject<dynamic>(response.Content); | ||
release.version = new Version(jsonData[0]["tag_name"].ToString()); | ||
release.name = jsonData[0]["name"]; | ||
release.description = jsonData[0]["body"]; | ||
release.releaseUri = new Uri(jsonData[0]["html_url"].ToString()); | ||
release.releaseDate = Convert.ToDateTime(jsonData[0]["published_at"].ToString()); | ||
// Look for a zip attachment that contains just the pre-built exe. | ||
foreach (var asset in jsonData[0]["assets"]) | ||
{ | ||
if (asset["content_type"] == "application/x-zip-compressed") | ||
{ | ||
release.downloadUri = asset["browser_download_url"]; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
release.version = new Version(0, 0, 0, 0); | ||
} | ||
return release; | ||
} | ||
} | ||
|
||
public class GitHubRelease | ||
{ | ||
public string name; | ||
public string description; | ||
public Version version; | ||
public DateTime releaseDate; | ||
public Uri releaseUri; | ||
public Uri downloadUri; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using DfBAdminToolkit.Services; | ||
|
||
namespace DfBAdminToolkit.View | ||
{ | ||
public partial class VersionWindow : Form | ||
{ | ||
private GitHubRelease _release; | ||
|
||
public VersionWindow(GitHubRelease release) | ||
{ | ||
_release = release; | ||
InitializeComponent(); | ||
versionAlertText.Text = String.Format(@"Version {0} of the Admin Toolkit is now available!", _release.version.ToString()); | ||
versionDetails.Text = String.Format(@"Release Notes:{0}{1}", Environment.NewLine, _release.description); | ||
if (_release.downloadUri != null) | ||
{ | ||
downloadButton.Text = @"Download Release"; | ||
} | ||
else | ||
{ | ||
downloadButton.Text = @"View Details"; | ||
} | ||
downloadButton.Focus(); | ||
} | ||
|
||
private void downloadButton_Clicked(object sender, EventArgs e) | ||
{ | ||
if (_release.downloadUri != null) | ||
{ | ||
System.Diagnostics.Process.Start(_release.downloadUri.ToString()); | ||
Application.Exit(); | ||
} | ||
else | ||
{ | ||
System.Diagnostics.Process.Start(_release.releaseUri.ToString()); | ||
} | ||
this.Close(); | ||
} | ||
|
||
private void dismissButton_Click(object sender, EventArgs e) | ||
{ | ||
this.Close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.