From: sr55 Date: Sun, 13 Mar 2011 12:35:48 +0000 (+0000) Subject: WinGui: X-Git-Tag: 0.9.6~621 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57224a250b66b28bed628f587486197c9900bc1d;p=handbrake WinGui: - Shuffle some more code around. Aiming to remove the framework library completely soon. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3842 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- 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 @@ + + @@ -139,6 +141,8 @@ + + diff --git a/win/C#/HandBrake.Framework/Model/UpdateCheckInformation.cs b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs similarity index 58% rename from win/C#/HandBrake.Framework/Model/UpdateCheckInformation.cs rename to win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs index ff59dce72..5932aa402 100644 --- a/win/C#/HandBrake.Framework/Model/UpdateCheckInformation.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckInformation.cs @@ -3,10 +3,9 @@ Homepage: . It may be used under the terms of the GNU General Public License. */ -namespace HandBrake.Framework.Model +namespace HandBrake.ApplicationServices.Model.General { using System; - using HandBrake.Framework.Services.Interfaces; /// /// Provides information about an update check. @@ -27,9 +26,24 @@ namespace HandBrake.Framework.Model } /// - /// Gets or sets information about the new build, if any. This will be null if there is no new verison. + /// Gets or sets Information about an update to HandBrake /// - public IAppcastReader BuildInformation { get; set; } + public Uri DescriptionUrl { get; set; } + + /// + /// Gets or sets HandBrake's version from the appcast.xml file. + /// + public string Version { get; set; } + + /// + /// Gets or sets HandBrake's Build from the appcast.xml file. + /// + public string Build { get; set; } + + /// + /// Gets or sets the URL for update file. + /// + public string DownloadFile { get; set; } /// /// Gets or sets the error that occurred, if any. This will be null if no error occured. diff --git a/win/C#/HandBrake.Framework/Model/UpdateCheckResult.cs b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs similarity index 81% rename from win/C#/HandBrake.Framework/Model/UpdateCheckResult.cs rename to win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs index ba04100ca..2f7c7e874 100644 --- a/win/C#/HandBrake.Framework/Model/UpdateCheckResult.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/General/UpdateCheckResult.cs @@ -3,7 +3,7 @@ Homepage: . It may be used under the terms of the GNU General Public License. */ -namespace HandBrake.Framework.Model +namespace HandBrake.ApplicationServices.Model.General { using System; using System.Threading; @@ -14,7 +14,7 @@ namespace HandBrake.Framework.Model public class UpdateCheckResult : IAsyncResult { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The async state. @@ -22,7 +22,7 @@ namespace HandBrake.Framework.Model /// /// The info. /// - public UpdateCheckResult(object asyncState, UpdateCheckInformation info) + public UpdateCheckResult(object asyncState, ApplicationServices.Model.General.UpdateCheckInformation info) { this.AsyncState = asyncState; this.Result = info; @@ -36,7 +36,7 @@ namespace HandBrake.Framework.Model /// /// Gets the result of the update check. /// - public UpdateCheckInformation Result { get; private set; } + public ApplicationServices.Model.General.UpdateCheckInformation Result { get; private set; } /// /// Gets AsyncWaitHandle. 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; + + /// + /// The Update Service + /// + public class UpdateService + { + /// + /// Begins checking for an update to HandBrake. + /// + /// + /// The method that will be called when the check is finished. + /// + /// + /// Whether or not to execute this in debug mode. + /// + /// + /// The url. + /// + /// + /// The current Build. + /// + /// + /// The skip Build. + /// + /// + /// The current Version. + /// + 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 })); + } + }); + } + + /// + /// End Check for Updates + /// + /// + /// The result. + /// + /// + /// Update Check information + /// + public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result) + { + return ((UpdateCheckResult)result).Result; + } + } +} diff --git a/win/C#/HandBrake.Framework/Services/AppcastReader.cs b/win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs similarity index 94% rename from win/C#/HandBrake.Framework/Services/AppcastReader.cs rename to win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs index 31bd853a7..a8173d5fe 100644 --- a/win/C#/HandBrake.Framework/Services/AppcastReader.cs +++ b/win/C#/HandBrake.ApplicationServices/Utilities/AppcastReader.cs @@ -3,7 +3,7 @@ Homepage: . It may be used under the terms of the GNU General Public License. */ -namespace HandBrake.Framework.Services +namespace HandBrake.ApplicationServices.Utilities { using System; using System.IO; @@ -15,7 +15,7 @@ namespace HandBrake.Framework.Services /// /// Appcast Reader - Used for parsing HandBrakes update file /// - public class AppcastReader : IAppcastReader + public class AppcastReader { /// /// Gets Information about an update to HandBrake diff --git a/win/C#/HandBrake.Framework/HandBrake.Framework.csproj b/win/C#/HandBrake.Framework/HandBrake.Framework.csproj index e7a7664b6..9e625e5db 100644 --- a/win/C#/HandBrake.Framework/HandBrake.Framework.csproj +++ b/win/C#/HandBrake.Framework/HandBrake.Framework.csproj @@ -55,9 +55,6 @@ - - - True @@ -65,27 +62,13 @@ Resources.resx - - Form ExceptionWindow.cs - - Form - - - DownloadUpdate.cs - - - Form - - - UpdateInfo.cs - @@ -95,14 +78,6 @@ ExceptionWindow.cs - - DownloadUpdate.cs - Designer - - - UpdateInfo.cs - Designer - @@ -110,12 +85,6 @@ - - - - - -