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             if (Settings.Default.UpdateRequired)\r
28             {\r
29                 Settings.Default.Upgrade();\r
30                 Settings.Default.UpdateRequired = false;\r
31             }\r
32 \r
33             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);\r
34 \r
35             const string failedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
36             const string nightlyCLIMissing =\r
37                 "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
38                 "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
39             string missingFiles = string.Empty;\r
40 \r
41             // Verify HandBrakeCLI.exe and ilibgcc_s_sjlj-1.dll exists\r
42             if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
43             {\r
44                 missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
45             }\r
46 \r
47             if (missingFiles != string.Empty)\r
48             {\r
49                 MessageBox.Show(\r
50                     failedInstall + missingFiles + "\n\n" + nightlyCLIMissing,\r
51                     "Error",\r
52                     MessageBoxButtons.OK,\r
53                     MessageBoxIcon.Error);\r
54                 return;\r
55             }\r
56 \r
57             // Check were not running on a screen that's going to cause some funnies to happen.\r
58             Screen scr = Screen.PrimaryScreen;\r
59             if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 620))\r
60                 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
61             else\r
62             {\r
63                 string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");\r
64                 if (!Directory.Exists(logDir))\r
65                     Directory.CreateDirectory(logDir);\r
66 \r
67                 if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))\r
68                 {\r
69                     PresetsHandler x = new PresetsHandler();\r
70                     x.UpdateBuiltInPresets();\r
71                 }\r
72 \r
73                 Application.EnableVisualStyles();\r
74                 Application.SetCompatibleTextRenderingDefault(false);\r
75                 Application.Run(new frmMain());\r
76             }\r
77         }\r
78 \r
79         /// <summary>\r
80         /// Throw up an error message for any unhandled exceptions.\r
81         /// </summary>\r
82         /// <param name="sender">The sender</param>\r
83         /// <param name="e">Unhandled Exception EventArgs </param>\r
84         private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)\r
85         {\r
86             MessageBox.Show(\r
87                 "An unexpected error has occured.\n\nSender:" + sender + "\n\nException:" + e.ExceptionObject, \r
88                 "Unhandled Exception",\r
89                 MessageBoxButtons.OK,\r
90                 MessageBoxIcon.Error);\r
91         }\r
92     }\r
93 }