summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2014-11-29 17:59:31 +0000
committersr55 <[email protected]>2014-11-29 17:59:31 +0000
commit7c0af498a9d5f7aae1e5c8d06b939c8189edcfbe (patch)
tree74d348fb0cd83d48d13d4ae1007909e032a5a807 /win/CS/HandBrakeWPF
parentd364449a2ec863db317422645d5c7a927d294654 (diff)
WinGui: Re-factoring the services library.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6567 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/Collections/SerializableDictionary.cs126
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj5
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs1
-rw-r--r--win/CS/HandBrakeWPF/Services/UpdateService.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/UserSettingService.cs19
-rw-r--r--win/CS/HandBrakeWPF/Utilities/AppcastReader.cs123
-rw-r--r--win/CS/HandBrakeWPF/Utilities/PList.cs155
-rw-r--r--win/CS/HandBrakeWPF/Utilities/Win7.cs80
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/InstantViewModel.cs1
-rw-r--r--win/CS/HandBrakeWPF/Views/ShellView.xaml.cs1
10 files changed, 503 insertions, 10 deletions
diff --git a/win/CS/HandBrakeWPF/Collections/SerializableDictionary.cs b/win/CS/HandBrakeWPF/Collections/SerializableDictionary.cs
new file mode 100644
index 000000000..92ec90d1f
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Collections/SerializableDictionary.cs
@@ -0,0 +1,126 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="SerializableDictionary.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// A Serializable Dictionary
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Collections
+{
+ using System.Collections.Generic;
+ using System.Collections.Specialized;
+ using System.Xml.Serialization;
+
+ /// <summary>
+ /// A Serializable Dictionary
+ /// </summary>
+ /// <typeparam name="TKey">
+ /// The Key Type
+ /// </typeparam>
+ /// <typeparam name="TValue">
+ /// The Value Type
+ /// </typeparam>
+ [XmlRoot("dictionary")]
+ public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
+ {
+ #region IXmlSerializable Members
+
+ /// <summary>
+ /// Get the Schema
+ /// </summary>
+ /// <returns>
+ /// Nothing. We don't use this.
+ /// </returns>
+ public System.Xml.Schema.XmlSchema GetSchema()
+ {
+ return null;
+ }
+
+ /// <summary>
+ /// Deserialize some XML into a dictionary
+ /// </summary>
+ /// <param name="reader">
+ /// The reader.
+ /// </param>
+ public void ReadXml(System.Xml.XmlReader reader)
+ {
+ XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
+ XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
+
+ bool wasEmpty = reader.IsEmptyElement;
+ reader.Read();
+
+ if (wasEmpty)
+ return;
+
+ while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
+ {
+ reader.ReadStartElement("item");
+
+ reader.ReadStartElement("key");
+ TKey key = (TKey)keySerializer.Deserialize(reader);
+ reader.ReadEndElement();
+
+ reader.ReadStartElement("value");
+ TValue value;
+ if (reader.Name.Contains("ArrayOfString"))
+ {
+ XmlSerializer scSerializer = new XmlSerializer(typeof(StringCollection));
+ value = (TValue)scSerializer.Deserialize(reader);
+ }
+ else
+ {
+ value = (TValue)valueSerializer.Deserialize(reader);
+ }
+ reader.ReadEndElement();
+
+ this.Add(key, value);
+
+ reader.ReadEndElement();
+ reader.MoveToContent();
+ }
+ reader.ReadEndElement();
+ }
+
+ /// <summary>
+ /// Write the Dictionary out to XML
+ /// </summary>
+ /// <param name="writer">
+ /// The writer.
+ /// </param>
+ public void WriteXml(System.Xml.XmlWriter writer)
+ {
+ XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
+ XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));
+
+ foreach (TKey key in this.Keys)
+ {
+ writer.WriteStartElement("item");
+
+ writer.WriteStartElement("key");
+ keySerializer.Serialize(writer, key);
+ writer.WriteEndElement();
+
+ writer.WriteStartElement("value");
+ TValue value = this[key];
+
+ if (value.GetType() == typeof(StringCollection))
+ {
+ XmlSerializer scSerializer = new XmlSerializer(typeof(StringCollection));
+ scSerializer.Serialize(writer, value);
+ writer.WriteEndElement();
+ }
+ else
+ {
+ valueSerializer.Serialize(writer, value);
+ writer.WriteEndElement();
+ }
+
+ writer.WriteEndElement();
+ }
+ }
+ #endregion
+ }
+}
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index 3ca004790..1e588f984 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -132,6 +132,7 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
+ <Reference Include="System.Xml.Linq" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
</ItemGroup>
@@ -142,6 +143,7 @@
</ApplicationDefinition>
<Compile Include="AppArguments.cs" />
<Compile Include="AttachedProperties\MenuItemExtensions.cs" />
+ <Compile Include="Collections\SerializableDictionary.cs" />
<Compile Include="Commands\CancelScanCommand.cs" />
<Compile Include="Commands\Interfaces\IAdvancedEncoderOptionsCommand.cs" />
<Compile Include="Commands\OpenOptionsScreenCommand.cs" />
@@ -163,10 +165,13 @@
<Compile Include="Services\Interfaces\IUserSettingService.cs" />
<Compile Include="Services\Presets\PresetService.cs" />
<Compile Include="Services\UserSettingService.cs" />
+ <Compile Include="Utilities\AppcastReader.cs" />
<Compile Include="Utilities\DelayedActionProcessor.cs" />
<Compile Include="Utilities\DPIAwareness.cs" />
<Compile Include="Utilities\HandBrakeApp.cs" />
<Compile Include="Services\Presets\Factories\PlistFactory.cs" />
+ <Compile Include="Utilities\PList.cs" />
+ <Compile Include="Utilities\Win7.cs" />
<Compile Include="ViewModels\CountdownAlertViewModel.cs" />
<Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />
<Compile Include="Controls\SourceSelection.xaml.cs">
diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs
index b06df1728..7edf71836 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/PlistPresetFactory.cs
@@ -26,6 +26,7 @@ namespace HandBrakeWPF.Services.Presets.Factories
using HandBrakeWPF.Services.Presets;
using HandBrakeWPF.Services.Presets.Model;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// A Factory to translate a Plist object into a Preset.
diff --git a/win/CS/HandBrakeWPF/Services/UpdateService.cs b/win/CS/HandBrakeWPF/Services/UpdateService.cs
index 67220c0e3..2064e8e5c 100644
--- a/win/CS/HandBrakeWPF/Services/UpdateService.cs
+++ b/win/CS/HandBrakeWPF/Services/UpdateService.cs
@@ -20,6 +20,8 @@ namespace HandBrakeWPF.Services
using HandBrakeWPF.Model;
using HandBrakeWPF.Services.Interfaces;
+ using AppcastReader = HandBrakeWPF.Utilities.AppcastReader;
+
/// <summary>
/// The Update Service
/// </summary>
diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
index d10ec84df..6b7d87f1b 100644
--- a/win/CS/HandBrakeWPF/Services/UserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
@@ -16,7 +16,6 @@ namespace HandBrakeWPF.Services
using System.Reflection;
using System.Xml.Serialization;
- using HandBrake.ApplicationServices.Collections;
using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Exceptions;
@@ -35,12 +34,12 @@ namespace HandBrakeWPF.Services
/// <summary>
/// The XML Serializer
/// </summary>
- readonly XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, object>));
+ readonly XmlSerializer serializer = new XmlSerializer(typeof(Collections.SerializableDictionary<string, object>));
/// <summary>
/// The User Settings
/// </summary>
- private SerializableDictionary<string, object> userSettings;
+ private Collections.SerializableDictionary<string, object> userSettings;
/// <summary>
/// Initializes a new instance of the <see cref="UserSettingService"/> class.
@@ -162,17 +161,17 @@ namespace HandBrakeWPF.Services
{
using (StreamReader reader = new StreamReader(this.settingsFile))
{
- SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)this.serializer.Deserialize(reader);
+ Collections.SerializableDictionary<string, object> data = (Collections.SerializableDictionary<string, object>)this.serializer.Deserialize(reader);
this.userSettings = data;
}
}
else
{
- this.userSettings = new SerializableDictionary<string, object>();
+ this.userSettings = new Collections.SerializableDictionary<string, object>();
}
// Add any missing / new settings
- SerializableDictionary<string, object> defaults = this.GetDefaults();
+ Collections.SerializableDictionary<string, object> defaults = this.GetDefaults();
foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key)))
{
this.userSettings.Add(item.Key, item.Value);
@@ -205,7 +204,7 @@ namespace HandBrakeWPF.Services
/// <returns>
/// The get defaults.
/// </returns>
- private SerializableDictionary<string, object> GetDefaults()
+ private Collections.SerializableDictionary<string, object> GetDefaults()
{
try
{
@@ -213,15 +212,15 @@ namespace HandBrakeWPF.Services
Stream stream = assembly.GetManifestResourceStream("HandBrakeWPF.defaultsettings.xml");
if (stream != null)
{
- return (SerializableDictionary<string, object>)this.serializer.Deserialize(stream);
+ return (Collections.SerializableDictionary<string, object>)this.serializer.Deserialize(stream);
}
}
catch (Exception)
{
- return new SerializableDictionary<string, object>();
+ return new Collections.SerializableDictionary<string, object>();
}
- return new SerializableDictionary<string, object>();
+ return new Collections.SerializableDictionary<string, object>();
}
}
}
diff --git a/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs b/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs
new file mode 100644
index 000000000..49d7f4714
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/AppcastReader.cs
@@ -0,0 +1,123 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AppcastReader.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Appcast Reader - Used for parsing HandBrakes update file
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.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/HandBrakeWPF/Utilities/PList.cs b/win/CS/HandBrakeWPF/Utilities/PList.cs
new file mode 100644
index 000000000..1e3c30e20
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/PList.cs
@@ -0,0 +1,155 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="PList.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// A Helper class to parse plist files.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Xml.Linq;
+
+ /// <summary>
+ /// A Helper class to parse plist files.
+ /// </summary>
+ public class PList : Dictionary<string, dynamic>
+ {
+ #region Constructors and Destructors
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PList"/> class.
+ /// </summary>
+ public PList()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PList"/> class.
+ /// </summary>
+ /// <param name="file">
+ /// The file.
+ /// </param>
+ public PList(string file)
+ {
+ this.Load(file);
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// Load a plist file.
+ /// </summary>
+ /// <param name="file">
+ /// The file name / path
+ /// </param>
+ /// <returns>
+ /// True if successful, false otherwise.
+ /// </returns>
+ public bool Load(string file)
+ {
+ this.Clear();
+
+ XDocument doc = XDocument.Load(file);
+ XElement plist = doc.Element("plist");
+ if (plist != null)
+ {
+ XElement array = plist.Element("array");
+ if (array != null)
+ {
+ XElement dict = array.Element("dict");
+
+ if (dict != null)
+ {
+ IEnumerable<XElement> dictElements = dict.Elements();
+ this.Parse(this, dictElements);
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// Parse a list of elements
+ /// </summary>
+ /// <param name="dict">
+ /// The dict.
+ /// </param>
+ /// <param name="elements">
+ /// The elements.
+ /// </param>
+ private void Parse(PList dict, IEnumerable<XElement> elements)
+ {
+ for (int i = 0; i < elements.Count(); i += 2)
+ {
+ XElement key = elements.ElementAt(i);
+ XElement val = elements.ElementAt(i + 1);
+
+ dict[key.Value] = this.ParseValue(val);
+ }
+ }
+
+ /// <summary>
+ /// The parse array.
+ /// </summary>
+ /// <param name="elements">
+ /// The elements.
+ /// </param>
+ /// <returns>
+ /// The <see cref="List"/>.
+ /// </returns>
+ private List<dynamic> ParseArray(IEnumerable<XElement> elements)
+ {
+ return elements.Select(e => this.ParseValue(e)).ToList();
+ }
+
+ /// <summary>
+ /// The parse value.
+ /// </summary>
+ /// <param name="val">
+ /// The XElement.
+ /// </param>
+ /// <returns>
+ /// The parsed value object.
+ /// </returns>
+ private dynamic ParseValue(XElement val)
+ {
+ switch (val.Name.ToString())
+ {
+ case "string":
+ return val.Value;
+ case "integer":
+ return int.Parse(val.Value);
+ case "real":
+ return float.Parse(val.Value);
+ case "true":
+ return true;
+ case "false":
+ return false;
+ case "dict":
+ var plist = new PList();
+ this.Parse(plist, val.Elements());
+ return plist;
+ case "array":
+ List<dynamic> list = this.ParseArray(val.Elements());
+ return list;
+ default:
+ throw new ArgumentException("This plist file is not supported.");
+ }
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Utilities/Win7.cs b/win/CS/HandBrakeWPF/Utilities/Win7.cs
new file mode 100644
index 000000000..0f6cb5680
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/Win7.cs
@@ -0,0 +1,80 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="Win7.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// A class implimenting Windows 7 Specific features
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System.Windows.Shell;
+
+ /// <summary>
+ /// A class implementing Windows 7 Specific features
+ /// </summary>
+ public class Win7
+ {
+ /// <summary>
+ /// The Windows Taskbar
+ /// </summary>
+ public static TaskbarItemInfo WindowsTaskbar;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Win7"/> class.
+ /// </summary>
+ public Win7()
+ {
+ if (WindowsTaskbar == null)
+ WindowsTaskbar = new TaskbarItemInfo();
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether is windows seven.
+ /// </summary>
+ public bool IsWindowsSeven
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ /// <summary>
+ /// The get task bar.
+ /// </summary>
+ /// <returns>
+ /// The <see cref="TaskbarItemInfo"/>.
+ /// </returns>
+ public TaskbarItemInfo GetTaskBar()
+ {
+ return WindowsTaskbar;
+ }
+
+ /// <summary>
+ /// Set the Task Bar Percentage.
+ /// </summary>
+ /// <param name="percentage">
+ /// The percentage.
+ /// </param>
+ public void SetTaskBarProgress(int percentage)
+ {
+ // Update the taskbar progress indicator. The normal state shows a green progress bar.
+ Caliburn.Micro.Execute.OnUIThread(
+ () =>
+ {
+ WindowsTaskbar.ProgressState = TaskbarItemProgressState.Normal;
+ WindowsTaskbar.ProgressValue = (double)percentage / 100;
+ });
+ }
+
+ /// <summary>
+ /// Disable Task Bar Progress
+ /// </summary>
+ public void SetTaskBarProgressToNoProgress()
+ {
+ Caliburn.Micro.Execute.OnUIThread(() => WindowsTaskbar.ProgressState = TaskbarItemProgressState.None);
+ }
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/ViewModels/InstantViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/InstantViewModel.cs
index 1eddfd83e..3d4781276 100644
--- a/win/CS/HandBrakeWPF/ViewModels/InstantViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/InstantViewModel.cs
@@ -35,6 +35,7 @@ namespace HandBrakeWPF.ViewModels
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using HandBrakeWPF.Views;
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
index 35e1e0333..bb757662c 100644
--- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
+++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs
@@ -23,6 +23,7 @@ namespace HandBrakeWPF.Views
using HandBrakeWPF.Commands;
using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Application = System.Windows.Application;