-
Notifications
You must be signed in to change notification settings - Fork 12
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 #218 from anno-mods/devel/self-updater
add update checker, support sub mods
- Loading branch information
Showing
8 changed files
with
94 additions
and
42 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,60 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using Octokit; | ||
|
||
namespace Anno.Utils | ||
{ | ||
internal class SelfUpdater | ||
{ | ||
public static void CheckForUpdate(GitHubClient client, string owner, string repo) | ||
{ | ||
Task.Run(async () => | ||
{ | ||
var availableUpdate = await IsUpdateAvailableAsync(client, owner, repo); | ||
if (availableUpdate is not null) | ||
{ | ||
var answer = MessageBox.Show($"iModYourAnno {availableUpdate.TagName} is available.\n\nDo you want to download it now?", | ||
"Update Available", MessageBoxButton.YesNo); | ||
if (answer == MessageBoxResult.Yes) | ||
{ | ||
OpenReleasePage(availableUpdate); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public async static Task<Release?> IsUpdateAvailableAsync(GitHubClient client, string owner, string repo) | ||
{ | ||
var latest = await client.Repository.Release.GetLatest(owner, repo); | ||
if (latest is null) return null; | ||
|
||
Console.WriteLine( | ||
"The latest release is tagged at {0} and is named {1}", | ||
latest.TagName, | ||
latest.Name); | ||
|
||
var latestVersion = new Version(latest.TagName[1..]); | ||
var currentVersion = GetCurrentVersion(); | ||
|
||
return (latestVersion > currentVersion) ? latest : null; | ||
} | ||
|
||
public static void OpenReleasePage(Release release) | ||
{ | ||
var info = new ProcessStartInfo(release.HtmlUrl) | ||
{ | ||
UseShellExecute = true, | ||
}; | ||
Process.Start(info); | ||
} | ||
|
||
public static Version GetCurrentVersion() | ||
{ | ||
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); | ||
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
return new Version((fvi.FileVersion ?? "v0.0")[1..].Split('-')[0]); | ||
} | ||
} | ||
} |
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 was deleted.
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
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