Exemplo n.º 1
0
        /// <summary>
        /// 新たな更新情報が確認された後の手続きを確認します。
        /// </summary>
        private NextUpdateAction OnUpdateDetected(AppCastItem latestVersion)
        {
            var e = new UpdateDetectedEventArgs
            {
                NextAction        = NextUpdateAction.ContinueToUpdate,
                ApplicationConfig = config,
                LatestVersion     = latestVersion,
            };

            UpdateDetected.SafeRaiseEvent(this, e);
            return(e.NextAction);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新情報のダウンロード後に呼ばれます。
        /// </summary>
        void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                Log.ErrorException(e.Error,
                                   "更新情報の取得に失敗しました。");

                this.latestVersionEvent.Set();
                return;
            }

            try
            {
                var text          = Encoding.UTF8.GetString(e.Result);
                var latestVersion = AppCastItemUtil.GetLatestVersion(text);
                if (!IsUpdateRequired(latestVersion))
                {
                    this.latestVersionEvent.Set();
                    return;
                }

                this.latestVersion = latestVersion;
                this.latestVersionEvent.Set();

                // show the update window
                Log.Info(
                    "Update needed from version {0} to version {1}.",
                    this.config.InstalledVersion,
                    latestVersion.Version);

                switch (OnUpdateDetected(latestVersion))
                {
                case NextUpdateAction.ContinueToUpdate:
                    Log.Info("Updater: Continue to update");
                    BeginDownload(latestVersion);
                    break;

                case NextUpdateAction.ProhibitUpdate:
                default:
                    Log.Info("Updater: Update prohibited");
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException(ex,
                                   "ダウンロードに失敗しました。");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 必要なファイルのダウンロードを開始します。
        /// </summary>
        private void BeginDownload(AppCastItem latestVersion)
        {
            this.downloader         = new Downloader();
            this.downloadFilePath   = Util.GetTempFileName();
            this.packFilePath       = Util.GetTempFileName();
            this.packConfigFilePath = this.packFilePath + ".config";

            this.downloader.BeginDownload(
                new Uri(latestVersion.DownloadLink),
                (_, e) => SaveDownloadFile(this.downloadFilePath, e));
            this.downloader.BeginDownload(
                new Uri(latestVersion.UpdatePackLink),
                (_, e) => SaveDownloadFile(this.packFilePath, e));
            this.downloader.BeginDownload(
                new Uri(latestVersion.UpdatePackLink + ".config"),
                (_, e) => SaveDownloadFile(this.packConfigFilePath, e));
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method checks if an update is required. During this process the appcast
        /// will be downloaded and checked against the reference assembly. Ensure that
        /// the calling process has access to the internet and read access to the
        /// reference assembly. This method is also called from the background loops.
        /// </summary>
        private bool IsUpdateRequired(AppCastItem latestVersion)
        {
            if (latestVersion == null)
            {
                Log.Info(
                    "Updater: No version information in app cast found.");
                return(false);
            }
            else
            {
                Log.Info(
                    "Updater: Lastest version on the server is {0}.",
                    latestVersion.Version);
            }

            // check if the available update has to be skipped
            if (latestVersion.Version.Equals(this.config.SkipThisVersion))
            {
                Log.Info(
                    "Updater: Latest update has to be skipped (user decided to skip version {0})",
                    config.SkipThisVersion);
                return(false);
            }

            // check if the version will be the same then the installed version
            var v1 = new Version(this.config.InstalledVersion);
            var v2 = new Version(latestVersion.Version);

            if (v2 <= v1)
            {
                Log.Info(
                    "Updater: Installed version is valid, no update needed. ({0})",
                    this.config.InstalledVersion);
                return(false);
            }

            // ok we need an update
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// アプリの最新バージョン情報を取得します。
        /// </summary>
        /// <remarks>
        /// このメソッドは例外を投げる可能性があります。
        /// </remarks>
        public static AppCastItem GetLatestVersion(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            /*using (var textReader = new StringReader(text))
             * using (var reader = XmlReader.Create(textReader))*/
            {
                var doc = new XmlDocument
                {
                    PreserveWhitespace = false,
                };
                doc.LoadXml(text);

                var         itemNodes     = doc.SelectNodes(TopItemNode);
                AppCastItem latestVersion = null;

                // rss中の全itemタグを検索します。
                foreach (var itemNode in itemNodes.OfType <XmlNode>())
                {
                    var currentItem = CreateAppCastItemFromNode(doc, itemNode);

                    if (latestVersion == null)
                    {
                        latestVersion = currentItem;
                    }
                    else if (currentItem.CompareTo(latestVersion) > 0)
                    {
                        latestVersion = currentItem;
                    }
                }

                // go ahead
                return(latestVersion);
            }
        }