OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Program.cs
1 /*  Program.cs\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace Handbrake\r
7 {\r
8     using System;\r
9     using System.Diagnostics;\r
10     using System.IO;\r
11     using System.Windows.Forms;\r
12 \r
13     using Handbrake.Presets;\r
14 \r
15     using HandBrake.ApplicationServices;\r
16 \r
17     using Handbrake.Properties;\r
18 \r
19     /// <summary>\r
20     /// HandBrake Starts Here\r
21     /// </summary>\r
22     public static class Program\r
23     {\r
24         /// <summary>\r
25         /// The main entry point for the application.\r
26         /// </summary>\r
27         /// <param name="args">Arguments passed in from the shortcut/executable</param>\r
28         [STAThread]\r
29         public static void Main(string[] args)\r
30         {\r
31             InstanceId = Process.GetProcessesByName("HandBrake").Length;\r
32 \r
33             // Handle any unhandled exceptions\r
34             AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;\r
35 \r
36             // Attempt to upgrade / keep the users settings between versions\r
37             if (Settings.Default.UpdateRequired)\r
38             {\r
39                 Settings.Default.Upgrade();\r
40                 Settings.Default.UpdateRequired = false;\r
41             }\r
42 \r
43             // Make sure we have any pre-requesits before trying to launch\r
44             const string FailedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
45             const string NightlyCLIMissing =\r
46                 "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
47                 "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
48             string missingFiles = string.Empty;\r
49 \r
50             // Verify HandBrakeCLI.exe exists\r
51             if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
52             {\r
53                 missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
54             }\r
55 \r
56             if (missingFiles != string.Empty)\r
57             {\r
58                 MessageBox.Show(\r
59                     FailedInstall + missingFiles + "\n\n" + NightlyCLIMissing,\r
60                     "Error",\r
61                     MessageBoxButtons.OK,\r
62                     MessageBoxIcon.Error);\r
63                 return;\r
64             }\r
65 \r
66             // Check were not running on a screen that's going to cause some funnies to happen.\r
67             Screen scr = Screen.PrimaryScreen;\r
68             if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 620))\r
69                 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 1024x620 or greater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
70             else\r
71             {\r
72                 string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");\r
73                 if (!Directory.Exists(logDir))\r
74                     Directory.CreateDirectory(logDir);\r
75 \r
76                 if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))\r
77                 {\r
78                     PresetsHandler x = new PresetsHandler();\r
79                     x.UpdateBuiltInPresets();\r
80                 }\r
81 \r
82                 InitializeApplicationServices();\r
83 \r
84                 Application.EnableVisualStyles();\r
85                 Application.SetCompatibleTextRenderingDefault(false);\r
86                 Application.Run(new frmMain(args));\r
87             }\r
88         }\r
89 \r
90         /// <summary>\r
91         /// Initialize App Services\r
92         /// </summary>\r
93         private static void InitializeApplicationServices()\r
94         {\r
95             string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
96             Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
97                                Settings.Default.growlEncode, Settings.Default.growlQueue,\r
98                                Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath,\r
99                                Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep);\r
100         }\r
101 \r
102         /// <summary>\r
103         /// Throw up an error message for any unhandled exceptions.\r
104         /// </summary>\r
105         /// <param name="sender">The sender</param>\r
106         /// <param name="e">Unhandled Exception EventArgs </param>\r
107         private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)\r
108         {\r
109             try\r
110             {\r
111                 frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
112                 exceptionWindow.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString());\r
113                 exceptionWindow.ShowDialog();\r
114             }\r
115             catch (Exception)\r
116             {\r
117                 MessageBox.Show(\r
118                     "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject,\r
119                     "Unhandled Exception",\r
120                     MessageBoxButtons.OK,\r
121                     MessageBoxIcon.Error);\r
122             }\r
123         }\r
124 \r
125         public static int InstanceId;\r
126     }\r
127 }