OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Program.cs
index 71f1385..c147542 100644 (file)
@@ -1,27 +1,80 @@
-/*  Program.cs \r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr>.\r
-          It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.Windows.Forms;\r
-using System.IO;\r
-using Handbrake.Presets;\r
+/*  Program.cs\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake\r
 {\r
-    static class Program\r
+    using System;\r
+    using System.Diagnostics;\r
+    using System.Drawing;\r
+    using System.IO;\r
+    using System.Windows.Forms;\r
+\r
+    using HandBrake.ApplicationServices;\r
+\r
+    using Handbrake.Presets;\r
+    using Handbrake.Properties;\r
+\r
+    /// <summary>\r
+    /// HandBrake Starts Here\r
+    /// </summary>\r
+    public static class Program\r
     {\r
         /// <summary>\r
         /// The main entry point for the application.\r
         /// </summary>\r
+        /// <param name="args">\r
+        /// The args.\r
+        /// </param>\r
         [STAThread]\r
-        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(CurrentDomainUnhandledException);\r
+\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
+                Functions.Main.SetCliVersionData();\r
+            }\r
+\r
+            // Make sure we have any pre-requesits before trying to launch\r
+            string failedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
+            string missingFiles = string.Empty;\r
+\r
+            // Verify HandBrakeCLI.exe exists\r
+            if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
+            {\r
+                missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
+            }\r
+\r
+            if (missingFiles != string.Empty)\r
+            {\r
+                MessageBox.Show(\r
+                    failedInstall + missingFiles,\r
+                    "Error",\r
+                    MessageBoxButtons.OK,\r
+                    MessageBoxIcon.Error);\r
+                return;\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
-                MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n" + "Your screen is running at: " + scr.Bounds.Width + "x" + scr.Bounds.Height + " \nScreen resolution is too Low. Must be 1024x720 or greater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            {\r
+                MessageBox.Show(\r
+                    "Your system does not meet the minimum requirements for HandBrake. \n" +\r
+                    "Your screen is running at: " + scr.Bounds.Width + "x" + scr.Bounds.Height +\r
+                    " \nScreen resolution is too Low. Must be 1024x620 or greater.\n\n",\r
+                    "Error",\r
+                    MessageBoxButtons.OK,\r
+                    MessageBoxIcon.Error);\r
+            } \r
             else\r
             {\r
                 string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");\r
@@ -34,11 +87,40 @@ 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
 \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 CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)\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
+        public static int InstanceId;\r
+    }\r
 }
\ No newline at end of file