OSDN Git Service

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