-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added version checking and an update button, this will serve as a tes…
…t release
- Loading branch information
1 parent
0a60b72
commit 5508f33
Showing
7 changed files
with
91 additions
and
1 deletion.
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
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,48 @@ | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
|
||
namespace PostScriptumMortarCalculator.Services | ||
{ | ||
public class UpdateService | ||
{ | ||
private const string c_OWNER_NAME = "sirdoombox"; | ||
private const string c_REPO_NAME = "PostScriptumMortarCalculator"; | ||
private const string c_RELEASE_PATH = "https://github.com/sirdoombox/PostScriptumMortarCalculator/releases/latest"; | ||
|
||
private readonly GitHubClient m_client; | ||
|
||
public UpdateService() | ||
{ | ||
m_client = new GitHubClient(new ProductHeaderValue("PostScriptumMortarCalculator")); | ||
} | ||
|
||
public async Task<UpdateInfo> CheckForUpdate() | ||
{ | ||
#if (!DEBUG) | ||
var release = await m_client.Repository.Release.GetLatest(c_OWNER_NAME, c_REPO_NAME); | ||
var releaseVersion = decimal.Parse(release.TagName); | ||
var currentVersionString = Assembly.GetExecutingAssembly().GetName().Version.ToString(); | ||
var currentVersion = decimal.Parse(currentVersionString); | ||
return new UpdateInfo(currentVersion, releaseVersion, c_RELEASE_PATH); | ||
#endif | ||
return new UpdateInfo(1.0m,1.1m,c_RELEASE_PATH); | ||
} | ||
|
||
public struct UpdateInfo | ||
{ | ||
public decimal CurrentVersion { get; } | ||
public decimal NewVersion { get; } | ||
public string ReleasePath { get; } | ||
|
||
public bool IsUpdateAvailable => NewVersion > CurrentVersion; | ||
|
||
public UpdateInfo(decimal currentVersion, decimal newVersion, string releasePath) | ||
{ | ||
CurrentVersion = currentVersion; | ||
NewVersion = newVersion; | ||
ReleasePath = releasePath; | ||
} | ||
} | ||
} | ||
} |
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
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