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