Created
June 20, 2016 11:28
-
-
Save igorkulman/702be46eacba7bfe3f1444815aef645a to your computer and use it in GitHub Desktop.
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
public class UpdateService : IUpdateService | |
{ | |
public async Task<UpdateInfo> CheckForUpdates() | |
{ | |
try | |
{ | |
bool restart = false; | |
string latestExe = ""; | |
using (var mgr = new Squirrel.UpdateManager(@"http://x.y.z/AppName/Releases/")) | |
{ | |
var updates = await mgr.CheckForUpdate(); | |
if (updates.ReleasesToApply.Any()) | |
{ | |
Log.Information($"Update Service - New version avaliable "); | |
var lastVersion = updates.ReleasesToApply.OrderBy(x => x.Version).Last(); | |
Log.Information($"Update Service - New version avaliable - last version: {lastVersion.Version.Version.ToString()}"); | |
await mgr.DownloadReleases(updates.ReleasesToApply); | |
await mgr.ApplyReleases(updates); | |
Log.Information($"Update Service - New version avaliable - downloading release"); | |
latestExe = System.IO.Path.Combine(mgr.RootAppDirectory, string.Concat("app-", lastVersion.Version.Version.Major, ".", lastVersion.Version.Version.Minor, ".", lastVersion.Version.Version.Build, ".", lastVersion.Version.Version.Revision), "IsicCheck.exe"); | |
restart = true; | |
Log.Information($"Update Service - New version avaliable - Lastest EXE file: {latestExe}"); | |
} | |
else | |
{ | |
Log.Information($"Update Service - No new updates"); | |
return new UpdateInfo(false, String.Empty); | |
} | |
} | |
if (restart) | |
{ | |
return new UpdateInfo(true, $"\"{ latestExe}\""); | |
} | |
return new UpdateInfo(false, String.Empty); | |
} | |
catch (Exception e) | |
{ | |
Log.Information($"UpdateService - CheckForUpdates Exception: {e.Message}"); | |
//MessageBox.Show(e.Message); | |
return new UpdateInfo(false, String.Empty); | |
} | |
} | |
public void RestartApp(UpdateInfo info) | |
{ | |
try | |
{ | |
if (info.IsUpdateAvaliable) | |
{ | |
Log.Information($"Update Service - Update found - Application will restart"); | |
Squirrel.UpdateManager.RestartApp(info.LatestExePath); | |
} | |
} | |
catch (Exception e) | |
{ | |
Log.Information($"UpdateService - RestartApp Exception: {e.Message}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment