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