예제 #1
0
        public async Task <bool> GetUpdatesInBackgroundAsync(Action <int> progress = null)
        {
            bool hasDownloaded = false;

            try
            {
                UpdateInfo info = await _updateManager.CheckForUpdate();

                if (IsNewVersionAvailable(info))
                {
                    await _updateManager.DownloadReleases(info.ReleasesToApply, progress);

                    hasDownloaded         = true;
                    _downloadedUpdateInfo = info;
                }
            }
            catch (WebException ex)
            {
                Trace.WriteLine($"GetUpdatesInBackgroundAsync failed with web exception {ex.Message}");
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"GetUpdatesInBackgroundAsync failed with unexpected error {ex.Message}");
            }

            return(hasDownloaded);
        }
예제 #2
0
        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}");
            }
        }
예제 #3
0
        /// <summary>
        /// Download a list of releases into the local package directory.
        /// </summary>
        /// <param name="releasesToDownload">The list of releases to download,
        /// almost always from UpdateInfo.ReleasesToApply.</param>
        /// <param name="progress">An Action which can be used to report Progress -
        /// will return values from 0-100</param>
        /// <returns>A completion Task<returns>
        public static Task DownloadReleasesAsync(this IUpdateManager This, IEnumerable <ReleaseEntry> releasesToDownload, Action <int> progress)
        {
            var subj = new Subject <int>();

            subj.Subscribe(progress, ex => { });

            return(This.DownloadReleases(releasesToDownload, subj).ToTask());
        }
        /// <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);
                    }
                }
            }
        }
예제 #6
0
        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());
        }
예제 #7
0
        public void Update(Action <UpdateStatus, int> progressCallback, Action <Exception> errCallback)
        {
            if (!Enabled)
            {
                throw new ApplicationException("Updates are currently disabled");
            }

            if (_updateInfo == null)
            {
                throw new ApplicationException("The update available link was shown while update info is not available to SettingsViewModel.Update.");
            }

            // TODO: Make an update dialog
            progressCallback(UpdateStatus.Downloading, 0);
            Log.Info("Squirrel: Downloading releases...");
            var downloadReleasesTask = _updateManager.DownloadReleases(_updateInfo.ReleasesToApply, progress => progressCallback(UpdateStatus.Downloading, progress));

            downloadReleasesTask.ContinueWith(t => DownloadReleasesCallback(progressCallback, errCallback), TaskContinuationOptions.OnlyOnRanToCompletion);
            downloadReleasesTask.ContinueWith(t => HandleAsyncError(errCallback, t.Exception), TaskContinuationOptions.OnlyOnFaulted);
        }
예제 #8
0
        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));
        }
예제 #9
0
        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());
        }
예제 #10
0
        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);
        }