OSDN Git Service

Started work on the update checker (RAD-36)
authorLatif Khalifa <latifer@streamgrid.net>
Wed, 23 Sep 2009 14:41:17 +0000 (14:41 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Wed, 23 Sep 2009 14:41:17 +0000 (14:41 +0000)
git-svn-id: https://radegast.googlecode.com/svn/trunk@264 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Updater/UpdateChecker.cs [new file with mode: 0644]
Radegast/GUI/Dialogs/MainForm.Designer.cs
Radegast/GUI/Dialogs/MainForm.cs
Radegast/Properties/Resources.Designer.cs
Radegast/Properties/Resources.resx
Radegast/Radegast.csproj
Radegast/Radegast.csproj.user

diff --git a/Radegast/Core/Updater/UpdateChecker.cs b/Radegast/Core/Updater/UpdateChecker.cs
new file mode 100644 (file)
index 0000000..e95be86
--- /dev/null
@@ -0,0 +1,138 @@
+// \r
+// Radegast Metaverse Client\r
+// Copyright (c) 2009, Radegast Development Team\r
+// All rights reserved.\r
+// \r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are met:\r
+// \r
+//     * Redistributions of source code must retain the above copyright notice,\r
+//       this list of conditions and the following disclaimer.\r
+//     * Redistributions in binary form must reproduce the above copyright\r
+//       notice, this list of conditions and the following disclaimer in the\r
+//       documentation and/or other materials provided with the distribution.\r
+//     * Neither the name of the application "Radegast", nor the names of its\r
+//       contributors may be used to endorse or promote products derived from\r
+//       this software without specific prior written permission.\r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+// $Id: RadegastInstance.cs 234 2009-09-13 12:45:52Z logicmoo $\r
+//\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+using System.Reflection;\r
+using System.Net;\r
+using OpenMetaverse;\r
+using OpenMetaverse.StructuredData;\r
+using System.Threading;\r
+\r
+namespace Radegast\r
+{\r
+    public class UpdateChecker : IDisposable\r
+    {\r
+        public AssemblyName MyAssembly;\r
+\r
+        public delegate void UpdateInfoCallback(object sender, UpdateCheckerArgs e);\r
+\r
+        public event UpdateInfoCallback OnUpdateInfoReceived;\r
+\r
+        private WebClient client;\r
+\r
+        public UpdateChecker()\r
+        {\r
+            MyAssembly = Assembly.GetExecutingAssembly().GetName();\r
+        }\r
+\r
+        public void Dispose()\r
+        {\r
+            if (client != null)\r
+            {\r
+                client.Dispose();\r
+                client = null;\r
+            }\r
+        }\r
+\r
+        public void StartCheck()\r
+        {\r
+            if (client == null)\r
+            {\r
+                client = new WebClient();\r
+                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnDownloadStringCompleted);\r
+            }\r
+\r
+            ThreadPool.QueueUserWorkItem((object state) =>\r
+                {\r
+                    client.DownloadStringAsync(new Uri(Properties.Resources.UpdateCheckUri));\r
+                }\r
+            );\r
+        }\r
+\r
+        private void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)\r
+        {\r
+            if (e.Error != null)\r
+            {\r
+                Logger.Log("Failed fetching updatede information: ", Helpers.LogLevel.Warning, e.Error);\r
+                FireCallback(new UpdateCheckerArgs() { Success = false });\r
+            }\r
+            else\r
+            {\r
+                try\r
+                {\r
+                    OSDMap upd = OSDParser.DeserializeJson(e.Result) as OSDMap;\r
+                    UpdateInfo inf = new UpdateInfo()\r
+                    {\r
+                        Error = upd["Error"].AsBoolean(),\r
+                        ErrMessage = upd["ErrMessage"].AsString(),\r
+                        CurrentVersion = upd["CurrentVersion"].AsString(),\r
+                        DownloadSite = upd["DownloadSite"].AsString(),\r
+                        DisplayMOTD = upd["DisplayMOTD"].AsBoolean(),\r
+                        MOTD = upd["MOTD"].AsString()\r
+                    };\r
+                    FireCallback(new UpdateCheckerArgs() { Success = !inf.Error, Info = inf });\r
+                }\r
+                catch (Exception ex)\r
+                {\r
+                    Logger.Log("Failed decoding updatede information: ", Helpers.LogLevel.Warning, ex);\r
+                    FireCallback(new UpdateCheckerArgs() { Success = false });\r
+                }\r
+            }\r
+        }\r
+\r
+        private void FireCallback(UpdateCheckerArgs e)\r
+        {\r
+            if (OnUpdateInfoReceived != null)\r
+            {\r
+                try { OnUpdateInfoReceived(this, e); }\r
+                catch { }\r
+            }\r
+        }\r
+    }\r
+\r
+    public class UpdateInfo\r
+    {\r
+        public bool Error { get; set; }\r
+        public string ErrMessage { get; set; }\r
+        public string CurrentVersion { get; set; }\r
+        public string DownloadSite { get; set; }\r
+        public bool DisplayMOTD { get; set; }\r
+        public string MOTD { get; set; }\r
+    }\r
+\r
+    public class UpdateCheckerArgs : EventArgs\r
+    {\r
+        public bool Success { get; set; }\r
+        public UpdateInfo Info { get; set; }\r
+    }\r
+\r
+}\r
index e7a422c..4273e91 100644 (file)
@@ -130,6 +130,8 @@ namespace Radegast
             this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();\r
             this.pnlDialog = new System.Windows.Forms.Panel();\r
             this.timerWorldClock = new System.Windows.Forms.Timer(this.components);\r
+            this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripSeparator();\r
+            this.checkForUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
             this.toolStrip1.SuspendLayout();\r
             this.statusStrip1.SuspendLayout();\r
             this.toolStripContainer1.TopToolStripPanel.SuspendLayout();\r
@@ -501,6 +503,8 @@ namespace Radegast
             this.tbtnHelp.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;\r
             this.tbtnHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {\r
             this.reportBugsToolStripMenuItem,\r
+            this.checkForUpdatesToolStripMenuItem,\r
+            this.toolStripMenuItem6,\r
             this.aboutRadegastToolStripMenuItem});\r
             this.tbtnHelp.Image = ((System.Drawing.Image)(resources.GetObject("tbtnHelp.Image")));\r
             this.tbtnHelp.ImageTransparentColor = System.Drawing.Color.Magenta;\r
@@ -678,6 +682,18 @@ namespace Radegast
             this.timerWorldClock.Interval = 1000;\r
             this.timerWorldClock.Tick += new System.EventHandler(this.timerWorldClock_Tick);\r
             // \r
+            // toolStripMenuItem6\r
+            // \r
+            this.toolStripMenuItem6.Name = "toolStripMenuItem6";\r
+            this.toolStripMenuItem6.Size = new System.Drawing.Size(200, 6);\r
+            // \r
+            // checkForUpdatesToolStripMenuItem\r
+            // \r
+            this.checkForUpdatesToolStripMenuItem.Name = "checkForUpdatesToolStripMenuItem";\r
+            this.checkForUpdatesToolStripMenuItem.Size = new System.Drawing.Size(203, 22);\r
+            this.checkForUpdatesToolStripMenuItem.Text = "Check for Updates...";\r
+            this.checkForUpdatesToolStripMenuItem.Click += new System.EventHandler(this.checkForUpdatesToolStripMenuItem_Click);\r
+            // \r
             // frmMain\r
             // \r
             this.AutoSavePosition = true;\r
@@ -770,6 +786,8 @@ namespace Radegast
         private System.Windows.Forms.ToolStripDropDownButton tbtnHelp;\r
         private System.Windows.Forms.ToolStripMenuItem reportBugsToolStripMenuItem;\r
         private System.Windows.Forms.ToolStripMenuItem aboutRadegastToolStripMenuItem;\r
+        private System.Windows.Forms.ToolStripSeparator toolStripMenuItem6;\r
+        private System.Windows.Forms.ToolStripMenuItem checkForUpdatesToolStripMenuItem;\r
     }\r
 }\r
 \r
index 1e3b542..6805a6c 100644 (file)
@@ -952,6 +952,23 @@ namespace Radegast
             (new frmAbout(instance)).ShowDialog();\r
         }\r
 \r
+        private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)\r
+        {\r
+            tabsConsole.SelectTab("chat");\r
+            tabsConsole.DisplayNotificationInChat("Checking for updates...");\r
+            UpdateChecker upd = new UpdateChecker();\r
+            upd.OnUpdateInfoReceived += new UpdateChecker.UpdateInfoCallback(OnUpdateInfoReceived);\r
+            upd.StartCheck();\r
+        }\r
+\r
+        void OnUpdateInfoReceived(object sender, UpdateCheckerArgs e)\r
+        {\r
+            if (!e.Success)\r
+            {\r
+                tabsConsole.DisplayNotificationInChat("Error: Failed connecting to the update site.");\r
+            }\r
+            ((UpdateChecker)sender).Dispose();\r
+        }\r
         #endregion\r
     }\r
 }
\ No newline at end of file
index 3a9f5cd..5c66138 100644 (file)
@@ -654,5 +654,14 @@ namespace Radegast.Properties {
                 return ((System.Drawing.Bitmap)(obj));\r
             }\r
         }\r
+        \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to http://update.radegastclient.org/svc/get_latest.\r
+        /// </summary>\r
+        public static string UpdateCheckUri {\r
+            get {\r
+                return ResourceManager.GetString("UpdateCheckUri", resourceCulture);\r
+            }\r
+        }\r
     }\r
 }\r
index 50571ca..17c45d2 100644 (file)
   <data name="radegast_large" type="System.Resources.ResXFileRef, System.Windows.Forms">\r
     <value>../Resources/radegast_large.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>\r
   </data>\r
+  <data name="UpdateCheckUri" xml:space="preserve">\r
+    <value>http://update.radegastclient.org/svc/get_latest</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 5c50e4b..dc8d02e 100644 (file)
@@ -2,7 +2,7 @@
   <PropertyGroup>\r
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
-    <ProductVersion>9.0.21022</ProductVersion>\r
+    <ProductVersion>9.0.30729</ProductVersion>\r
     <SchemaVersion>2.0</SchemaVersion>\r
     <ProjectGuid>{A6D955CD-1F55-459F-A7AD-01E591404989}</ProjectGuid>\r
     <OutputType>WinExe</OutputType>\r
     <Compile Include="Core\Types\TransparentLabel.cs">\r
       <SubType>Component</SubType>\r
     </Compile>\r
+    <Compile Include="Core\Updater\UpdateChecker.cs" />\r
     <Compile Include="FormFlash.cs" />\r
     <Compile Include="GUI\Consoles\AnimDetail.cs">\r
       <SubType>UserControl</SubType>\r
     <None Include="openjpeg-dotnet.dll">\r
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
     </None>\r
-    <None Include="assemblies\fmodex-dotnet.dll" />\r
     <None Include="fmodex.dll">\r
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
     </None>\r
+    <None Include="assemblies\fmodex-dotnet.dll">\r
+    </None>\r
     <Content Include="openmetaverse_data\avatar_lad.xml">\r
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
     </Content>\r
index dbf2dff..85c49c6 100644 (file)
@@ -11,6 +11,6 @@
     </BootstrapperUrlHistory>\r
     <FallbackCulture>en-US</FallbackCulture>\r
     <VerifyUploadedFiles>false</VerifyUploadedFiles>\r
-    <ProjectView>ShowAllFiles</ProjectView>\r
+    <ProjectView>ProjectFiles</ProjectView>\r
   </PropertyGroup>\r
 </Project>
\ No newline at end of file