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     using Presets;\r
12 \r
13     /// <summary>\r
14     /// HandBrake Starts Here\r
15     /// </summary>\r
16     public static class Program\r
17     {\r
18         /// <summary>\r
19         /// The main entry point for the application.\r
20         /// </summary>\r
21         [STAThread]\r
22         public static void Main()\r
23         {\r
24             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);\r
25 \r
26             const string failedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
27             const string nightlyCLIMissing =\r
28                 "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
29                 "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
30             string missingFiles = string.Empty;\r
31 \r
32             // Verify HandBrakeCLI.exe and ilibgcc_s_sjlj-1.dll exists\r
33             if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
34             {\r
35                 missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
36             }\r
37 \r
38             if (missingFiles != string.Empty)\r
39             {\r
40                 MessageBox.Show(\r
41                     failedInstall + missingFiles + "\n\n" + nightlyCLIMissing,\r
42                     "Error",\r
43                     MessageBoxButtons.OK,\r
44                     MessageBoxIcon.Error);\r
45                 return;\r
46             }\r
47 \r
48             // Make sure we have a recent version for svn builds\r
49             string version = Properties.Settings.Default.hb_version;\r
50             if (version.Contains("svn"))\r
51             {\r
52                 version = version.Replace("svn", string.Empty).Trim();\r
53                 int build;\r
54                 int.TryParse(version, out build);\r
55                 if (build < Properties.Settings.Default.hb_min_cli)\r
56                 {\r
57                     MessageBox.Show(\r
58                         "It appears you are trying to use a CLI executable that is too old for this version of the HandBrake GUI.\n" + \r
59                         "Please update the HandBrakeCLI.exe to a newer build. ",\r
60                         "Error",\r
61                         MessageBoxButtons.OK,\r
62                         MessageBoxIcon.Error);\r
63                     return;\r
64                 }\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                 Application.EnableVisualStyles();\r
84                 Application.SetCompatibleTextRenderingDefault(false);\r
85                 Application.Run(new frmMain());\r
86             }\r
87         }\r
88 \r
89         /// <summary>\r
90         /// Throw up an error message for any unhandled exceptions.\r
91         /// </summary>\r
92         /// <param name="sender">The sender</param>\r
93         /// <param name="e">Unhandled Exception EventArgs </param>\r
94         private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)\r
95         {\r
96             MessageBox.Show(\r
97                 "An unexpected error has occured.\n\nSender:" + sender + "\n\nException:" + e.ExceptionObject, \r
98                 "Unhandled Exception",\r
99                 MessageBoxButtons.OK,\r
100                 MessageBoxIcon.Error);\r
101         }\r
102     }\r
103 }