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