OSDN Git Service

WinGui: Re-checkin updated stylecop settings
[handbrake-jp/handbrake-jp-git.git] / win / C# / Program.cs
index bf4f317..1c428c8 100644 (file)
@@ -6,8 +6,14 @@
 namespace Handbrake\r
 {\r
     using System;\r
+    using System.Diagnostics;\r
     using System.IO;\r
     using System.Windows.Forms;\r
+\r
+    using HandBrake.ApplicationServices;\r
+\r
+    using Handbrake.Properties;\r
+\r
     using Presets;\r
 \r
     /// <summary>\r
@@ -19,17 +25,28 @@ namespace Handbrake
         /// The main entry point for the application.\r
         /// </summary>\r
         [STAThread]\r
-        public static void Main()\r
+        public static void Main(string[] args)\r
         {\r
+            InstanceId = Process.GetProcessesByName("HandBrake").Length;\r
+\r
+            // Handle any unhandled exceptions\r
             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);\r
 \r
-            const string failedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
-            const string nightlyCLIMissing =\r
+            // Attempt to upgrade / keep the users settings between versions\r
+            if (Settings.Default.UpdateRequired)\r
+            {\r
+                Settings.Default.Upgrade();\r
+                Settings.Default.UpdateRequired = false;\r
+            }\r
+\r
+            // Make sure we have any pre-requesits before trying to launch\r
+            const string FailedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
+            const string NightlyCLIMissing =\r
                 "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
                 "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
             string missingFiles = string.Empty;\r
 \r
-            // Verify HandBrakeCLI.exe and ilibgcc_s_sjlj-1.dll exists\r
+            // Verify HandBrakeCLI.exe exists\r
             if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
             {\r
                 missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
@@ -37,30 +54,14 @@ namespace Handbrake
 \r
             if (missingFiles != string.Empty)\r
             {\r
-                MessageBox.Show(failedInstall + missingFiles + "\n\n"+ nightlyCLIMissing, "Error", MessageBoxButtons.OK,\r
-                                MessageBoxIcon.Error);\r
+                MessageBox.Show(\r
+                    FailedInstall + missingFiles + "\n\n" + NightlyCLIMissing,\r
+                    "Error",\r
+                    MessageBoxButtons.OK,\r
+                    MessageBoxIcon.Error);\r
                 return;\r
             }\r
 \r
-            // Make sure we have a recent version for svn builds\r
-            string version = Properties.Settings.Default.hb_version;\r
-            if (version.Contains("svn"))\r
-            {\r
-                version = version.Replace("svn", string.Empty).Trim();\r
-                int build;\r
-                int.TryParse(version, out build);\r
-                if (build < Properties.Settings.Default.hb_min_cli)\r
-                {\r
-                    MessageBox.Show(\r
-                        "It appears you are trying to use a CLI executable that is too old for this version of the HandBrake GUI.\n" + \r
-                        "Please update the HandBrakeCLI.exe to a newer build. ",\r
-                        "Error",\r
-                        MessageBoxButtons.OK,\r
-                        MessageBoxIcon.Error);\r
-                    return;\r
-                }\r
-            }\r
-\r
             // Check were not running on a screen that's going to cause some funnies to happen.\r
             Screen scr = Screen.PrimaryScreen;\r
             if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 620))\r
@@ -77,24 +78,52 @@ namespace Handbrake
                     x.UpdateBuiltInPresets();\r
                 }\r
 \r
+                InitializeApplicationServices();\r
+\r
                 Application.EnableVisualStyles();\r
                 Application.SetCompatibleTextRenderingDefault(false);\r
-                Application.Run(new frmMain());\r
+                Application.Run(new frmMain(args));\r
             }\r
         }\r
 \r
         /// <summary>\r
+        /// Initialize App Services\r
+        /// </summary>\r
+        private static void InitializeApplicationServices()\r
+        {\r
+            string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
+            Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
+                               Settings.Default.growlEncode, Settings.Default.growlQueue,\r
+                               Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath,\r
+                               Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep);\r
+        }\r
+\r
+        /// <summary>\r
         /// Throw up an error message for any unhandled exceptions.\r
         /// </summary>\r
         /// <param name="sender">The sender</param>\r
         /// <param name="e">Unhandled Exception EventArgs </param>\r
         private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)\r
         {\r
-            MessageBox.Show(\r
-                "An unexpected error has occured.\n\nSender:" + sender + "\n\nException:" + e.ExceptionObject, \r
-                "Unhandled Exception",\r
-                MessageBoxButtons.OK,\r
-                MessageBoxIcon.Error);\r
+            try\r
+            {\r
+                frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
+                exceptionWindow.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString());\r
+                exceptionWindow.ShowDialog();\r
+            }\r
+            catch (Exception)\r
+            {\r
+                MessageBox.Show(\r
+                    "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject,\r
+                    "Unhandled Exception",\r
+                    MessageBoxButtons.OK,\r
+                    MessageBoxIcon.Error);\r
+            }\r
         }\r
+\r
+\r
+        public static int InstanceId = 0;\r
+\r
+\r
     }\r
 }
\ No newline at end of file