예제 #1
0
        private static async Task <bool> SquirrelUpdate(UpdateManager mgr, SplashScreenWindow splashScreenWindow, bool ignoreDelta = false)
        {
            try
            {
                Log.Info($"Checking for updates (ignoreDelta={ignoreDelta})");
                splashScreenWindow?.StartSkipTimer();
                var updateInfo = await mgr.CheckForUpdate(ignoreDelta);

                if (!updateInfo.ReleasesToApply.Any())
                {
                    Log.Info("No new updated available");
                    return(false);
                }
                var latest  = updateInfo.ReleasesToApply.LastOrDefault()?.Version;
                var current = mgr.CurrentlyInstalledVersion();
                if (latest <= current)
                {
                    Log.Info($"Installed version ({current}) is greater than latest release found ({latest}). Not downloading updates.");
                    return(false);
                }
                if (IsRevisionIncrement(current?.Version, latest?.Version))
                {
                    Log.Info($"Latest update ({latest}) is revision increment. Updating in background.");
                    if (splashScreenWindow != null)
                    {
                        splashScreenWindow.SkipUpdate = true;
                    }
                }
                splashScreenWindow?.ShowConditional();
                Log.Info($"Downloading {updateInfo.ReleasesToApply.Count} {(ignoreDelta ? "" : "delta ")}releases, latest={latest?.Version}");
                if (splashScreenWindow != null)
                {
                    await mgr.DownloadReleases(updateInfo.ReleasesToApply, splashScreenWindow.Updating);
                }
                else
                {
                    await mgr.DownloadReleases(updateInfo.ReleasesToApply);
                }
                splashScreenWindow?.Updating(100);
                Log.Info("Applying releases");
                if (splashScreenWindow != null)
                {
                    await mgr.ApplyReleases(updateInfo, splashScreenWindow.Installing);
                }
                else
                {
                    await mgr.ApplyReleases(updateInfo);
                }
                splashScreenWindow?.Installing(100);
                await mgr.CreateUninstallerRegistryEntry();

                Log.Info("Done");
                return(true);
            }
            catch (WebException ex)
            {
                Log.Error(ex);
                if (!_useChinaMirror)
                {
                    _useChinaMirror = true;
                    Log.Warn("Now using china mirror");
                    return(await SquirrelUpdate(mgr, splashScreenWindow, ignoreDelta));
                }
                return(false);
            }
            catch (Exception ex)
            {
                if (ignoreDelta)
                {
                    return(false);
                }
                if (ex is Win32Exception)
                {
                    Log.Info("Not able to apply deltas, downloading full release");
                }
                return(await SquirrelUpdate(mgr, splashScreenWindow, true));
            }
        }
        private static async Task <bool> SquirrelUpdate(UpdateManager mgr, SplashScreenWindow splashScreenWindow, bool ignoreDelta = false)
        {
            try
            {
                var updateInfo = await mgr.CheckForUpdate(ignoreDelta);

                if (!updateInfo.ReleasesToApply.Any())
                {
                    Logger.Info("No new updated available");
                    return(false);
                }
                var latest  = updateInfo.ReleasesToApply.LastOrDefault()?.Version;
                var current = mgr.CurrentlyInstalledVersion();
                if (latest <= current)
                {
                    Logger.Info($"Installed version ({current}) is greater or equal ({latest}). Not downloading updates.");
                    return(false);
                }
                if (IsRevisionIncrement(current?.Version, latest?.Version))
                {
                    Logger.Info($"Newest version ({latest}) is greater or equal ({current}). Updating in background.");
                }
                if (splashScreenWindow != null)
                {
                    await mgr.DownloadReleases(updateInfo.ReleasesToApply, splashScreenWindow.Updating);
                }
                else
                {
                    await mgr.DownloadReleases(updateInfo.ReleasesToApply);
                }
                splashScreenWindow?.Updating(100);
                Logger.Info($"Applying release ({latest})");
                if (splashScreenWindow != null)
                {
                    await mgr.ApplyReleases(updateInfo, splashScreenWindow.Installing);
                }
                else
                {
                    await mgr.ApplyReleases(updateInfo);
                }
                splashScreenWindow?.Installing(100);
                await mgr.CreateUninstallerRegistryEntry();

                Logger.Info("Applying done");
                return(true);
            }
            catch (Exception e)
            {
                if (ignoreDelta)
                {
                    return(false);
                }
                if (e is Win32Exception)
                {
                    Logger.Error("Not able to apply deltas, downloading full release", e);
                }
                if (e is Exception)
                {
                    Logger.Error("Not able to apply update", e);
                }
                return(await SquirrelUpdate(mgr, splashScreenWindow, true));
            }
        }