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(CurrentDomainUnhandledException);\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                 Functions.Main.SetCliVersionData();\r
43             }\r
44 \r
45             // Make sure we have any pre-requesits before trying to launch\r
46             const string FailedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
47             const string NightlyCLIMissing =\r
48                 "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
49                 "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
50             string missingFiles = string.Empty;\r
51 \r
52             // Verify HandBrakeCLI.exe exists\r
53             if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
54             {\r
55                 missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
56             }\r
57 \r
58             if (missingFiles != string.Empty)\r
59             {\r
60                 MessageBox.Show(\r
61                     FailedInstall + missingFiles + "\n\n" + NightlyCLIMissing,\r
62                     "Error",\r
63                     MessageBoxButtons.OK,\r
64                     MessageBoxIcon.Error);\r
65                 return;\r
66             }\r
67 \r
68             // Check were not running on a screen that's going to cause some funnies to happen.\r
69             Screen scr = Screen.PrimaryScreen;\r
70             if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 620))\r
71                 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
72             else\r
73             {\r
74                 string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");\r
75                 if (!Directory.Exists(logDir))\r
76                     Directory.CreateDirectory(logDir);\r
77 \r
78                 if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))\r
79                 {\r
80                     PresetsHandler x = new PresetsHandler();\r
81                     x.UpdateBuiltInPresets();\r
82                 }\r
83 \r
84                 InitializeApplicationServices();\r
85 \r
86                 Application.EnableVisualStyles();\r
87                 Application.SetCompatibleTextRenderingDefault(false);\r
88                 Application.Run(new frmMain(args));\r
89             }\r
90         }\r
91 \r
92         /// <summary>\r
93         /// Initialize App Services\r
94         /// </summary>\r
95         private static void InitializeApplicationServices()\r
96         {\r
97             string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
98             Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
99                                Settings.Default.growlEncode, Settings.Default.growlQueue,\r
100                                Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath,\r
101                                Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep);\r
102         }\r
103 \r
104         /// <summary>\r
105         /// Throw up an error message for any unhandled exceptions.\r
106         /// </summary>\r
107         /// <param name="sender">The sender</param>\r
108         /// <param name="e">Unhandled Exception EventArgs </param>\r
109         private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)\r
110         {\r
111             MessageBox.Show(\r
112                 "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject,\r
113                 "Unhandled Exception",\r
114                 MessageBoxButtons.OK,\r
115                 MessageBoxIcon.Error);\r
116         }\r
117 \r
118         public static int InstanceId;\r
119     }\r
120 }