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