OSDN Git Service

アップデート確認機能を追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 18 May 2012 21:31:10 +0000 (06:31 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 18 May 2012 21:38:40 +0000 (06:38 +0900)
自動アップデートではない

OpenTween/ApplicationSettings.cs
OpenTween/DialogAsShieldIcon.cs
OpenTween/MyCommon.cs
OpenTween/Resources/ChangeLog.txt
OpenTween/Tween.cs
OpenTween/Twitter.cs

index 19635a3..ac8f2e7 100644 (file)
@@ -65,6 +65,17 @@ namespace OpenTween
         public const string ShortcutKeyUrl = "http://sourceforge.jp/projects/tween/wiki/%E3%82%B7%E3%83%A7%E3%83%BC%E3%83%88%E3%82%AB%E3%83%83%E3%83%88%E3%82%AD%E3%83%BC";
 
         //=====================================================================
+        // アップデートチェック関連
+
+        /// <summary>
+        /// 最新バージョンの情報を取得するためのURL
+        /// </summary>
+        /// <remarks>
+        /// version.txt のフォーマットについては http://sourceforge.jp/projects/opentween/wiki/VersionTxt を参照。
+        /// </remarks>
+        public const string VersionInfoUrl = "http://www.opentween.org/status/version.txt";
+
+        //=====================================================================
         // Twitter
         // https://dev.twitter.com/ から取得できます。
 
index 40c2689..5dd6a26 100644 (file)
@@ -72,7 +72,8 @@ namespace OpenTween
             this.PictureBox1.Image = System.Drawing.SystemIcons.Question.ToBitmap();
         }
 
-        public System.Windows.Forms.DialogResult ShowDialog(string text, string detail = "", string caption = "DialogAsShieldIcon",
+        public System.Windows.Forms.DialogResult ShowDialog(IWin32Window owner,
+            string text, string detail = "", string caption = "DialogAsShieldIcon",
             System.Windows.Forms.MessageBoxButtons Buttons = System.Windows.Forms.MessageBoxButtons.OKCancel,
             System.Windows.Forms.MessageBoxIcon icon = MessageBoxIcon.Question)
         {
index f1e3305..86d2036 100644 (file)
@@ -815,15 +815,22 @@ namespace OpenTween
         /// <remarks>
         /// バージョン1.0.0.1のように末尾が0でない(=開発版)の場合は「1.0.1-beta1」が出力される
         /// </remarks>
-        /// <returns></returns>
-        public static string GetReadableVersion()
+        /// <returns>
+        /// 生成されたバージョン番号の文字列
+        /// </returns>
+        public static string GetReadableVersion(string fileVersion = null)
         {
-            if (string.IsNullOrEmpty(MyCommon.fileVersion))
+            if (fileVersion == null)
+            {
+                fileVersion = MyCommon.fileVersion;
+            }
+
+            if (string.IsNullOrEmpty(fileVersion))
             {
                 return null;
             }
 
-            int[] version = MyCommon.fileVersion.Split('.')
+            int[] version = fileVersion.Split('.')
                 .Select(x => int.Parse(x)).ToArray();
 
             if (version[3] == 0)
index d1f567f..f2bdc9a 100644 (file)
@@ -1,6 +1,7 @@
 更新履歴
 
 ==== Ver 1.0.2-beta1(2012/xx/xx)
+ * NEW: アップデート確認機能を追加
  * FIX: 発言詳細部においてUnicodeで追加された一部の文字が正しく表示されない問題を修正
  * FIX: メッセージなどに含まれるアプリケーション名の変更漏れを修正
  * FIX: タスクバーから復元した際に最大化した状態が保持されない問題を修正
index 44a633f..406ae17 100644 (file)
@@ -5979,10 +5979,57 @@ namespace OpenTween
 
         private void CheckNewVersion(bool startup = false)
         {
-            // TODO 自動アップデート機能の実装
-            if (!startup)
+            if (string.IsNullOrEmpty(MyCommon.fileVersion))
+            {
+                return;
+            }
+
+            string retMsg;
+            try
+            {
+                retMsg = tw.GetVersionInfo();
+            }
+            catch
+            {
+                retMsg = "";
+            }
+
+            if (string.IsNullOrEmpty(retMsg))
+            {
+                StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
+                if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText10, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
+                return;
+            }
+
+            // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
+            string[] msgPart = retMsg.Split(new string[] {"\n\n", "\r\n\r\n"}, 2, StringSplitOptions.None);
+
+            string[] msgHeader = msgPart[0].Split(new string[] {"\n", "\r\n"}, StringSplitOptions.None);
+            string msgBody = msgPart.Length == 2 ? msgPart[1] : "";
+
+            msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
+
+            string currentVersion = msgHeader[0];
+            string downloadUrl = msgHeader[1];
+
+            if (currentVersion.Replace(".", "").CompareTo(MyCommon.fileVersion.Replace(".", "")) > 0)
+            {
+                string dialogText = string.Format(Properties.Resources.CheckNewVersionText3, MyCommon.GetReadableVersion(currentVersion));
+                using (DialogAsShieldIcon dialog = new DialogAsShieldIcon())
+                {
+                    DialogResult ret = dialog.ShowDialog(this, dialogText, msgBody, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText1), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+                    if (ret == DialogResult.Yes)
+                    {
+                        this.OpenUriAsync(downloadUrl);
+                    }
+                }
+            }
+            else
             {
-                MessageBox.Show(this, "OpenTween の自動アップデート機能は未実装です。OpenTween のウェブサイトで更新を確認し手動でアップデートしてください。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
+                if (!startup)
+                {
+                    MessageBox.Show(Properties.Resources.CheckNewVersionText7 + MyCommon.GetReadableVersion() + Properties.Resources.CheckNewVersionText8 + MyCommon.GetReadableVersion(currentVersion), MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Information);
+                }
             }
         }
 
index 8855bcb..7627d67 100644 (file)
@@ -1656,7 +1656,7 @@ namespace OpenTween
         public string GetVersionInfo()
         {
             var content = "";
-            if (!(new HttpVarious()).GetData("http://tween.sourceforge.jp/version.txt?" + DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount.ToString(), null, out content, MyCommon.GetUserAgentString()))
+            if (!(new HttpVarious()).GetData(ApplicationSettings.VersionInfoUrl + "?" + DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount.ToString(), null, out content, MyCommon.GetUserAgentString()))
             {
                 throw new Exception("GetVersionInfo Failed");
             }