OSDN Git Service

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