public async Task <bool> ApplyDownloadedUpdatesAsync(bool restartAfterUpdate = true, string restartArguments = null, Action <int> progress = null) { bool isUpdated = false; try { if (IsNewVersionAvailable(_downloadedUpdateInfo)) { await _updateManager.ApplyReleases(_downloadedUpdateInfo, progress); isUpdated = true; _downloadedUpdateInfo = null; if (restartAfterUpdate) { RestartApplication(restartArguments); } } } catch (WebException ex) { Trace.WriteLine($"ApplyDownloadedUpdatesAsync failed with web exception {ex.Message}"); _downloadedUpdateInfo = null; } catch (Exception ex) { Trace.WriteLine($"ApplyDownloadedUpdatesAsync failed with unexpected error {ex.Message}"); _downloadedUpdateInfo = null; } return(isUpdated); }
/// <summary> /// Take an already downloaded set of releases and apply them, /// copying in the new files from the NuGet package and rewriting /// the application shortcuts. /// </summary> /// <param name="updateInfo">The UpdateInfo instance acquired from /// CheckForUpdate</param> /// <param name="progress">An Action which can be used to report Progress - /// will return values from 0-100</param> /// <returns>A list of EXEs that should be started if this is a new /// installation.</returns> public static Task <List <string> > ApplyReleasesAsync(this IUpdateManager This, UpdateInfo updateInfo, Action <int> progress) { var subj = new Subject <int>(); subj.Subscribe(progress, ex => { }); return(This.ApplyReleases(updateInfo, subj).ToTask()); }
private async Task CheckForUpdate() { try { ShowMessage("Checking new versions..."); var update = await _updateManager.CheckForUpdate(false, x => ShowMessage($"Checking updates: {x}%")); try { var semanticVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0); var version = update.FutureReleaseEntry.Version; if (semanticVersion < version) { ShowMessage($"Updating to [{version}]..."); await _updateManager.DownloadReleases(update.ReleasesToApply, x => ShowMessage($"Download update: {x}%")); await _updateManager.ApplyReleases(update, x => ShowMessage($"Applying update: {x}%")); ShowMessage($"Done update to [{version}]"); } else { ShowMessage("The latest version is installed"); } } catch (Exception ex) { ShowMessage($"[{_currentVersion}]: Fail updating - {ex.Message}"); } } catch (Exception ex) { ShowMessage($"[{_currentVersion}]: Can't check for update - {ex.Message}"); } }
private void DownloadReleasesCallback(Action <UpdateStatus, int> progressCallback, Action <Exception> errCallback) { progressCallback(UpdateStatus.Installing, 0); Log.Info("Squirrel: Applying releases..."); var applyReleasesTask = _updateManager.ApplyReleases(_updateInfo, progress => progressCallback(UpdateStatus.Installing, progress)); applyReleasesTask.ContinueWith(t => ApplyReleasesCallback(progressCallback, errCallback, t.Result), TaskContinuationOptions.OnlyOnRanToCompletion); applyReleasesTask.ContinueWith(t => HandleAsyncError(errCallback, t.Exception), TaskContinuationOptions.OnlyOnFaulted); }
/// <summary> /// Updates this instance. /// </summary> /// <returns></returns> /// <exception cref="Exception">Update manager can not be null</exception> private async Task Update() { if (updateManager == null) { throw new Exception("Update manager can not be null"); } Log.InfoFormat("Automatic-renewal was launched ({0})", curversion); { while (true) { await Task.Delay(checkUpdatePeriod); try { // Check for update var update = await updateManager.CheckForUpdate(); try { var oldVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0); Log.InfoFormat("Installed version: {0}", oldVersion); var newVersion = update.FutureReleaseEntry.Version; if (oldVersion < newVersion) { Log.InfoFormat("Found a new version: {0}", newVersion); // Downlaod Release await updateManager.DownloadReleases(update.ReleasesToApply); // Apply Release await updateManager.ApplyReleases(update); } } catch (Exception ex) { Log.ErrorFormat("Error on update ({0}): {1}", curversion, ex); } } catch (Exception ex) { Log.ErrorFormat("Error on check for update ({0}): {1}", curversion, ex); } } } }
private async Task Update() { if (updateManager == null) { throw new Exception("Update manager can not be null"); } Trace.TraceInformation("Automatic-renewal was launched ({0})", curversion); { while (true) { await Task.Delay(checkUpdatePeriod); try { //Проверяем наличие новой версии var update = await updateManager.CheckForUpdate(); try { var oldVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0); var newVersion = update.FutureReleaseEntry.Version; if (oldVersion < newVersion) { Trace.TraceInformation("Found a new version: {0}", newVersion); //Скачиваем новую версию await updateManager.DownloadReleases(update.ReleasesToApply); //Распаковываем новую версию await updateManager.ApplyReleases(update); } } catch (Exception ex) { Trace.TraceError("Error on update ({0}): {1}", curversion, ex); } } catch (Exception ex) { Trace.TraceError("Error on check for update ({0}): {1}", curversion, ex); } } } }
public static async Task <ReleaseEntry> UpdateApp(this IUpdateManager This, Action <int> progress = null) { progress = progress ?? (_ => {}); This.Log().Info("Starting automatic update"); var updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(false, x => progress(x / 3)), "Failed to check for updates"); await This.ErrorIfThrows(() => This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)), "Failed to download updates"); await This.ErrorIfThrows(() => This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)), "Failed to apply updates"); return(updateInfo.ReleasesToApply.MaxBy(x => x.Version).LastOrDefault()); }
public static async Task <ReleaseEntry> UpdateApp(this IUpdateManager This, Action <int> progress = null) { progress = progress ?? (_ => { }); This.Log().Info("Starting automatic update"); bool ignoreDeltaUpdates = false; retry: var updateInfo = default(UpdateInfo); try { updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(ignoreDeltaUpdates, x => progress(x / 3)), "Failed to check for updates"); await This.ErrorIfThrows(() => This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)), "Failed to download updates"); await This.ErrorIfThrows(() => This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)), "Failed to apply updates"); This.ErrorIfThrows(() => This.UpdateUninstallerVersionRegistryEntry(), "Failed to set up uninstaller"); } catch { if (ignoreDeltaUpdates == false) { ignoreDeltaUpdates = true; goto retry; } throw; } return(updateInfo.ReleasesToApply.Any() ? updateInfo.ReleasesToApply.MaxBy(x => x.Version).Last() : default(ReleaseEntry)); }
public static Task <ReleaseEntry> UpdateAppAsync(this IUpdateManager This, Action <int> progress) { var checkSubj = new Subject <int>(); var downloadSubj = new Subject <int>(); var applySubj = new Subject <int>(); var ret = This.CheckForUpdate(false, checkSubj) .SelectMany(x => This.DownloadReleases(x.ReleasesToApply, downloadSubj).TakeLast(1).Select(_ => x)) .SelectMany(x => This.ApplyReleases(x, applySubj).TakeLast(1).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).LastOrDefault())) .PublishLast(); var allProgress = Observable.Merge( checkSubj.Select(x => (double)x / 3.0), downloadSubj.Select(x => (double)x / 3.0), applySubj.Select(x => (double)x / 3.0)) .Scan(0.0, (acc, x) => acc + x); allProgress.Subscribe(x => progress((int)x)); ret.Connect(); return(ret.ToTask()); }
public static IObservable <ReleaseEntry> UpdateApp(this IUpdateManager This) { IDisposable theLock; try { theLock = This.AcquireUpdateLock(); } catch (TimeoutException _) { // TODO: Bad Programmer! return(Observable.Return(default(ReleaseEntry))); } catch (Exception ex) { return(Observable.Throw <ReleaseEntry>(ex)); } var ret = This.CheckForUpdate() .SelectMany(x => This.DownloadReleases(x.ReleasesToApply).TakeLast(1).Select(_ => x)) .SelectMany(x => This.ApplyReleases(x).TakeLast(1).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).LastOrDefault())) .Finally(() => theLock.Dispose()) .Multicast(new AsyncSubject <ReleaseEntry>()); ret.Connect(); return(ret); }