示例#1
0
        private void UpdateForm_Load(object sender, EventArgs e)
        {
            downloadClient = new WebClient();
            //イベントハンドラの作成
            downloadClient.DownloadProgressChanged +=
                new System.Net.DownloadProgressChangedEventHandler(
                    downloadClient_DownloadProgressChanged);
            downloadClient.DownloadFileCompleted +=
                new System.ComponentModel.AsyncCompletedEventHandler(downloadClient_DownloadFileCompleted);

            if (Program.isForceUpdate)
            {
                update();
                return;
            }

            // アップデートする必要があるか?
            string nowVersion = "";

            if (File.Exists(LINEAR_DIR + "\\LinearAudioPlayer.exe"))
            {
                System.Diagnostics.FileVersionInfo appver = System.Diagnostics.FileVersionInfo.GetVersionInfo(
                    LINEAR_DIR + "\\LinearAudioPlayer.exe");
                nowVersion = appver.FileMajorPart.ToString() + "."
                             + appver.FileMinorPart.ToString() + "."
                             + appver.FileBuildPart.ToString();
            }

            WebResponse res            = new WebManager().request(LINEAR_URL);
            string      newFileVersion = "";

            newFileVersion = Path.GetFileNameWithoutExtension(res.ResponseUri.ToString());
            res.Close();
            newFileVersion = newFileVersion.Substring(newFileVersion.Length - 5, 5);

            if (newFileVersion.CompareTo(nowVersion) > 0)
            {
                if (MessageUtils.showQuestionMessage("最新バージョンが見つかりました。\nver." + newFileVersion + "にアップデートしますか?\nアップデートするとLinearAudioPlayerは再起動します。") == DialogResult.OK)
                {
                    update();
                }
                else
                {
                    // 終了
                    Application.Exit();
                }
            }
            else
            {
                MessageUtils.showMessage(MessageBoxIcon.Information, "最新バージョンのLinearAudioPlayerを使用しています。");
                // 終了
                Application.Exit();
            }
        }
        /// <summary>
        /// 最新バージョンがリリースされているかチェックする
        /// </summary>
        /// <returns></returns>
        public static UpdateInfo checkSoftwareUpdate()
        {
            UpdateInfo updateInfo = new UpdateInfo();

            WebResponse res = null;

            try
            {
                res =
                    new WebManager().request("http://www.finalstream.net/dl/download.php?dl=lap-checkupdate");
                updateInfo.NewFileVersion = Path.GetFileNameWithoutExtension(res.ResponseUri.ToString());
                updateInfo.NewFileVersion = updateInfo.NewFileVersion.Substring(updateInfo.NewFileVersion.Length - 5, 5);

                string nowVersion = LinearGlobal.ApplicationVersion.Substring(
                    LinearGlobal.ApplicationVersion.Length - 5, 5);

                if (updateInfo.NewFileVersion.CompareTo(nowVersion) > 0)
                {
                    updateInfo.CheckResultMessage      = "新しいバージョン(ver." + updateInfo.NewFileVersion + ")がリリースされています。";
                    updateInfo.CheckResultMessageColor = Color.Crimson;
                    updateInfo.IsReleaseNewVersion     = true;
                }
                else if (updateInfo.NewFileVersion.CompareTo(nowVersion) == 0)
                {
                    updateInfo.CheckResultMessage = "最新バージョンのLinear Audio Playerを使用しています。";
                }
                else
                {
                    updateInfo.CheckResultMessage      = "開発中バージョンのLinear Audio Playerを使用しています。";
                    updateInfo.CheckResultMessageColor = Color.MediumBlue;
                }
            }
            catch
            {
                updateInfo.CheckResultMessage = "最新バージョンチェックに失敗しました。";
            }
            finally
            {
                if (res != null)
                {
                    res.Close();
                }
            }


            return(updateInfo);
        }