OSDN Git Service

Win32ApiクラスをNativeMethodsクラスに名前変更 (CA1060)
[opentween/open-tween.git] / OpenTween / ApplicationEvents.cs
index 0a05836..8af9147 100644 (file)
@@ -36,6 +36,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using System.Globalization;
 using System.Reflection;
+using Microsoft.Win32;
 
 namespace OpenTween
 {
@@ -52,6 +53,13 @@ namespace OpenTween
         [STAThread]
         static int Main(string[] args)
         {
+            if (!CheckRuntimeVersion())
+            {
+                var message = string.Format(Properties.Resources.CheckRuntimeVersion_Error, ".NET Framework 4.5.1");
+                MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return 1;
+            }
+
             StartupOptions = ParseArguments(args);
 
             if (!SetConfigDirectoryPath())
@@ -91,6 +99,26 @@ namespace OpenTween
         }
 
         /// <summary>
+        /// 動作中の .NET Framework のバージョンが適切かチェックします
+        /// </summary>
+        private static bool CheckRuntimeVersion()
+        {
+            // Mono 上で動作している場合はバージョンチェックを無視します
+            if (Type.GetType("Mono.Runtime", false) != null)
+                return true;
+
+            // .NET Framework 4.5.1 以降で動作しているかチェックする
+            // 参照: http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx
+
+            using (var lmKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
+            using (var ndpKey = lmKey.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
+            {
+                var releaseKey = (int)ndpKey.GetValue("Release");
+                return releaseKey >= 378675;
+            }
+        }
+
+        /// <summary>
         /// “/key:value”形式の起動オプションを解釈し IDictionary に変換する
         /// </summary>
         /// <remarks>
@@ -121,7 +149,7 @@ namespace OpenTween
             {
                 if (form.WindowState == FormWindowState.Minimized)
                 {
-                    Win32Api.RestoreWindow(form);
+                    NativeMethods.RestoreWindow(form);
                 }
                 form.Activate();
             }