diff options
author | sr55 <[email protected]> | 2011-03-13 16:44:49 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-03-13 16:44:49 +0000 |
commit | b6a5d4eba610711d15ed99dc5f2e9e126ce06086 (patch) | |
tree | e72eb5be161c3ac9b01bbc3b3efcd4ab8f91e06c /win/CS/HandBrake.ApplicationServices/Functions | |
parent | 38f64c238720fe0524f99b380fbb1a8c795a7586 (diff) |
Rename Direction C# to CS
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3846 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Functions')
7 files changed, 743 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/Converters.cs b/win/CS/HandBrake.ApplicationServices/Functions/Converters.cs new file mode 100644 index 000000000..1dd817e23 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/Converters.cs @@ -0,0 +1,189 @@ +/* Converters.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using System.Text.RegularExpressions;
+
+ using HandBrake.ApplicationServices.Model.Encoding;
+
+ /// <summary>
+ /// A class to convert various things to native C# objects
+ /// </summary>
+ public class Converters
+ {
+ /**
+ * TODO:
+ * - Many of these converters can be ditched at a later point. Should be able to model all this within the enums themsevles.
+ *
+ **/
+
+ /// <summary>
+ /// Convert HandBrakes time remaining into a TimeSpan
+ /// </summary>
+ /// <param name="time">
+ /// The time remaining for the encode.
+ /// </param>
+ /// <returns>
+ /// A TimepSpan object
+ /// </returns>
+ public static TimeSpan EncodeToTimespan(string time)
+ {
+ TimeSpan converted = new TimeSpan(0, 0, 0, 0);
+
+ Match m = Regex.Match(time.Trim(), @"^([0-9]{2}:[0-9]{2}:[0-9]{2})");
+ if (m.Success)
+ {
+ TimeSpan.TryParse(m.Groups[0].Value, out converted);
+ }
+
+ return converted;
+ }
+
+ /// <summary>
+ /// Get the GUI equiv to a CLI mixdown
+ /// </summary>
+ /// <param name="mixdown">The Audio Mixdown</param>
+ /// <returns>The GUI representation of the mixdown</returns>
+ public static string GetMixDown(string mixdown)
+ {
+ switch (mixdown.Trim())
+ {
+ case "mono":
+ return "Mono";
+ case "stereo":
+ return "Stereo";
+ case "dpl1":
+ return "Dolby Surround";
+ case "dpl2":
+ return "Dolby Pro Logic II";
+ case "6ch":
+ return "6 Channel Discrete";
+ default:
+ return "Automatic";
+ }
+ }
+
+ /// <summary>
+ /// Get the GUI equiv to a CLI audio encoder
+ /// </summary>
+ /// <param name="audioEnc">The Audio Encoder</param>
+ /// <returns>The GUI representation of that audio encoder</returns>
+ public static string GetGUIAudioEncoder(string audioEnc)
+ {
+ switch (audioEnc)
+ {
+ case "faac":
+ return "AAC (faac)";
+ case "lame":
+ return "MP3 (lame)";
+ case "vorbis":
+ return "Vorbis (vorbis)";
+ case "ac3":
+ return "AC3 (ffmpeg)";
+ case "copy:ac3":
+ return "AC3 Passthru";
+ case "copy:dts":
+ return "DTS Passthru";
+ default:
+ return "AAC (faac)";
+ }
+ }
+
+ /// <summary>
+ /// Get the Video Encoder for a given string
+ /// </summary>
+ /// <param name="encoder">
+ /// The encoder name
+ /// </param>
+ /// <returns>
+ /// VideoEncoder enum object
+ /// </returns>
+ public static VideoEncoder GetVideoEncoder(string encoder)
+ {
+ switch (encoder)
+ {
+ case "ffmpeg":
+ return VideoEncoder.FFMpeg;
+ case "x264":
+ return VideoEncoder.X264;
+ case "theora":
+ return VideoEncoder.Theora;
+ default:
+ return VideoEncoder.X264;
+ }
+ }
+
+ /// <summary>
+ /// Get a GUI name for a given video Encoder.
+ /// </summary>
+ /// <param name="encoder">
+ /// A VideoEncoder Enum object
+ /// </param>
+ /// <returns>
+ /// A GUI encoder name, default is x264
+ /// </returns>
+ public static string GetGUIVideoEncoder(VideoEncoder encoder)
+ {
+ switch (encoder)
+ {
+ case VideoEncoder.FFMpeg:
+ return "MPEG-4 (FFmpeg)";
+ case VideoEncoder.X264:
+ return "H.264 (x264)";
+ case VideoEncoder.Theora:
+ return "VP3 (Theora)";
+ default:
+ return "H.264 (x264)";
+ }
+ }
+
+
+ /// <summary>
+ /// Get the OutputFormat Enum for a given string
+ /// </summary>
+ /// <param name="format">
+ /// OutputFormat as a string
+ /// </param>
+ /// <returns>
+ /// An OutputFormat Enum
+ /// </returns>
+ public static OutputFormat GetFileFormat(string format)
+ {
+ switch (format.ToLower())
+ {
+ default:
+ return OutputFormat.Mp4;
+ case "m4v":
+ return OutputFormat.M4V;
+ case "mkv":
+ return OutputFormat.Mkv;
+ }
+ }
+
+ /// <summary>
+ /// Get the OutputFormat Enum for a given string
+ /// </summary>
+ /// <param name="format">
+ /// OutputFormat as a string
+ /// </param>
+ /// <returns>
+ /// An OutputFormat Enum
+ /// </returns>
+ public static string GetFileFormat(OutputFormat format)
+ {
+ switch (format)
+ {
+ default:
+ return "mp4";
+ case OutputFormat.M4V:
+ return "m4v";
+ case OutputFormat.Mkv:
+ return "mkv";
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs new file mode 100644 index 000000000..0bbc746d7 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs @@ -0,0 +1,35 @@ +/* EnumHelper.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using System.ComponentModel;
+ using System.Reflection;
+
+ /// <summary>
+ /// Enum Helpers
+ /// </summary>
+ public class EnumHelper
+ {
+ /// <summary>
+ /// Get the description of an Enum
+ /// </summary>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ /// <returns>
+ /// The Description string
+ /// </returns>
+ public static string GetDescription(Enum value)
+ {
+ FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
+ DescriptionAttribute[] attributes =
+ (DescriptionAttribute[])fieldInfo.GetCustomAttributes(
+ typeof(DescriptionAttribute), false);
+ return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/GrowlCommunicator.cs b/win/CS/HandBrake.ApplicationServices/Functions/GrowlCommunicator.cs new file mode 100644 index 000000000..a28457836 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/GrowlCommunicator.cs @@ -0,0 +1,119 @@ +/* GrowlCommunicator.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+
+ using Growl.Connector;
+
+ /// <summary>
+ /// Provides all functionality for communicating with Growl for Windows.
+ /// </summary>
+ /// <remarks>
+ /// This class is implemented as a static class because:
+ /// 1. It allows nearly all of the Growl-related code to be in one place
+ /// 2. It prevents the main form, queue handler, and any other part of Handbrake from having to declare
+ /// or track any new instance variables
+ /// </remarks>
+ public static class GrowlCommunicator
+ {
+ /// <summary>
+ /// The <see cref="GrowlConnector"/> that actually talks to Growl
+ /// </summary>
+ private static GrowlConnector growl;
+
+ /// <summary>
+ /// The Handbrake application instance that is registered with Growl
+ /// </summary>
+ private static Application application;
+
+ /// <summary>
+ /// Notification shown upon completion of encoding
+ /// </summary>
+ private static NotificationType encodeOrQueueCompleted = new NotificationType("EncodeOrQueue", "HandBrake Status");
+
+ /// <summary>
+ /// Checks to see if Growl is currently running on the local machine.
+ /// </summary>
+ /// <returns>
+ /// <c>true</c> if Growl is running;
+ /// <c>false</c> otherwise
+ /// </returns>
+ public static bool IsRunning()
+ {
+ Initialize();
+
+ return GrowlConnector.IsGrowlRunningLocally();
+ }
+
+ /// <summary>
+ /// Registers Handbrake with the local Growl instance
+ /// </summary>
+ /// <remarks>
+ /// This should usually be called at application start-up
+ /// </remarks>
+ public static void Register()
+ {
+ Initialize();
+ growl.Register(application, new[] {encodeOrQueueCompleted});
+ }
+
+ /// <summary>
+ /// Sends a notification to Growl. (Since Handbrake currently only supports one type of notification with
+ /// static text, this is a shortcut method).
+ /// </summary>
+ /// <param name="title">
+ /// The title.
+ /// </param>
+ /// <param name="text">
+ /// The text to display.
+ /// </param>
+ public static void Notify(string title, string text)
+ {
+ Notification notification = new Notification(application.Name, encodeOrQueueCompleted.Name, String.Empty,
+ title, text);
+ growl.Notify(notification);
+ }
+
+ /// <summary>
+ /// Sends a notification to Growl. (This is the more generic version that could be used in the future if
+ /// more notification types are implemented)
+ /// </summary>
+ /// <param name="notificationType">The <see cref="NotificationType">type</see> of notification to send</param>
+ /// <param name="title">The notification title</param>
+ /// <param name="text">The notification text</param>
+ /// <param name="imageUrl">The notification image as a url</param>
+ public static void Notify(NotificationType notificationType, string title, string text, string imageUrl)
+ {
+ Notification notification = new Notification(application.Name, notificationType.Name, String.Empty, title,
+ text)
+ {
+ Icon = imageUrl
+ };
+
+ growl.Notify(notification);
+ }
+
+ /// <summary>
+ /// Initializes the GrowlCommunicator
+ /// </summary>
+ private static void Initialize()
+ {
+ if (growl == null)
+ {
+ growl = new GrowlConnector
+ {
+ EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText
+ };
+
+ application = new Application("Handbrake")
+ {
+ Icon = Properties.Resources.logo64
+ };
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Functions/PlistHelper.cs b/win/CS/HandBrake.ApplicationServices/Functions/PlistHelper.cs new file mode 100644 index 000000000..fab40a27c --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/PlistHelper.cs @@ -0,0 +1,127 @@ +/* PlistHelper.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Xml;
+
+ /// <summary>
+ /// A Plist Helper
+ /// </summary>
+ public class PlistHelper
+ {
+ /// <summary>
+ /// Get the Audio Track XML Nodes from a plist preset file
+ /// </summary>
+ /// <param name="filename">
+ /// A Plist preset file
+ /// </param>
+ /// <returns>
+ /// A List of XmlNodes which contain audio tracks
+ /// </returns>
+ public static List<XmlNode> GetAudioTracks(string filename)
+ {
+ // Data Store
+ List<XmlNode> audioTracks = new List<XmlNode>();
+
+ // Load the file and get the Root note, or return if none found
+ XmlNode root = LoadFile(filename);
+ if (root == null)
+ {
+ return null;
+ }
+
+ // Get the Audio Tracks
+ XmlNode audioListDict = root.ChildNodes[2].ChildNodes[0].FirstChild.ChildNodes[1];
+ for (int i = 0; i < audioListDict.ChildNodes.Count; i++)
+ {
+ XmlNode audioChannel = audioListDict.ChildNodes[i]; // <dict>
+ audioTracks.Add(audioChannel);
+ }
+
+ return audioTracks;
+ }
+
+ /// <summary>
+ /// Get the settings portion of a presets file
+ /// </summary>
+ /// <param name="filename">
+ /// A Plist preset file
+ /// </param>
+ /// <returns>
+ /// A Dictionary of plist key against an XML node containing the setting.
+ /// </returns>
+ public static Dictionary<string, XmlNode> GetPresetSettings(string filename)
+ {
+ // Data Store
+ Dictionary<string, XmlNode> settings = new Dictionary<string, XmlNode>();
+
+ // Load the file and get the Root note, or return if none found
+ XmlNode root = LoadFile(filename);
+ if (root == null)
+ {
+ return null;
+ }
+
+ // Get the Preset Settings, starting from the 3rd node (skipping the audio notes we've just prcessed)
+ XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;
+ for (int i = 2; i < presetSettings.ChildNodes.Count; i += 2)
+ {
+ string key = presetSettings.ChildNodes[i].InnerText;
+ XmlNode node = presetSettings.ChildNodes[i + 1];
+ settings.Add(key, node);
+ }
+
+ return settings;
+ }
+
+ /// <summary>
+ /// Load a Plist Preset file and return it as an XML document
+ /// </summary>
+ /// <param name="filename">
+ /// A Plist preset file
+ /// </param>
+ /// <returns>
+ /// An XML document
+ /// </returns>
+ private static XmlNode LoadFile(string filename)
+ {
+ try
+ {
+ if (!File.Exists(filename))
+ {
+ return null;
+ }
+
+ StreamReader sr = File.OpenText(filename);
+ string fromfile = string.Empty;
+ int fileChar;
+ while ((fileChar = sr.Read()) != -1)
+ {
+ fromfile += Convert.ToChar(fileChar);
+ }
+
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(fromfile);
+
+ XmlNode root = doc;
+ if (!root.HasChildNodes)
+ {
+ return null;
+ }
+
+ return root;
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/System.cs b/win/CS/HandBrake.ApplicationServices/Functions/System.cs new file mode 100644 index 000000000..9b08a4be2 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/System.cs @@ -0,0 +1,56 @@ +/* System.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System.Windows.Forms;
+
+ using Microsoft.Win32;
+
+ /// <summary>
+ /// The System Information.
+ /// </summary>
+ public class SystemInfo
+ {
+ /// <summary>
+ /// Gets the total physical ram in a system
+ /// </summary>
+ /// <returns>The total memory in the system</returns>
+ public static ulong TotalPhysicalMemory
+ {
+ get
+ {
+ Win32.MEMORYSTATUSEX memStat = new Win32.MEMORYSTATUSEX { dwLength = 64 };
+ Win32.GlobalMemoryStatusEx(ref memStat);
+
+ ulong value = memStat.ullTotalPhys / 1024 / 1024;
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the number of CPU Cores
+ /// </summary>
+ /// <returns>Object</returns>
+ public static object GetCpuCount
+ {
+ get
+ {
+ RegistryKey regKey = Registry.LocalMachine;
+ regKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
+ return regKey == null ? 0 : regKey.GetValue("ProcessorNameString");
+ }
+ }
+
+ /// <summary>
+ /// Gets the System screen size information.
+ /// </summary>
+ /// <returns>System.Windows.Forms.Scree</returns>
+ public static Screen ScreenBounds
+ {
+ get { return Screen.PrimaryScreen; }
+ }
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs b/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs new file mode 100644 index 000000000..8cb464b80 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs @@ -0,0 +1,144 @@ +/* win32.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using System.Runtime.InteropServices;
+
+ /// <summary>
+ /// Win32 API calls
+ /// </summary>
+ public class Win32
+ {
+ /// <summary>
+ /// Set the Forground Window
+ /// </summary>
+ /// <param name="hWnd">
+ /// The h wnd.
+ /// </param>
+ /// <returns>
+ /// A Boolean true when complete.
+ /// </returns>
+ [DllImport("user32.dll")]
+ public static extern bool SetForegroundWindow(int hWnd);
+
+ /// <summary>
+ /// Lock the workstation
+ /// </summary>
+ [DllImport("user32.dll")]
+ public static extern void LockWorkStation();
+
+ /// <summary>
+ /// Exit Windows
+ /// </summary>
+ /// <param name="uFlags">
+ /// The u flags.
+ /// </param>
+ /// <param name="dwReason">
+ /// The dw reason.
+ /// </param>
+ /// <returns>
+ /// an integer
+ /// </returns>
+ [DllImport("user32.dll")]
+ public static extern int ExitWindowsEx(int uFlags, int dwReason);
+
+ /// <summary>
+ /// Memory Status EX Struct
+ /// </summary>
+ public struct MEMORYSTATUSEX
+ {
+ public int dwLength;
+ public int dwMemoryLoad;
+ public ulong ullTotalPhys;
+ public ulong ullAvailPhys;
+ public ulong ullTotalPageFile;
+ public ulong ullAvailPageFile;
+ public ulong ullTotalVirtual;
+ public ulong ullAvailVirtual;
+ public ulong ullAvailExtendedVirtual;
+ }
+
+ /// <summary>
+ /// Get the System Memory information
+ /// </summary>
+ /// <param name="lpBuffer">
+ /// The lp buffer.
+ /// </param>
+ /// <returns>
+ /// A boolean.
+ /// </returns>
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
+
+
+ /// <summary>
+ /// Generate a Console Ctrl Event
+ /// </summary>
+ /// <param name="sigevent">
+ /// The sigevent.
+ /// </param>
+ /// <param name="dwProcessGroupId">
+ /// The dw process group id.
+ /// </param>
+ /// <returns>
+ /// Bool true is sucess
+ /// </returns>
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId);
+
+ /// <summary>
+ /// Console Ctrl Event
+ /// </summary>
+ public enum ConsoleCtrlEvent
+ {
+ /// <summary>
+ /// Ctrl - C
+ /// </summary>
+ CTRL_C = 0,
+
+ /// <summary>
+ /// Ctrl - Break
+ /// </summary>
+ CTRL_BREAK = 1,
+
+ /// <summary>
+ /// Ctrl - Close
+ /// </summary>
+ CTRL_CLOSE = 2,
+ }
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
+
+ /// <summary>
+ /// Execution State
+ /// </summary>
+ [FlagsAttribute]
+ public enum EXECUTION_STATE : uint
+ {
+ ES_SYSTEM_REQUIRED = 0x00000001,
+ ES_CONTINUOUS = 0x80000000,
+ ES_AWAYMODE_REQUIRED = 0x00000040
+ }
+
+ /// <summary>
+ /// Prevent the system from sleeping
+ /// </summary>
+ public static void PreventSleep()
+ {
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
+ }
+
+ /// <summary>
+ /// Allow the system to sleep.
+ /// </summary>
+ public static void AllowSleep()
+ {
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
+ }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/Win7.cs b/win/CS/HandBrake.ApplicationServices/Functions/Win7.cs new file mode 100644 index 000000000..8d694d2f8 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Functions/Win7.cs @@ -0,0 +1,73 @@ +/* Win7.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Functions
+{
+ using System;
+ using Microsoft.WindowsAPICodePack.Taskbar;
+
+ /// <summary>
+ /// A class implimenting Windows 7 Specific features
+ /// </summary>
+ public class Win7
+ {
+ /// <summary>
+ /// The Windows Taskbar
+ /// </summary>
+ private TaskbarManager windowsTaskbar;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Win7"/> class.
+ /// </summary>
+ public Win7()
+ {
+ if (IsWindowsSeven)
+ {
+ windowsTaskbar = TaskbarManager.Instance;
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this is Windows Seven.
+ /// </summary>
+ public bool IsWindowsSeven
+ {
+ get
+ {
+ OperatingSystem os = Environment.OSVersion;
+ return os.Version.Major >= 6 && os.Version.Minor >= 1;
+ }
+ }
+
+ /// <summary>
+ /// Set the Task Bar Percentage.
+ /// </summary>
+ /// <param name="percentage">
+ /// The percentage.
+ /// </param>
+ public void SetTaskBarProgress(int percentage)
+ {
+ if (!IsWindowsSeven)
+ {
+ return;
+ }
+ windowsTaskbar.SetProgressState(TaskbarProgressBarState.Normal);
+ windowsTaskbar.SetProgressValue(percentage, 100);
+ }
+
+ /// <summary>
+ /// Disable Task Bar Progress
+ /// </summary>
+ public void SetTaskBarProgressToNoProgress()
+ {
+ if (!IsWindowsSeven)
+ {
+ return;
+ }
+
+ windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
+ }
+ }
+}
\ No newline at end of file |