OSDN Git Service

add win/C# diff files
[handbrake-jp/handbrake-jp.git] / win / C# / HandBrake.Framework / Services / UpdateService.cs.diff
diff --git a/win/C#/HandBrake.Framework/Services/UpdateService.cs.diff b/win/C#/HandBrake.Framework/Services/UpdateService.cs.diff
new file mode 100644 (file)
index 0000000..6e5bae5
--- /dev/null
@@ -0,0 +1,107 @@
+diff --git a/win/C#/HandBrake.Framework/Services/UpdateService.cs b/win/C#/HandBrake.Framework/Services/UpdateService.cs
+new file mode 100644
+index 0000000..0bbd781
+--- /dev/null
++++ b/win/C#/HandBrake.Framework/Services/UpdateService.cs
+@@ -0,0 +1,101 @@
++/*  UpdateService.cs $\r
++    This file is part of the HandBrake source code.\r
++    Homepage: <http://handbrake.fr>.\r
++    It may be used under the terms of the GNU General Public License. */\r
++\r
++namespace HandBrake.Framework.Services\r
++{\r
++    using System;\r
++    using System.IO;\r
++    using System.Net;\r
++    using System.Threading;\r
++\r
++    using HandBrake.Framework.Model;\r
++    using HandBrake.Framework.Services.Interfaces;\r
++\r
++    public class UpdateService\r
++    {\r
++        /// <summary>\r
++        /// Begins checking for an update to HandBrake.\r
++        /// </summary>\r
++        /// <param name="callback">\r
++        /// The method that will be called when the check is finished.\r
++        /// </param>\r
++        /// <param name="debug">\r
++        /// Whether or not to execute this in debug mode.\r
++        /// </param>\r
++        /// <param name="url">\r
++        /// The url.\r
++        /// </param>\r
++        /// <param name="currentBuild">\r
++        /// The current Build.\r
++        /// </param>\r
++        /// <param name="skipBuild">\r
++        /// The skip Build.\r
++        /// </param>\r
++        /// <param name="currentVersion">\r
++        /// The current Version.\r
++        /// </param>\r
++        public static void BeginCheckForUpdates(AsyncCallback callback, bool debug, string url, int currentBuild, int skipBuild, string currentVersion)\r
++        {\r
++            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate\r
++            {\r
++                try\r
++                {\r
++                    // Initialize variables\r
++                    WebRequest request = WebRequest.Create(url);\r
++                    WebResponse response = request.GetResponse();\r
++                    IAppcastReader reader = new AppcastReader();\r
++\r
++                    // Get the data, convert it to a string, and parse it into the AppcastReader\r
++                    reader.GetUpdateInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());\r
++\r
++                    // Further parse the information\r
++                    string build = reader.Build;\r
++\r
++                    int latest = int.Parse(build);\r
++                    int current = currentBuild;\r
++                    int skip = skipBuild;\r
++\r
++                    // If the user wanted to skip this version, don't report the update\r
++                    if (latest == skip)\r
++                    {\r
++                        UpdateCheckInformation info =\r
++                            new UpdateCheckInformation\r
++                            {\r
++                                NewVersionAvailable = false,\r
++                                BuildInformation = null\r
++                            };\r
++                        callback(new UpdateCheckResult(debug, info));\r
++                        return;\r
++                    }\r
++\r
++                    UpdateCheckInformation info2 = new UpdateCheckInformation\r
++                        {\r
++                            NewVersionAvailable = latest > current,\r
++                            BuildInformation = reader\r
++                        };\r
++                    callback(new UpdateCheckResult(debug, info2));\r
++                }\r
++                catch (Exception exc)\r
++                {\r
++                    callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));\r
++                }\r
++            }));\r
++        }\r
++\r
++        /// <summary>\r
++        /// End Check for Updates\r
++        /// </summary>\r
++        /// <param name="result">\r
++        /// The result.\r
++        /// </param>\r
++        /// <returns>\r
++        /// Update Check information\r
++        /// </returns>\r
++        public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)\r
++        {\r
++            return ((UpdateCheckResult)result).Result;\r
++        }\r
++    }\r
++}\r