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
9 using System.Diagnostics;
\r
11 using System.Windows.Forms;
\r
13 using Caliburn.Castle;
\r
15 using Castle.Core.Resource;
\r
16 using Castle.Windsor;
\r
17 using Castle.Windsor.Configuration.Interpreters;
\r
19 using HandBrake.ApplicationServices;
\r
21 using Handbrake.Presets;
\r
22 using Handbrake.Properties;
\r
24 using Microsoft.Practices.ServiceLocation;
\r
27 /// HandBrake Starts Here
\r
29 public static class Program
\r
32 /// The main entry point for the application.
\r
34 /// <param name="args">
\r
38 public static void Main(string[] args)
\r
40 WindsorContainer container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
\r
41 ServiceLocator.SetLocatorProvider(() => new WindsorAdapter(container));
\r
43 InstanceId = Process.GetProcessesByName("HandBrake").Length;
\r
45 // Handle any unhandled exceptions
\r
46 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException);
\r
48 // Attempt to upgrade / keep the users settings between versions
\r
49 if (Settings.Default.UpdateRequired)
\r
51 Settings.Default.Upgrade();
\r
52 Settings.Default.UpdateRequired = false;
\r
53 Functions.Main.SetCliVersionData();
\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
63 // Verify HandBrakeCLI.exe exists
\r
64 if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))
\r
66 missingFiles += "\"HandBrakeCLI.exe\" was not found.";
\r
69 if (missingFiles != string.Empty)
\r
72 FailedInstall + missingFiles + "\n\n" + NightlyCLIMissing,
\r
74 MessageBoxButtons.OK,
\r
75 MessageBoxIcon.Error);
\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
85 string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");
\r
86 if (!Directory.Exists(logDir))
\r
87 Directory.CreateDirectory(logDir);
\r
89 if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))
\r
91 PresetsHandler x = new PresetsHandler();
\r
92 x.UpdateBuiltInPresets();
\r
95 InitializeApplicationServices();
\r
97 Application.EnableVisualStyles();
\r
98 Application.SetCompatibleTextRenderingDefault(false);
\r
99 Application.Run(new frmMain(args));
\r
104 /// Initialize App Services
\r
106 private static void InitializeApplicationServices()
\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
116 /// Throw up an error message for any unhandled exceptions.
\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
123 "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject,
\r
124 "Unhandled Exception",
\r
125 MessageBoxButtons.OK,
\r
126 MessageBoxIcon.Error);
\r
129 public static int InstanceId;
\r