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