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/Utilities | |
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/Utilities')
4 files changed, 1329 insertions, 0 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/AppcastReader.cs b/win/CS/HandBrake.ApplicationServices/Utilities/AppcastReader.cs new file mode 100644 index 000000000..8b0053a86 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/AppcastReader.cs @@ -0,0 +1,119 @@ +/* AppcastReader.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.Utilities
+{
+ using System;
+ using System.IO;
+ using System.Text.RegularExpressions;
+ using System.Xml;
+
+ /// <summary>
+ /// Appcast Reader - Used for parsing HandBrakes update file
+ /// </summary>
+ public class AppcastReader
+ {
+ /// <summary>
+ /// Gets Information about an update to HandBrake
+ /// </summary>
+ public Uri DescriptionUrl { get; private set; }
+
+ /// <summary>
+ /// Gets HandBrake's version from the appcast.xml file.
+ /// </summary>
+ public string Version { get; private set; }
+
+ /// <summary>
+ /// Gets HandBrake's Build from the appcast.xml file.
+ /// </summary>
+ public string Build { get; private set; }
+
+ /// <summary>
+ /// Gets the URL for update file.
+ /// </summary>
+ public string DownloadFile { get; private set; }
+
+ /// <summary>
+ /// Get the build information from the required appcasts. Run before accessing the public vars.
+ /// </summary>
+ /// <param name="input">
+ /// The input.
+ /// </param>
+ public void GetUpdateInfo(string input)
+ {
+ try
+ {
+ // Get the correct Appcast and set input.
+ XmlNode nodeItem = ReadRss(new XmlTextReader(new StringReader(input)));
+ string result = nodeItem.InnerXml;
+
+ // Regular Expressions
+ Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\""");
+ Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""(([svn]*)([0-9.\s]*))\""");
+
+ this.Build = ver.ToString().Replace("sparkle:version=", string.Empty).Replace("\"", string.Empty);
+ this.Version = verShort.ToString().Replace("sparkle:shortVersionString=", string.Empty).Replace(
+ "\"", string.Empty);
+ this.DownloadFile = nodeItem["windows"].InnerText;
+ this.DescriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText);
+ }
+ catch (Exception)
+ {
+ return;
+ }
+ }
+
+ /// <summary>
+ /// Read the RSS file.
+ /// </summary>
+ /// <param name="rssReader">
+ /// The RSS reader
+ /// </param>
+ /// <returns>
+ /// The read rss.
+ /// </returns>
+ private static XmlNode ReadRss(XmlReader rssReader)
+ {
+ XmlNode nodeItem = null;
+ XmlNode nodeChannel = null;
+ XmlNode nodeRss = null;
+
+ XmlDocument rssDoc = new XmlDocument();
+ rssDoc.Load(rssReader);
+
+ foreach (XmlNode t in rssDoc.ChildNodes)
+ {
+ if (t.Name == "rss")
+ {
+ nodeRss = t;
+ }
+ }
+
+ if (nodeRss != null)
+ {
+ foreach (XmlNode t in nodeRss.ChildNodes)
+ {
+ if (t.Name == "channel")
+ {
+ nodeChannel = t;
+ }
+ }
+ }
+
+ if (nodeChannel != null)
+ {
+ foreach (XmlNode t in nodeChannel.ChildNodes)
+ {
+ if (t.Name == "item")
+ {
+ nodeItem = t;
+ }
+ }
+ }
+
+ return nodeItem;
+ }
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs new file mode 100644 index 000000000..ee1ab225a --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs @@ -0,0 +1,664 @@ +/* PlistPresetHandler.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.Utilities
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Text;
+ using System.Windows.Forms;
+ using System.Xml;
+
+ using HandBrake.ApplicationServices.Functions;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Model.Encoding;
+
+ /// <summary>
+ /// Plist Preset Converter
+ /// </summary>
+ public class PlistPresetHandler
+ {
+ /**
+ * TODO:
+ * - Update with the new vfr,pfr,cfr keys
+ * - Clean up this code, it's pretty nasty right now.
+ **/
+
+ #region Import
+
+ public static EncodeTask Import(string filename)
+ {
+ XmlNode root = loadFile(filename);
+ if (root == null) return null;
+
+ // We'll query a query parser object and use it's public var structures to store all the data.
+ // This will allow the preset loader logic to be used instead of writing custom logic just for this file.
+ EncodeTask parsed = new EncodeTask();
+ string qualityMode = string.Empty;
+
+ #region Get a List of Audio Track Objects
+ XmlNode audioListDict = root.ChildNodes[2].ChildNodes[0].FirstChild.ChildNodes[1];
+ List<AudioTrack> audioTracks = new List<AudioTrack>();
+
+ for (int i = 0; i < audioListDict.ChildNodes.Count; i++)
+ {
+ XmlNode audioChannel = audioListDict.ChildNodes[i];
+ AudioTrack track = new AudioTrack();
+
+ for (int subi = 0; subi < audioChannel.ChildNodes.Count; subi += 2)
+ {
+ // Audio Channel Information is here.
+ string key = audioChannel.ChildNodes[subi].InnerText;
+ string value = audioChannel.ChildNodes[subi + 1].InnerText;
+ switch (key)
+ {
+ case "AudioBitrate":
+ track.Bitrate = value;
+ break;
+ case "AudioEncoder":
+ track.Encoder = value.Replace("AAC (CoreAudio)", "AAC (faac)");
+ break;
+ case "AudioMixdown":
+ track.MixDown = value;
+ break;
+ case "AudioSamplerate":
+ track.SampleRate = value;
+ break;
+ case "AudioTrack":
+ track.Track = value;
+ break;
+ case "AudioTrackDRCSlider":
+ track.DRC = value;
+ break;
+ }
+ }
+ audioTracks.Add(track);
+ parsed.AudioTracks = audioTracks;
+ }
+ #endregion
+
+ #region Parse the reset of the plist keys into local variables
+
+ XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;
+
+ // Start from 2 to avoid the audio settings which we don't need.
+ for (int i = 2; i < presetSettings.ChildNodes.Count; i += 2)
+ {
+ string key = presetSettings.ChildNodes[i].InnerText;
+ string value = presetSettings.ChildNodes[i + 1].InnerText;
+
+ switch (key)
+ {
+ // Output Settings
+ case "FileFormat":
+ parsed.OutputFormat = Converters.GetFileFormat(value);
+ break;
+ case "Mp4HttpOptimize":
+ parsed.OptimizeMP4 = value == "1";
+ break;
+ case "Mp4LargeFile":
+ parsed.IPod5GSupport = value == "1";
+ break;
+ case "Mp4iPodCompatible":
+ parsed.IPod5GSupport = value == "1";
+ break;
+
+ // Picture Settings
+ case "PictureAutoCrop":
+ // Not used
+ break;
+ case "PictureTopCrop":
+ parsed.Cropping.Top = int.Parse(value);
+ break;
+ case "PictureBottomCrop":
+ parsed.Cropping.Bottom = int.Parse(value);
+ break;
+ case "PictureLeftCrop":
+ parsed.Cropping.Left = int.Parse(value);
+ break;
+ case "PictureRightCrop":
+ parsed.Cropping.Right = int.Parse(value);
+ break;
+ case "PictureHeight":
+ parsed.Height = int.Parse(value);
+ break;
+ case "PictureWidth":
+ parsed.Width = int.Parse(value);
+ break;
+ case "PictureKeepRatio":
+ parsed.KeepDisplayAspect = value == "1";
+ break;
+ case "PicturePAR":
+ switch (value)
+ {
+
+ case "0":
+ parsed.Anamorphic = Anamorphic.None;
+ break;
+ default:
+ parsed.Anamorphic = Anamorphic.Strict;
+ break;
+ case "2":
+ parsed.Anamorphic = Anamorphic.Loose;
+ break;
+ case "3":
+ parsed.Anamorphic = Anamorphic.Custom;
+ break;
+
+ }
+ break;
+
+ // Filters
+ case "PictureDeblock":
+ parsed.Deblock = int.Parse(value);
+ break;
+ case "PictureDecomb":
+ parsed.Decomb = Decomb.Off;
+ // Don't place custom here as it's handled in the filter panel
+ if (value == "2") parsed.Decomb = Decomb.Default;
+ break;
+ case "PictureDecombCustom":
+ if (value != string.Empty)
+ parsed.CustomDecomb = value;
+ break;
+ case "PictureDecombDeinterlace":
+ // Not Used
+ break;
+ case "PictureDeinterlace":
+ switch (value)
+ {
+ case "0":
+ parsed.Deinterlace = Deinterlace.Off;
+ break;
+ // Don't place custom here as it's handled in the filter panel
+ case "2":
+ parsed.Deinterlace = Deinterlace.Fast;
+ break;
+ case "3":
+ parsed.Deinterlace = Deinterlace.Slow;
+ break;
+ case "4":
+ parsed.Deinterlace = Deinterlace.Slower;
+ break;
+ }
+ break;
+ case "PictureDeinterlaceCustom":
+ if (value != string.Empty)
+ parsed.CustomDeinterlace = value;
+ break;
+ case "PictureDenoise":
+ switch (value)
+ {
+ case "0":
+ parsed.Denoise = Denoise.Off;
+ break;
+ // Don't place custom here as it's handled in the filter panel
+ case "2":
+ parsed.Denoise = Denoise.Weak;
+ break;
+ case "3":
+ parsed.Denoise = Denoise.Medium;
+ break;
+ case "4":
+ parsed.Denoise = Denoise.Strong;
+ break;
+ }
+
+ break;
+ case "PictureDenoiseCustom":
+ if (value != string.Empty)
+ parsed.CustomDenoise = value;
+ break;
+ case "PictureDetelecine":
+ parsed.Detelecine = Detelecine.Off;
+ if (value == "1") parsed.Detelecine = Detelecine.Default;
+ break;
+ case "PictureDetelecineCustom":
+ if (value != string.Empty)
+ parsed.CustomDetelecine = value;
+ break;
+
+ // Video Tab
+ case "VideoAvgBitrate":
+ parsed.VideoBitrate = int.Parse(value);
+ break;
+ case "VideoEncoder":
+ parsed.VideoEncoder = Converters.GetVideoEncoder(value);
+ break;
+ case "VideoFramerate":
+ parsed.Framerate = int.Parse(value);
+ break;
+ case "VideoGrayScale":
+ parsed.Grayscale = value == "1";
+ break;
+ case "VideoQualitySlider":
+ parsed.Quality = double.Parse(value);
+ break;
+ case "VideoQualityType": // The Type of Quality Mode used
+ qualityMode = value;
+ break;
+ case "VideoTurboTwoPass":
+ parsed.TurboFirstPass = value == "1";
+ break;
+ case "VideoTwoPass":
+ parsed.TwoPass = value == "1";
+ break;
+
+ // Chapter Markers Tab
+ case "ChapterMarkers":
+ parsed.IncludeChapterMarkers = value == "1";
+ break;
+
+ // Advanced x264 tab
+ case "x264Option":
+ parsed.AdvancedEncoderOptions = value;
+ break;
+
+ // Preset Information
+ case "PresetBuildNumber":
+ parsed.PresetBuildNumber = int.Parse(value);
+ break;
+ case "PresetDescription":
+ parsed.PresetDescription = value;
+ break;
+ case "PresetName":
+ parsed.PresetName = value;
+ break;
+ case "Type":
+ parsed.Type = value;
+ break;
+ case "UsesMaxPictureSettings":
+ parsed.UsesMaxPictureSettings = value == "1";
+ break;
+ case "UsesPictureFilters":
+ parsed.UsesPictureFilters = value == "1";
+ break;
+ case "UsesPictureSettings":
+ parsed.UsesPictureSettings = value == "1";
+ break;
+ }
+ }
+
+ // Kill any Quality values we don't need.
+ switch (qualityMode)
+ {
+ case "0": // FileSize
+ parsed.Quality = null;
+ parsed.VideoBitrate = null;
+ break;
+ case "1": // Avg Bitrate
+ parsed.Quality = null;
+ break;
+ case "2": // CQ
+ parsed.VideoBitrate = null;
+ break;
+ }
+ #endregion
+
+ return parsed;
+ }
+
+ private static XmlNode loadFile(string filename)
+ {
+ try
+ {
+ XmlNode root;
+
+ 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);
+
+ root = doc;
+ if (!root.HasChildNodes)
+ {
+ MessageBox.Show(
+ "The Preset file you selected appears to be invlaid or from an older version of HandBrake",
+ "Error",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return null;
+ }
+
+ return root;
+ }
+ catch (Exception)
+ {
+ MessageBox.Show(
+ "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.",
+ "Error",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return null;
+ }
+ }
+ #endregion
+
+ #region Export
+
+ /// <summary>
+ /// Export a MacGui style plist preset.
+ /// </summary>
+ /// <param name="path">
+ /// The path.
+ /// </param>
+ /// <param name="preset">
+ /// The preset.
+ /// </param>
+ public static void Export(string path, Preset preset)
+ {
+ EncodeTask parsed = QueryParserUtility.Parse(preset.Query);
+ XmlTextWriter xmlWriter = new XmlTextWriter(path, Encoding.UTF8) { Formatting = Formatting.Indented };
+
+ // Header
+ xmlWriter.WriteStartDocument();
+ xmlWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN",
+ @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
+
+ xmlWriter.WriteStartElement("plist");
+ xmlWriter.WriteStartElement("array");
+
+ // Add New Preset Here. Can write multiple presets here if required in future.
+ WritePreset(xmlWriter, parsed, preset);
+
+ // Footer
+ xmlWriter.WriteEndElement();
+ xmlWriter.WriteEndElement();
+
+ xmlWriter.WriteEndDocument();
+
+ // Closeout
+ xmlWriter.Close();
+ }
+
+ /// <summary>
+ /// Write the Preset to a file
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="parsed">
+ /// The parsed.
+ /// </param>
+ /// <param name="preset">
+ /// The preset.
+ /// </param>
+ private static void WritePreset(XmlTextWriter xmlWriter, EncodeTask parsed, Preset preset)
+ {
+ xmlWriter.WriteStartElement("dict");
+ AudioListArrayDict(xmlWriter, parsed);
+ AddEncodeSettings(xmlWriter, parsed, preset);
+
+ xmlWriter.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Add the encode settings to the preset
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="parsed">
+ /// The parsed.
+ /// </param>
+ /// <param name="preset">
+ /// The preset.
+ /// </param>
+ private static void AddEncodeSettings(XmlTextWriter xmlWriter, EncodeTask parsed, Preset preset)
+ {
+ AddEncodeElement(xmlWriter, "ChapterMarkers", "integer", parsed.IncludeChapterMarkers ? "1" : "0");
+ AddEncodeElement(xmlWriter, "Default", "integer", "0");
+ AddEncodeElement(xmlWriter, "FileFormat", "string", Converters.GetFileFormat(parsed.OutputFormat) + " file");
+ AddBooleanElement(xmlWriter, "Folder", false);
+ AddEncodeElement(xmlWriter, "Mp4HttpOptimize", "integer", parsed.OptimizeMP4 ? "1" : "0");
+ AddEncodeElement(xmlWriter, "Mp4LargeFile", "integer", parsed.LargeFile ? "1" : "0");
+ AddEncodeElement(xmlWriter, "Mp4iPodCompatible", "integer", parsed.IPod5GSupport ? "1" : "0");
+ AddEncodeElement(xmlWriter, "PictureAutoCrop", "integer", "1");
+ AddEncodeElement(xmlWriter, "PictureBottomCrop", "integer", parsed.Cropping.Bottom.ToString());
+
+ // Filters
+ AddEncodeElement(xmlWriter, "PictureDeblock", "integer", parsed.Deblock.ToString());
+
+ switch (parsed.Decomb)
+ {
+ case Decomb.Off:
+ AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "0");
+ AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", string.Empty);
+ break;
+ case Decomb.Default:
+ AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "1");
+ AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", string.Empty);
+ break;
+ default:
+ AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "2");
+ AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", parsed.CustomDecomb);
+ break;
+ }
+ AddEncodeElement(xmlWriter, "PictureDecombDeinterlace", "integer", parsed.Decomb != Decomb.Off ? "0" : "1");
+
+ switch (parsed.Deinterlace)
+ {
+ case Deinterlace.Off:
+ AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "0");
+ AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
+ break;
+ case Deinterlace.Fast:
+ AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "1");
+ AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
+ break;
+ case Deinterlace.Slow:
+ AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "2");
+ AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
+ break;
+ case Deinterlace.Slower:
+ AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "3");
+ AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
+ break;
+ default:
+ AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "4");
+ AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", parsed.CustomDeinterlace);
+ break;
+ }
+
+ switch (parsed.Denoise)
+ {
+ case Denoise.Off:
+ AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "0");
+ AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
+ break;
+ case Denoise.Weak:
+ AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "1");
+ AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
+ break;
+ case Denoise.Medium:
+ AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "2");
+ AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
+ break;
+ case Denoise.Strong:
+ AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "3");
+ AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
+ break;
+ default:
+ AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "4");
+ AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", parsed.CustomDenoise);
+ break;
+ }
+
+ int detelecine;
+ switch (parsed.Detelecine)
+ {
+ case Detelecine.Off:
+ detelecine = 0;
+ break;
+ case Detelecine.Default:
+ detelecine = 2;
+ break;
+ default:
+ detelecine = 1;
+ break;
+ }
+
+ AddEncodeElement(xmlWriter, "PictureDetelecine", "integer", detelecine.ToString());
+ AddEncodeElement(xmlWriter, "PictureDetelecineCustom", "string", detelecine == 1 ? parsed.CustomDecomb : string.Empty);
+
+ // Picture Settings
+ AddEncodeElement(xmlWriter, "PictureHeight", "integer", parsed.Height.ToString());
+ AddEncodeElement(xmlWriter, "PictureKeepRatio", "integer", parsed.KeepDisplayAspect ? "1" : "0");
+ AddEncodeElement(xmlWriter, "PictureLeftCrop", "integer", parsed.Cropping.Left.ToString());
+ AddEncodeElement(xmlWriter, "PictureModulus", "integer", parsed.Modulus.ToString());
+ AddEncodeElement(xmlWriter, "PicturePAR", "integer", ((int)parsed.Anamorphic).ToString());
+ AddEncodeElement(xmlWriter, "PictureRightCrop", "integer", parsed.Cropping.Right.ToString());
+ AddEncodeElement(xmlWriter, "PictureTopCrop", "integer", parsed.Cropping.Top.ToString());
+ AddEncodeElement(xmlWriter, "PictureWidth", "integer", parsed.Width.ToString());
+
+ // Preset Information
+ AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", Init.Build.ToString());
+ AddEncodeElement(xmlWriter, "PresetDescription", "string", "No Description");
+ AddEncodeElement(xmlWriter, "PresetName", "string", preset.Name);
+ AddEncodeElement(xmlWriter, "Type", "integer", "1"); // 1 is user preset, 0 is built in
+
+ // Preset Settings
+ AddEncodeElement(xmlWriter, "UsesMaxPictureSettings", "integer", (parsed.MaxWidth != 0 || parsed.MaxHeight != 0) ? "1" : "0");
+ AddEncodeElement(xmlWriter, "UsesPictureFilters", "integer", "1");
+ AddEncodeElement(xmlWriter, "UsesPictureSettings", "integer", "2");
+
+ // Video Settings
+ AddEncodeElement(xmlWriter, "VideoAvgBitrate", "string", parsed.VideoBitrate.ToString());
+ AddEncodeElement(xmlWriter, "VideoEncoder", "string", Converters.GetGUIVideoEncoder(parsed.VideoEncoder));
+ AddEncodeElement(xmlWriter, "VideoFramerate", "string", parsed.Framerate.ToString());
+ AddEncodeElement(xmlWriter, "VideFrameratePFR", "integer", parsed.FramerateMode == FramerateMode.PFR ? "1" : "0");
+ AddEncodeElement(xmlWriter, "VideoGrayScale", "integer", parsed.Grayscale ? "1" : "0");
+ AddEncodeElement(xmlWriter, "VideoQualitySlider", "real", parsed.Quality.ToString());
+
+ int videoQualityType = 0;
+ if (parsed.VideoBitrate != null) videoQualityType = 1;
+ else if (parsed.Quality != null) videoQualityType = 2;
+
+ AddEncodeElement(xmlWriter, "VideoQualityType", "integer", videoQualityType.ToString());
+ AddEncodeElement(xmlWriter, "VideoTargetSize", "string", string.Empty);
+ AddEncodeElement(xmlWriter, "VideoTurboTwoPass", "integer", parsed.TurboFirstPass ? "1" : "0");
+ AddEncodeElement(xmlWriter, "VideoTwoPass", "integer", parsed.TwoPass ? "1" : "0");
+
+ // x264 string
+ AddEncodeElement(xmlWriter, "x264Option", "string", parsed.AdvancedEncoderOptions);
+ }
+
+ /// <summary>
+ /// Add a boolean element
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="keyName">
+ /// The key name.
+ /// </param>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ private static void AddBooleanElement(XmlTextWriter xmlWriter, string keyName, bool value)
+ {
+ xmlWriter.WriteStartElement("key");
+ xmlWriter.WriteString(keyName);
+ xmlWriter.WriteEndElement();
+ xmlWriter.WriteStartElement(value ? "true" : "false");
+ xmlWriter.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Add an encode setting element
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="keyName">
+ /// The key name.
+ /// </param>
+ /// <param name="type">
+ /// The type.
+ /// </param>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ private static void AddEncodeElement(XmlTextWriter xmlWriter, string keyName, string type, string value)
+ {
+ xmlWriter.WriteElementString("key", keyName);
+
+ // This is a hack for Apples XML parser. It doesn't understand <integer /> so instead, always set a default value
+ // of 0 if the value is empty.
+ if (type == "integer" && string.IsNullOrEmpty(value))
+ {
+ value = "0";
+ }
+ xmlWriter.WriteElementString(type, value);
+ }
+
+ /// <summary>
+ /// Add an Audio Track Array Dict
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="parsed">
+ /// The parsed.
+ /// </param>
+ private static void AudioListArrayDict(XmlTextWriter xmlWriter, EncodeTask parsed)
+ {
+ xmlWriter.WriteStartElement("key");
+ xmlWriter.WriteString("AudioList");
+ xmlWriter.WriteEndElement();
+
+ xmlWriter.WriteStartElement("array");
+ foreach (AudioTrack track in parsed.AudioTracks)
+ {
+ AddAudioItem(xmlWriter, track);
+ }
+ xmlWriter.WriteEndElement();
+ }
+
+ /// <summary>
+ /// Add an audio track
+ /// </summary>
+ /// <param name="xmlWriter">
+ /// The xml writer.
+ /// </param>
+ /// <param name="audioTrack">
+ /// The audio track.
+ /// </param>
+ private static void AddAudioItem(XmlTextWriter xmlWriter, AudioTrack audioTrack)
+ {
+ xmlWriter.WriteStartElement("dict");
+
+ xmlWriter.WriteElementString("key", "AudioBitrate");
+ xmlWriter.WriteElementString("string", audioTrack.Bitrate);
+
+ xmlWriter.WriteElementString("key", "AudioEncoder");
+ xmlWriter.WriteElementString("string", audioTrack.Encoder);
+
+ xmlWriter.WriteElementString("key", "AudioMixdown");
+ xmlWriter.WriteElementString("string", audioTrack.MixDown);
+
+ xmlWriter.WriteElementString("key", "AudioSamplerate");
+ xmlWriter.WriteElementString("string", audioTrack.SampleRate);
+
+ xmlWriter.WriteElementString("key", "AudioTrack");
+ xmlWriter.WriteElementString("integer", audioTrack.Track);
+
+ xmlWriter.WriteElementString("key", "AudioTrackDRCSlider");
+ xmlWriter.WriteElementString("real", audioTrack.DRC);
+
+ xmlWriter.WriteElementString("key", "AudioTrackDescription");
+ xmlWriter.WriteElementString("string", "Unknown");
+
+ xmlWriter.WriteEndElement();
+ }
+ #endregion
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs new file mode 100644 index 000000000..ab90cf010 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs @@ -0,0 +1,415 @@ +/* QueryParser.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.Utilities
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Text.RegularExpressions;
+
+ using HandBrake.ApplicationServices.Functions;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Model.Encoding;
+
+ /// <summary>
+ /// Parse a CLI Query
+ /// </summary>
+ public class QueryParserUtility
+ {
+
+ /**
+ * TODO
+ * - Add support for PointToPointMode = Seconds or Frames
+ **/
+
+ /// <summary>
+ /// The Culture
+ /// </summary>
+ private static readonly CultureInfo Culture = new CultureInfo("en-US", false);
+
+ /// <summary>
+ /// Takes in a query which can be in any order and parses it.
+ /// All varibles are then set so they can be used elsewhere.
+ /// </summary>
+ /// <param name="input">A ClI Query</param>
+ /// <returns>A Parsed Query</returns>
+ public static EncodeTask Parse(string input)
+ {
+ var parsed = new EncodeTask();
+
+ #region Regular Expressions
+
+ // Source
+ Match title = Regex.Match(input, @"-t ([0-9]*)");
+ Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
+
+ // Output Settings
+ Match format = Regex.Match(input, @"-f ([a-zA-Z0-9]*)");
+ Match grayscale = Regex.Match(input, @" -g");
+ Match largerMp4 = Regex.Match(input, @" -4");
+ Match ipodAtom = Regex.Match(input, @" -I");
+
+ // Picture Settings Tab
+ Match width = Regex.Match(input, @"-w ([0-9]*)");
+ Match height = Regex.Match(input, @"-l ([0-9]*)");
+ Match maxWidth = Regex.Match(input, @"-X ([0-9]*)");
+ Match maxHeight = Regex.Match(input, @"-Y ([0-9]*)");
+ Match crop = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");
+
+ Match looseAnamorphic = Regex.Match(input, @"--loose-anamorphic");
+ Match strictAnamorphic = Regex.Match(input, @"--strict-anamorphic");
+ Match customAnamorphic = Regex.Match(input, @"--custom-anamorphic");
+
+ Match keepDisplayAsect = Regex.Match(input, @"--keep-display-aspect");
+ Match displayWidth = Regex.Match(input, @"--display-width ([0-9]*)");
+ Match pixelAspect = Regex.Match(input, @"--pixel-aspect ([0-9]*):([0-9]*)");
+ Match modulus = Regex.Match(input, @"--modulus ([0-9]*)");
+
+ // Picture Settings - Filters
+ Match decomb = Regex.Match(input, @" --decomb");
+ Match decombValue = Regex.Match(input, @" --decomb=\""([a-zA-Z0-9.:]*)\""");
+ Match deinterlace = Regex.Match(input, @"--deinterlace=\""([a-zA-Z0-9.:]*)\""");
+ Match denoise = Regex.Match(input, @"--denoise=\""([a-zA-Z0-9.:]*)\""");
+ Match deblock = Regex.Match(input, @"--deblock=([0-9:]*)");
+ Match detelecine = Regex.Match(input, @"--detelecine");
+ Match detelecineValue = Regex.Match(input, @" --detelecine=\""([a-zA-Z0-9.:]*)\""");
+
+ // Video Settings Tab
+ Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
+ Match videoFramerate = Regex.Match(input, @"-r ([0-9.]*)");
+ Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
+ Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
+ Match twoPass = Regex.Match(input, @" -2");
+ Match turboFirstPass = Regex.Match(input, @" -T");
+ Match optimizeMP4 = Regex.Match(input, @" -O");
+ Match pfr = Regex.Match(input, @" --pfr");
+ Match vfr = Regex.Match(input, @" --vfr");
+ Match cfr = Regex.Match(input, @" --cfr");
+
+ // Audio Settings Tab
+ Match noAudio = Regex.Match(input, @"-a none");
+ Match audioTracks = Regex.Match(input, @"-a ([0-9,]*)");
+ Match audioTrackMixes = Regex.Match(input, @"-6 ([0-9a-zA-Z,]*)");
+ Match audioEncoders = Regex.Match(input, @"-E ([a-zA-Z0-9+,:]*)");
+ Match audioBitrates = Regex.Match(input, @"-B ([0-9a-zA-Z,]*)"); // Auto = a-z
+ Match audioSampleRates = Regex.Match(input, @"-R ([0-9a-zA-Z.,]*)"); // Auto = a-z
+ Match drcValues = Regex.Match(input, @"-D ([0-9.,]*)");
+
+ // Chapters Tab
+ Match chapterMarkers = Regex.Match(input, @" -m");
+ Match chapterMarkersFileMode = Regex.Match(input, @"--markers");
+
+ // Advanced Tab
+ Match advanced = Regex.Match(input, @"-x ([.,/a-zA-Z0-9=:-]*)");
+
+ #endregion
+
+ #region Set Varibles
+
+ try
+ {
+ #region Source Tab
+
+ if (title.Success)
+ {
+ parsed.Title = int.Parse(title.ToString().Replace("-t ", string.Empty));
+ }
+
+ if (chapters.Success)
+ {
+ parsed.PointToPointMode = PointToPointMode.Chapters;
+ string[] actTitles = chapters.ToString().Replace("-c ", string.Empty).Split('-');
+ parsed.StartPoint = int.Parse(actTitles[0]);
+ if (actTitles.Length > 1)
+ {
+ parsed.EndPoint = int.Parse(actTitles[1]);
+ }
+
+ if ((parsed.StartPoint == 1) && (parsed.EndPoint == 0))
+ {
+ parsed.EndPoint = parsed.StartPoint;
+ }
+ }
+
+ #endregion
+
+ #region Output Settings
+
+ if (format.Success)
+ {
+ parsed.OutputFormat = Converters.GetFileFormat(format.Groups[1].ToString());
+ }
+ parsed.LargeFile = largerMp4.Success;
+ parsed.IPod5GSupport = ipodAtom.Success;
+ parsed.OptimizeMP4 = optimizeMP4.Success;
+
+ #endregion
+
+ #region Picture Tab
+
+ if (width.Success)
+ parsed.Width = int.Parse(width.Groups[0].Value.Replace("-w ", string.Empty));
+
+ if (height.Success)
+ parsed.Height = int.Parse(height.Groups[0].Value.Replace("-l ", string.Empty));
+
+ if (maxWidth.Success)
+ parsed.MaxWidth = int.Parse(maxWidth.Groups[0].Value.Replace("-X ", string.Empty));
+
+ if (maxHeight.Success)
+ parsed.MaxHeight = int.Parse(maxHeight.Groups[0].Value.Replace("-Y ", string.Empty));
+
+ if (crop.Success)
+ {
+ try
+ {
+ string values = crop.ToString().Replace("--crop ", string.Empty);
+ string[] actCropValues = values.Split(':');
+ parsed.Cropping = new Cropping(
+ int.Parse(actCropValues[0]),
+ int.Parse(actCropValues[1]),
+ int.Parse(actCropValues[2]),
+ int.Parse(actCropValues[3]));
+ }
+ catch (Exception)
+ {
+ // No need to do anything.
+ }
+ }
+
+ if (strictAnamorphic.Success)
+ parsed.Anamorphic = Anamorphic.Strict;
+ else if (looseAnamorphic.Success)
+ parsed.Anamorphic = Anamorphic.Loose;
+ else if (customAnamorphic.Success)
+ parsed.Anamorphic = Anamorphic.Custom;
+ else
+ parsed.Anamorphic = Anamorphic.None;
+
+ parsed.KeepDisplayAspect = keepDisplayAsect.Success;
+
+ if (displayWidth.Success)
+ parsed.DisplayWidth =
+ double.Parse(displayWidth.Groups[0].Value.Replace("--display-width ", string.Empty));
+
+ if (pixelAspect.Success)
+ parsed.PixelAspectX = int.Parse(pixelAspect.Groups[1].Value.Replace("--pixel-aspect ", string.Empty));
+
+ if (pixelAspect.Success && pixelAspect.Groups.Count >= 3)
+ parsed.PixelAspectY = int.Parse(pixelAspect.Groups[2].Value.Replace("--pixel-aspect ", string.Empty));
+
+ if (modulus.Success)
+ parsed.Modulus = int.Parse(modulus.Groups[0].Value.Replace("--modulus ", string.Empty));
+
+ #endregion
+
+ #region Filters
+
+ parsed.Decomb = Decomb.Off;
+ if (decomb.Success)
+ {
+ parsed.Decomb = Decomb.Default;
+ if (decombValue.Success)
+ {
+ parsed.CustomDecomb = decombValue.ToString().Replace("--decomb=", string.Empty).Replace("\"", string.Empty);
+ }
+ }
+
+ parsed.Deinterlace = Deinterlace.Off;
+ if (deinterlace.Success)
+ {
+ switch (deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower())
+ {
+ case "fast":
+ parsed.Deinterlace = Deinterlace.Fast;
+ break;
+ case "slow":
+ parsed.Deinterlace = Deinterlace.Slow;
+ break;
+ case "slower":
+ parsed.Deinterlace = Deinterlace.Slower;
+ break;
+ case "slowest":
+ parsed.Deinterlace = Deinterlace.Slowest;
+ break;
+ default:
+ parsed.Deinterlace = Deinterlace.Custom;
+ parsed.CustomDeinterlace = deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower();
+ break;
+ }
+ }
+
+ parsed.Denoise = Denoise.Off;
+ if (denoise.Success)
+ {
+ switch (denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty))
+ {
+ case "weak":
+ parsed.Denoise = Denoise.Weak;
+ break;
+ case "medium":
+ parsed.Denoise = Denoise.Medium;
+ break;
+ case "strong":
+ parsed.Denoise = Denoise.Strong;
+ break;
+ default:
+ parsed.Denoise = Denoise.Custom;
+ parsed.CustomDenoise = denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty);
+ break;
+ }
+ }
+
+ parsed.Deblock = 0;
+ if (deblock.Success)
+ {
+ int dval;
+ int.TryParse(deblock.ToString().Replace("--deblock=", string.Empty), out dval);
+ parsed.Deblock = dval;
+ }
+
+ parsed.Detelecine = Detelecine.Off;
+ if (detelecine.Success)
+ {
+ parsed.Detelecine = Detelecine.Default;
+ if (detelecineValue.Success)
+ {
+ parsed.CustomDetelecine = detelecineValue.ToString().Replace("--detelecine=", string.Empty).Replace("\"", string.Empty);
+ parsed.Detelecine = Detelecine.Custom;
+ }
+ }
+
+ #endregion
+
+ #region Video Settings Tab
+
+ parsed.VideoEncoder = Converters.GetVideoEncoder(videoEncoder.ToString().Replace("-e ", string.Empty));
+
+ if (videoFramerate.Success)
+ {
+ double fps;
+ double.TryParse(videoFramerate.Groups[1].ToString(), out fps);
+ parsed.Framerate = fps;
+ }
+
+ if (pfr.Success)
+ parsed.FramerateMode = FramerateMode.PFR;
+ else if (cfr.Success)
+ parsed.FramerateMode = FramerateMode.CFR;
+ else
+ parsed.FramerateMode = FramerateMode.VFR; // Default to VFR
+
+ parsed.Grayscale = grayscale.Success;
+ parsed.TwoPass = twoPass.Success;
+ parsed.TurboFirstPass = turboFirstPass.Success;
+
+ if (videoBitrate.Success)
+ {
+ parsed.VideoEncodeRateType = VideoEncodeRateMode.AverageBitrate;
+ parsed.VideoBitrate = int.Parse(videoBitrate.ToString().Replace("-b ", string.Empty));
+ }
+
+ if (videoQuality.Success)
+ {
+ float quality = float.Parse(videoQuality.ToString().Replace("-q ", string.Empty), Culture);
+ parsed.Quality = quality;
+ }
+
+ #endregion
+
+ #region Audio Tab
+
+ // Find out how many tracks we need to add by checking how many encoders or audio tracks are selected.
+ int encoderCount = 0;
+ if (audioEncoders.Success)
+ {
+ string[] audioDataCounters = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
+ encoderCount = audioDataCounters.Length;
+ }
+
+ // Get the data from the regular expression results
+ string[] trackData = null;
+ string[] trackMixes = null;
+ string[] trackEncoders = null;
+ string[] trackBitrates = null;
+ string[] trackSamplerates = null;
+ string[] trackDRCvalues = null;
+
+ if (audioTracks.Success)
+ trackData = audioTracks.ToString().Replace("-a ", string.Empty).Split(',');
+ if (audioTrackMixes.Success)
+ trackMixes = audioTrackMixes.ToString().Replace("-6 ", string.Empty).Split(',');
+ if (audioEncoders.Success)
+ trackEncoders = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
+ if (audioBitrates.Success)
+ trackBitrates = audioBitrates.ToString().Replace("-B ", string.Empty).Split(',');
+ if (audioSampleRates.Success)
+ trackSamplerates = audioSampleRates.ToString().Replace("-R ", string.Empty).Split(',');
+ if (drcValues.Success)
+ trackDRCvalues = drcValues.ToString().Replace("-D ", string.Empty).Split(',');
+
+ // Create new Audio Track Classes and store them in the ArrayList
+ List<AudioTrack> allAudioTrackInfo = new List<AudioTrack>();
+ for (int x = 0; x < encoderCount; x++)
+ {
+ AudioTrack track = new AudioTrack();
+ if (trackData != null)
+ if (trackData.Length >= (x + 1)) // Audio Track
+ track.Track = trackData[x].Trim();
+
+ if (trackMixes != null)
+ if (trackMixes.Length >= (x + 1)) // Audio Mix
+ track.MixDown = Converters.GetMixDown(trackMixes[x].Trim());
+
+ if (trackEncoders != null)
+ if (trackEncoders.Length >= (x + 1)) // Audio Mix
+ track.Encoder = Converters.GetGUIAudioEncoder(trackEncoders[x].Trim());
+
+ if (trackBitrates != null)
+ if (trackBitrates.Length >= (x + 1)) // Audio Encoder
+ track.Bitrate = trackBitrates[x].Trim() == "auto" ? "Auto" : trackBitrates[x].Trim();
+
+ if (trackSamplerates != null)
+ if (trackSamplerates.Length >= (x + 1)) // Audio SampleRate
+ track.SampleRate = trackSamplerates[x].Trim() == "0" ? "Auto" : trackSamplerates[x].Trim();
+
+ if (trackDRCvalues != null)
+ if (trackDRCvalues.Length >= (x + 1)) // Audio DRC Values
+ track.DRC = trackDRCvalues[x].Trim();
+
+ allAudioTrackInfo.Add(track);
+ }
+
+ parsed.AudioTracks = allAudioTrackInfo;
+
+ #endregion
+
+ #region Chapters Tab
+
+ if (chapterMarkersFileMode.Success || chapterMarkers.Success)
+ parsed.IncludeChapterMarkers = true;
+
+ #endregion
+
+ #region Advanced and other
+
+ if (advanced.Success)
+ parsed.AdvancedEncoderOptions = advanced.ToString().Replace("-x ", string.Empty);
+
+ #endregion
+ }
+ catch (Exception exc)
+ {
+ throw new Exception("An error has occured in the QueryParser Utility.", exc);
+ }
+
+ #endregion
+
+ return parsed;
+ }
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/UtilityService.cs b/win/CS/HandBrake.ApplicationServices/Utilities/UtilityService.cs new file mode 100644 index 000000000..3cddf5e0b --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Utilities/UtilityService.cs @@ -0,0 +1,131 @@ +/* UtilityService.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.Utilities
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Text;
+ using System.Windows.Forms;
+
+ using HandBrake.ApplicationServices.Functions;
+ using HandBrake.ApplicationServices.Model;
+
+ /// <summary>
+ /// A Set of Static Utilites
+ /// </summary>
+ public class UtilityService
+ {
+ /// <summary>
+ /// The Default Log Directory
+ /// </summary>
+ private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+
+ /// <summary>
+ /// Clear all the log files older than 30 Days
+ /// </summary>
+ /// <param name="daysToKeep">
+ /// The Number of Days to Keep
+ /// </param>
+ public static void ClearLogFiles(int daysToKeep)
+ {
+ if (Directory.Exists(LogDir))
+ {
+ // Get all the log files
+ DirectoryInfo info = new DirectoryInfo(LogDir);
+ FileInfo[] logFiles = info.GetFiles("*.txt");
+
+ // Delete Them
+ foreach (FileInfo file in logFiles)
+ {
+ if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep))
+ {
+ if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt"))
+ {
+ File.Delete(file.FullName);
+ }
+ else if (file.Length > 104857600)
+ {
+ File.Delete(file.FullName);
+ }
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Get a list of available DVD drives which are ready and contain DVD content.
+ /// </summary>
+ /// <returns>A List of Drives with their details</returns>
+ public static List<DriveInformation> GetDrives()
+ {
+ List<DriveInformation> drives = new List<DriveInformation>();
+ DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
+ int id = 0;
+ foreach (DriveInfo curDrive in theCollectionOfDrives)
+ {
+ if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)
+ {
+ if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") || Directory.Exists(curDrive.RootDirectory + "BDMV"))
+ {
+ drives.Add(
+ new DriveInformation
+ {
+ Id = id,
+ VolumeLabel = curDrive.VolumeLabel,
+ RootDirectory = curDrive.RootDirectory.ToString()
+ });
+ id++;
+ }
+ }
+ }
+
+ return drives;
+ }
+
+ /// <summary>
+ /// Get the Process ID of HandBrakeCLI for the current instance.
+ /// </summary>
+ /// <returns>A list of processes</returns>
+ public static Process[] GetCliProcess()
+ {
+ return Process.GetProcessesByName("HandBrakeCLI");
+ }
+
+ /// <summary>
+ /// Add the CLI Query to the Log File.
+ /// </summary>
+ /// <param name="encJob">
+ /// The Encode Job Object
+ /// </param>
+ /// <returns>
+ /// The create cli log header.
+ /// </returns>
+ public static string CreateCliLogHeader(QueueTask encJob)
+ {
+ StringBuilder logHeader = new StringBuilder();
+
+ logHeader.AppendLine(String.Format("# {0}", Init.HandBrakeGuiVersionString));
+ logHeader.AppendLine(String.Format("# Running: {0}", Environment.OSVersion));
+ logHeader.AppendLine(String.Format("# CPU: {0}", SystemInfo.GetCpuCount));
+ logHeader.AppendLine(String.Format("# Ram: {0} MB", SystemInfo.TotalPhysicalMemory));
+ logHeader.AppendLine(String.Format("# Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));
+ logHeader.AppendLine(String.Format("# Temp Dir: {0}", Path.GetTempPath()));
+ logHeader.AppendLine(String.Format("# Install Dir: {0}", Application.StartupPath));
+ logHeader.AppendLine(String.Format("# Data Dir: {0}\n", Application.UserAppDataPath));
+
+ if (encJob != null)
+ {
+ logHeader.AppendLine(String.Format("# CLI Query: {0}", encJob.Query));
+ logHeader.AppendLine(String.Format("# User Query: {0}", encJob.CustomQuery));
+ }
+ logHeader.AppendLine("-------------------------------------------");
+
+ return logHeader.ToString();
+ }
+ }
+}
|