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"); await This.ErrorIfThrows(() => This.CreateUninstallerRegistryEntry(), "Failed to set up uninstaller"); } catch (Exception ex) { if (ignoreDeltaUpdates == false) { ignoreDeltaUpdates = true; goto retry; } throw; } return updateInfo.ReleasesToApply.Any() ? updateInfo.ReleasesToApply.MaxBy(x => x.Version).Last() : default(ReleaseEntry); }
/// <summary> /// Fetch the remote store for updates and compare against the current /// version to determine what updates to download. /// </summary> /// <param name="ignoreDeltaUpdates">Set this flag if applying a release /// fails to fall back to a full release, which takes longer to download /// but is less error-prone.</param> /// <param name="progress">An Action which can be used to report Progress - /// will return values from 0-100</param> /// <returns>An UpdateInfo object representing the updates to install. /// </returns> public static Task<UpdateInfo> CheckForUpdateAsync(this IUpdateManager This, bool ignoreDeltaUpdates, Action<int> progress) { var subj = new Subject<int>(); subj.Subscribe(progress); return This.CheckForUpdate(ignoreDeltaUpdates, subj).ToTask(); }
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 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).Select(_ => x)) .SelectMany(x => This.ApplyReleases(x).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).FirstOrDefault())) .Finally(() => theLock.Dispose()) .Multicast(new AsyncSubject<ReleaseEntry>()); ret.Connect(); return ret; }