-using System;\r
-using System.Collections.Generic;\r
-using System.Collections.Specialized;\r
-using System.ComponentModel;\r
-using System.Data;\r
-using System.Drawing;\r
-using System.Text;\r
-using System.Windows.Forms;\r
-using System.Net;\r
-using System.IO;\r
-using System.Diagnostics;\r
-using System.Threading;\r
-using System.Runtime.InteropServices;\r
-\r
+/* Program.cs\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr>.\r
+ It may be used under the terms of the GNU General Public License. */\r
\r
namespace Handbrake\r
{\r
- static class Program\r
+ using System;\r
+ using System.Diagnostics;\r
+ using System.IO;\r
+ using System.Windows.Forms;\r
+\r
+ using HandBrake.ApplicationServices;\r
+\r
+ using Handbrake.Presets;\r
+ using Handbrake.Properties;\r
+\r
+ /// <summary>\r
+ /// HandBrake Starts Here\r
+ /// </summary>\r
+ public static class Program\r
{\r
/// <summary>\r
/// The main entry point for the application.\r
/// </summary>\r
+ /// <param name="args">\r
+ /// The args.\r
+ /// </param>\r
[STAThread]\r
- static void Main()\r
+ public static void Main(string[] args)\r
{\r
- \r
- /* Some Code to allow development builds to expire.\r
- * \r
- * long start = DateTime.Now.Ticks;\r
- * 633286573227430160 today was long end = DateTime.Now.AddDays(31).Ticks;\r
- * if (start > 633286573227430160) { MessageBox.Show("Sorry, this Handbrake has expired"); return; }\r
- * \r
- */\r
-\r
-\r
- // Check the system meets the system requirements.\r
- Boolean launch = true;\r
- try\r
+ InstanceId = Process.GetProcessesByName("HandBrake").Length;\r
+\r
+ // Handle any unhandled exceptions\r
+ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);\r
+\r
+ // Attempt to upgrade / keep the users settings between versions\r
+ if (Settings.Default.UpdateRequired)\r
{\r
- // Make sure the screen resolution is not below 1024x768\r
- System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;\r
- if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 768))\r
- {\r
- MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n Screen resolution is too Low. Must be 1024x768 or greater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- launch = false;\r
- }\r
+ Settings.Default.Upgrade();\r
+ Settings.Default.UpdateRequired = false;\r
+ }\r
\r
- // Make sure the system has enough RAM. 384MB or greater\r
- uint memory = MemoryCheck.CheckMemeory();\r
+ // Make sure we have any pre-requesits before trying to launch\r
+ const string FailedInstall = "HandBrake is not installed properly. Please reinstall HandBrake. \n\n";\r
+ const string NightlyCLIMissing =\r
+ "If you have downloaded the \"HandBrakeGUI\" nightly, " +\r
+ "please make sure you have also downloaded the \"HandBrakeCLI\" nightly and extracted it's contents to the same folder. ";\r
+ string missingFiles = string.Empty;\r
\r
- if (memory < 319) // Set to 319 to allow for 64MB dedicated to video Memory and Windows returnig the memory figure slightly out.\r
- {\r
- MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n Insufficient Memory. 384MB or greater required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- launch = false;\r
- }\r
+ // Verify HandBrakeCLI.exe exists\r
+ if (!File.Exists(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe")))\r
+ {\r
+ missingFiles += "\"HandBrakeCLI.exe\" was not found.";\r
+ }\r
+\r
+ if (missingFiles != string.Empty)\r
+ {\r
+ MessageBox.Show(\r
+ FailedInstall + missingFiles + "\n\n" + NightlyCLIMissing,\r
+ "Error",\r
+ MessageBoxButtons.OK,\r
+ MessageBoxIcon.Error);\r
+ return;\r
}\r
- catch (Exception exc)\r
+\r
+ // Check were not running on a screen that's going to cause some funnies to happen.\r
+ Screen scr = Screen.PrimaryScreen;\r
+ if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 620))\r
+ 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
+ else\r
{\r
- if (Properties.Settings.Default.GuiDebug == "Checked")\r
+ string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\logs");\r
+ if (!Directory.Exists(logDir))\r
+ Directory.CreateDirectory(logDir);\r
+\r
+ if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))\r
{\r
- MessageBox.Show("frmMain.cs - systemCheck() " + exc.ToString());\r
+ PresetsHandler x = new PresetsHandler();\r
+ x.UpdateBuiltInPresets();\r
}\r
- }\r
\r
+ InitializeApplicationServices();\r
\r
- // Either Launch or Close the Application\r
- if (launch == true)\r
- {\r
Application.EnableVisualStyles();\r
Application.SetCompatibleTextRenderingDefault(false);\r
- Application.Run(new frmMain());\r
- }\r
- else\r
- {\r
- Application.Exit();\r
+ Application.Run(new frmMain(args));\r
}\r
}\r
- }\r
\r
- class MemoryCheck\r
- {\r
- public struct MEMORYSTATUS\r
+ /// <summary>\r
+ /// Initialize App Services\r
+ /// </summary>\r
+ private static void InitializeApplicationServices()\r
{\r
- public UInt32 dwLength;\r
- public UInt32 dwMemoryLoad;\r
- public UInt32 dwTotalPhys; // Used\r
- public UInt32 dwAvailPhys;\r
- public UInt32 dwTotalPageFile;\r
- public UInt32 dwAvailPageFile;\r
- public UInt32 dwTotalVirtual;\r
- public UInt32 dwAvailVirtual;\r
- // Aditional Varibles left in for future usage (JIC)\r
+ string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version);\r
+ Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav,\r
+ Settings.Default.growlEncode, Settings.Default.growlQueue,\r
+ Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath,\r
+ Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep);\r
}\r
\r
- [DllImport("kernel32.dll")]\r
- public static extern void GlobalMemoryStatus\r
- (\r
- ref MEMORYSTATUS lpBuffer\r
- );\r
-\r
- public static uint CheckMemeory()\r
+ /// <summary>\r
+ /// Throw up an error message for any unhandled exceptions.\r
+ /// </summary>\r
+ /// <param name="sender">The sender</param>\r
+ /// <param name="e">Unhandled Exception EventArgs </param>\r
+ private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)\r
{\r
- // Call the native GlobalMemoryStatus method\r
- // with the defined structure.\r
- MEMORYSTATUS memStatus = new MEMORYSTATUS();\r
- GlobalMemoryStatus(ref memStatus);\r
-\r
- uint MemoryInfo = memStatus.dwTotalPhys;\r
-\r
- return MemoryInfo;\r
+ try\r
+ {\r
+ frmExceptionWindow exceptionWindow = new frmExceptionWindow();\r
+ exceptionWindow.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString());\r
+ exceptionWindow.ShowDialog();\r
+ }\r
+ catch (Exception)\r
+ {\r
+ MessageBox.Show(\r
+ "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject,\r
+ "Unhandled Exception",\r
+ MessageBoxButtons.OK,\r
+ MessageBoxIcon.Error);\r
+ }\r
}\r
+\r
+ public static int InstanceId;\r
}\r
}
\ No newline at end of file