summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices')
-rw-r--r--win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj4
-rw-r--r--win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs53
-rw-r--r--win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs71
-rw-r--r--win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs97
-rw-r--r--win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs121
5 files changed, 346 insertions, 0 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index db3cd55ad..52d11a26d 100644
--- a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -113,6 +113,8 @@
<Compile Include="Model\Encoding\SubtitleTrack.cs" />
<Compile Include="Model\Encoding\VideoEncoder.cs" />
<Compile Include="Model\Encoding\VideoEncodeRateMode.cs" />
+ <Compile Include="Model\General\UpdateCheckInformation.cs" />
+ <Compile Include="Model\General\UpdateCheckResult.cs" />
<Compile Include="Model\Preset.cs" />
<Compile Include="Model\QueueTask.cs" />
<Compile Include="Model\Encoding\SubtitleType.cs" />
@@ -139,6 +141,8 @@
<Compile Include="Services\QueueManager.cs" />
<Compile Include="Services\QueueProcessor.cs" />
<Compile Include="Services\ScanService.cs" />
+ <Compile Include="Services\UpdateService.cs" />
+ <Compile Include="Utilities\AppcastReader.cs" />
<Compile Include="Utilities\PlistUtility.cs" />
<Compile Include="Utilities\QueryParserUtility.cs" />
<Compile Include="Utilities\UtilityService.cs" />
diff --git a/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs
new file mode 100644
index 000000000..5932aa402
--- /dev/null
+++ b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs
@@ -0,0 +1,53 @@
+/* UpdateCheckInformation.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.Model.General
+{
+ using System;
+
+ /// <summary>
+ /// Provides information about an update check.
+ /// </summary>
+ public struct UpdateCheckInformation
+ {
+ /// <summary>
+ /// Gets or sets a value indicating whether a New Version is Available.
+ /// </summary>
+ public bool NewVersionAvailable { get; set; }
+
+ /// <summary>
+ /// Gets a value indicating whether an Error Occured.
+ /// </summary>
+ public bool ErrorOccured
+ {
+ get { return this.Error != null; }
+ }
+
+ /// <summary>
+ /// Gets or sets Information about an update to HandBrake
+ /// </summary>
+ public Uri DescriptionUrl { get; set; }
+
+ /// <summary>
+ /// Gets or sets HandBrake's version from the appcast.xml file.
+ /// </summary>
+ public string Version { get; set; }
+
+ /// <summary>
+ /// Gets or sets HandBrake's Build from the appcast.xml file.
+ /// </summary>
+ public string Build { get; set; }
+
+ /// <summary>
+ /// Gets or sets the URL for update file.
+ /// </summary>
+ public string DownloadFile { get; set; }
+
+ /// <summary>
+ /// Gets or sets the error that occurred, if any. This will be null if no error occured.
+ /// </summary>
+ public Exception Error { get; set; }
+ }
+}
diff --git a/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs
new file mode 100644
index 000000000..2f7c7e874
--- /dev/null
+++ b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs
@@ -0,0 +1,71 @@
+/* UpdateCheckResult.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.Model.General
+{
+ using System;
+ using System.Threading;
+
+ /// <summary>
+ /// Used in EndUpdateCheck() for update checking and the IAsyncResult design pattern.
+ /// </summary>
+ public class UpdateCheckResult : IAsyncResult
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UpdateCheckResult"/> class.
+ /// </summary>
+ /// <param name="asyncState">
+ /// The async state.
+ /// </param>
+ /// <param name="info">
+ /// The info.
+ /// </param>
+ public UpdateCheckResult(object asyncState, ApplicationServices.Model.General.UpdateCheckInformation info)
+ {
+ this.AsyncState = asyncState;
+ this.Result = info;
+ }
+
+ /// <summary>
+ /// Gets whether the check was executed in debug mode.
+ /// </summary>
+ public object AsyncState { get; private set; }
+
+ /// <summary>
+ /// Gets the result of the update check.
+ /// </summary>
+ public ApplicationServices.Model.General.UpdateCheckInformation Result { get; private set; }
+
+ /// <summary>
+ /// Gets AsyncWaitHandle.
+ /// </summary>
+ /// <exception cref="NotImplementedException">
+ /// </exception>
+ public WaitHandle AsyncWaitHandle
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether CompletedSynchronously.
+ /// </summary>
+ /// <exception cref="NotImplementedException">
+ /// </exception>
+ public bool CompletedSynchronously
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether IsCompleted.
+ /// </summary>
+ /// <exception cref="NotImplementedException">
+ /// </exception>
+ public bool IsCompleted
+ {
+ get { throw new NotImplementedException(); }
+ }
+ }
+}
diff --git a/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs b/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs
new file mode 100644
index 000000000..5e65021e5
--- /dev/null
+++ b/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs
@@ -0,0 +1,97 @@
+namespace HandBrake.ApplicationServices.Services
+{
+ using System;
+ using System.IO;
+ using System.Net;
+ using System.Threading;
+
+ using HandBrake.ApplicationServices.Model.General;
+ using HandBrake.ApplicationServices.Utilities;
+
+ /// <summary>
+ /// The Update Service
+ /// </summary>
+ public class UpdateService
+ {
+ /// <summary>
+ /// Begins checking for an update to HandBrake.
+ /// </summary>
+ /// <param name="callback">
+ /// The method that will be called when the check is finished.
+ /// </param>
+ /// <param name="debug">
+ /// Whether or not to execute this in debug mode.
+ /// </param>
+ /// <param name="url">
+ /// The url.
+ /// </param>
+ /// <param name="currentBuild">
+ /// The current Build.
+ /// </param>
+ /// <param name="skipBuild">
+ /// The skip Build.
+ /// </param>
+ /// <param name="currentVersion">
+ /// The current Version.
+ /// </param>
+ public static void BeginCheckForUpdates(AsyncCallback callback, bool debug, string url, int currentBuild, int skipBuild, string currentVersion)
+ {
+ ThreadPool.QueueUserWorkItem(delegate
+ {
+ try
+ {
+ // Initialize variables
+ WebRequest request = WebRequest.Create(url);
+ WebResponse response = request.GetResponse();
+ AppcastReader reader = new AppcastReader();
+
+ // Get the data, convert it to a string, and parse it into the AppcastReader
+ reader.GetUpdateInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());
+
+ // Further parse the information
+ string build = reader.Build;
+
+ int latest = int.Parse(build);
+ int current = currentBuild;
+ int skip = skipBuild;
+
+ // If the user wanted to skip this version, don't report the update
+ if (latest == skip)
+ {
+ UpdateCheckInformation info = new UpdateCheckInformation { NewVersionAvailable = false };
+ callback(new UpdateCheckResult(debug, info));
+ return;
+ }
+
+ UpdateCheckInformation info2 = new UpdateCheckInformation
+ {
+ NewVersionAvailable = latest > current,
+ DescriptionUrl = reader.DescriptionUrl,
+ DownloadFile = reader.DownloadFile,
+ Build = reader.Build,
+ Version = reader.Version,
+ };
+ callback(new UpdateCheckResult(debug, info2));
+ }
+ catch (Exception exc)
+ {
+ callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));
+ }
+ });
+ }
+
+ /// <summary>
+ /// End Check for Updates
+ /// </summary>
+ /// <param name="result">
+ /// The result.
+ /// </param>
+ /// <returns>
+ /// Update Check information
+ /// </returns>
+ public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)
+ {
+ return ((UpdateCheckResult)result).Result;
+ }
+ }
+}
diff --git a/win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs b/win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs
new file mode 100644
index 000000000..a8173d5fe
--- /dev/null
+++ b/win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs
@@ -0,0 +1,121 @@
+/* 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;
+
+ using HandBrake.Framework.Services.Interfaces;
+
+ /// <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