From cb560a92d77c20294b427afae561239cf9abb16a Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Mon, 27 Jul 2015 10:10:18 +0200 Subject: [PATCH] Implement automatic updates. --- zaaReloaded2/Properties/Settings.Designer.cs | 22 ++++++------ zaaReloaded2/Properties/Settings.settings | 8 ++--- zaaReloaded2/ThisAddIn.cs | 35 +++++++++++++++++- zaaReloaded2/Updater/Updater.cs | 37 ++++++++++++++++++++ zaaReloaded2/app.config | 15 +++++--- zaaReloaded2/zaaReloaded2.csproj | 1 + 6 files changed, 99 insertions(+), 19 deletions(-) create mode 100755 zaaReloaded2/Updater/Updater.cs diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index 261896e..0d16820 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -72,16 +72,7 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("http://zaa.nephrowiki.de/downloads")] - public string UpdatesUrl { - get { - return ((string)(this["UpdatesUrl"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("versioninfo.txt")] + [global::System.Configuration.DefaultSettingValueAttribute("http://zaa.nephrowiki.de/versioninfo.txt")] public string VersionInfoFile { get { return ((string)(this["VersionInfoFile"])); @@ -96,5 +87,16 @@ namespace zaaReloaded2.Properties { return ((string)(this["ExceptionPostUrl"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.DateTime LastUpdateCheck { + get { + return ((global::System.DateTime)(this["LastUpdateCheck"])); + } + set { + this["LastUpdateCheck"] = value; + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index d4b4745..c32f4ba 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -17,14 +17,14 @@ http://zaa.nephrowiki.de - - http://zaa.nephrowiki.de/downloads - - versioninfo.txt + http://zaa.nephrowiki.de/versioninfo.txt http://zaa.nephrowiki.de/postreport.php + + + \ No newline at end of file diff --git a/zaaReloaded2/ThisAddIn.cs b/zaaReloaded2/ThisAddIn.cs index 54a27ac..2eef6aa 100755 --- a/zaaReloaded2/ThisAddIn.cs +++ b/zaaReloaded2/ThisAddIn.cs @@ -24,6 +24,8 @@ using System.IO; using Word = Microsoft.Office.Interop.Word; using Office = Microsoft.Office.Core; using Microsoft.Office.Tools.Word; +using Bovender.Versioning; +using Bovender.Mvvm.Messaging; namespace zaaReloaded2 { @@ -48,6 +50,11 @@ namespace zaaReloaded2 private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { + if (_updaterVM != null && _updaterVM.IsUpdatePending) + { + if (_updaterVM.InstallUpdateCommand.CanExecute(null)) + _updaterVM.InstallUpdateCommand.Execute(null); + } } #region Properties @@ -75,10 +82,36 @@ namespace zaaReloaded2 #endregion + #region Updater + + void CheckForUpdates() + { + if (DateTime.Today == Properties.Settings.Default.LastUpdateCheck.Date) + return; + + Properties.Settings.Default.LastUpdateCheck = DateTime.Today; + Properties.Settings.Default.Save(); + + _updaterVM = new UpdaterViewModel(new Updater.Updater()); + if (!_updaterVM.CanCheckForUpdate) return; + + _updaterVM.UpdateAvailableMessage.Sent += UpdateAvailableMessage_Sent; + _updaterVM.CheckForUpdateCommand.Execute(null); + } + + void UpdateAvailableMessage_Sent(object sender, MessageArgs e) + { + UpdaterViewModel uvm = e.Content.ViewModel as UpdaterViewModel; + uvm.DestinationFolder = System.IO.Path.GetTempPath(); + uvm.DownloadUpdateCommand.Execute(null); + } + + #endregion #region Private fields - private Ribbon _ribbon; + Ribbon _ribbon; + UpdaterViewModel _updaterVM; #endregion diff --git a/zaaReloaded2/Updater/Updater.cs b/zaaReloaded2/Updater/Updater.cs new file mode 100755 index 0000000..da7c822 --- /dev/null +++ b/zaaReloaded2/Updater/Updater.cs @@ -0,0 +1,37 @@ +/* Updater.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace zaaReloaded2.Updater +{ + class Updater : Bovender.Versioning.Updater + { + protected override Bovender.Versioning.SemanticVersion GetCurrentVersion() + { + return Version.CurrentVersion(); + } + + protected override Uri GetVersionInfoUri() + { + return new Uri(Properties.Settings.Default.VersionInfoFile); + } + } +} diff --git a/zaaReloaded2/app.config b/zaaReloaded2/app.config index 3876239..a014def 100755 --- a/zaaReloaded2/app.config +++ b/zaaReloaded2/app.config @@ -23,6 +23,9 @@
+ +
+ @@ -38,15 +41,19 @@ http://zaa.nephrowiki.de - - http://zaa.nephrowiki.de/downloads - - versioninfo.txt + http://zaa.nephrowiki.de/versioninfo.txt http://zaa.nephrowiki.de/postreport.php + + + + + + + \ No newline at end of file diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index cba2434..7c8dc1f 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -216,6 +216,7 @@ Code + AboutView.xaml