diff options
author | sr55 <[email protected]> | 2010-09-19 12:17:07 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-09-19 12:17:07 +0000 |
commit | 1d3a178d671af6d09b3e3be35562fe5070ace809 (patch) | |
tree | 288f38ac3e39cf5300fb7d3ddffff5e3604b1565 /win/C#/Functions | |
parent | 8cac9d8c62ce452ff27a6b70f005056f44b55581 (diff) |
WinGui:
- Moved some non-specific HandBrake code (Exception Window, Update Information Window, Update Download Window) out into a separate framework library. Hoping to make this more reusable at a later point.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3543 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Functions')
-rw-r--r-- | win/C#/Functions/AppcastReader.cs | 119 | ||||
-rw-r--r-- | win/C#/Functions/Main.cs | 87 | ||||
-rw-r--r-- | win/C#/Functions/UpdateCheckInformation.cs | 100 |
3 files changed, 3 insertions, 303 deletions
diff --git a/win/C#/Functions/AppcastReader.cs b/win/C#/Functions/AppcastReader.cs deleted file mode 100644 index 6b4a48470..000000000 --- a/win/C#/Functions/AppcastReader.cs +++ /dev/null @@ -1,119 +0,0 @@ -/* RssReader.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.Functions
-{
- 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 GetInfo(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/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index 78da9ca3c..385671355 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -16,6 +16,9 @@ namespace Handbrake.Functions using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
+
+ using HandBrake.Framework.Services;
+ using HandBrake.Framework.Services.Interfaces;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -486,90 +489,6 @@ namespace Handbrake.Functions }
/// <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>
- public static void BeginCheckForUpdates(AsyncCallback callback, bool debug)
- {
- ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
- {
- try
- {
- // Is this a stable or unstable build?
- string url =
- Properties.Settings.Default.hb_build.ToString()
- .EndsWith("1")
- ? Properties.Settings.Default.
- appcast_unstable
- : Properties.Settings.Default.appcast;
-
- // 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.GetInfo(
- new StreamReader(response.GetResponseStream())
- .ReadToEnd());
-
- // Further parse the information
- string build = reader.Build;
-
- int latest = int.Parse(build);
- int current = Properties.Settings.Default.hb_build;
- int skip = Properties.Settings.Default.skipversion;
-
- // If the user wanted to skip this version, don't report the update
- if (latest == skip)
- {
- UpdateCheckInformation info =
- new UpdateCheckInformation
- {
- NewVersionAvailable = false,
- BuildInformation = null
- };
- callback(new UpdateCheckResult(debug, info));
- return;
- }
-
- // Set when the last update was
- Properties.Settings.Default.lastUpdateCheckDate =
- DateTime.Now;
- Properties.Settings.Default.Save();
-
- UpdateCheckInformation info2 =
- new UpdateCheckInformation
- {
- NewVersionAvailable = latest > current,
- BuildInformation = reader
- };
- 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)
- {
- UpdateCheckResult checkResult = (UpdateCheckResult)result;
- return checkResult.Result;
- }
-
- /// <summary>
/// Map languages and their iso639_2 value into a IDictionary
/// </summary>
/// <returns>A Dictionary containing the language and iso code</returns>
diff --git a/win/C#/Functions/UpdateCheckInformation.cs b/win/C#/Functions/UpdateCheckInformation.cs deleted file mode 100644 index b3ed02b88..000000000 --- a/win/C#/Functions/UpdateCheckInformation.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* 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.Functions
-{
- using System;
- using System.Threading;
-
- /// <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 the new build, if any. This will be null if there is no new verison.
- /// </summary>
- public AppcastReader BuildInformation { 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; }
- }
-
- /// <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, 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 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(); }
- }
- }
-}
|