2015-06-17 18:15:02 +00:00
|
|
|
|
/* thisaddin.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;
|
2015-06-28 07:44:33 +00:00
|
|
|
|
using System.IO;
|
2015-07-27 08:10:18 +00:00
|
|
|
|
using Bovender.Versioning;
|
|
|
|
|
using Bovender.Mvvm.Messaging;
|
2015-07-27 20:14:18 +00:00
|
|
|
|
using zaaReloaded2.ExceptionHandler;
|
2015-08-31 10:28:50 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media;
|
2015-06-15 17:15:52 +00:00
|
|
|
|
|
|
|
|
|
namespace zaaReloaded2
|
|
|
|
|
{
|
|
|
|
|
public partial class ThisAddIn
|
|
|
|
|
{
|
2015-06-28 07:44:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the subdirectory for addin data in the user profile directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string Subdir
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
|
|
|
"zaaReloaded2");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 17:15:52 +00:00
|
|
|
|
private void ThisAddIn_Startup(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2015-07-27 20:14:18 +00:00
|
|
|
|
Bovender.ExceptionHandler.CentralHandler.ManageExceptionCallback += CentralHandler_ManageExceptionCallback;
|
2015-09-09 19:45:55 +00:00
|
|
|
|
Bovender.WpfHelpers.RegisterTextBoxSelectAll();
|
2015-10-09 20:38:31 +00:00
|
|
|
|
Properties.Settings.Default.Upgrade();
|
2015-07-28 11:25:17 +00:00
|
|
|
|
CheckForUpdates();
|
2015-08-18 07:00:26 +00:00
|
|
|
|
_oldCaption = Globals.ThisAddIn.Application.Caption;
|
|
|
|
|
Globals.ThisAddIn.Application.Caption =
|
|
|
|
|
String.Format(
|
|
|
|
|
"{0} ({1} {2})",
|
|
|
|
|
_oldCaption,
|
|
|
|
|
Properties.Settings.Default.AddinName,
|
|
|
|
|
Updater.Version.CurrentVersion().ToString()
|
|
|
|
|
);
|
2015-09-05 17:47:58 +00:00
|
|
|
|
ViewModels.FirstRunViewModel.InjectIntoIfNeeded<Views.FirstRunView>();
|
2015-06-15 17:15:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2015-07-27 08:10:18 +00:00
|
|
|
|
if (_updaterVM != null && _updaterVM.IsUpdatePending)
|
|
|
|
|
{
|
|
|
|
|
if (_updaterVM.InstallUpdateCommand.CanExecute(null))
|
|
|
|
|
_updaterVM.InstallUpdateCommand.Execute(null);
|
|
|
|
|
}
|
2015-08-18 07:00:26 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Globals.ThisAddIn.Application.Caption = _oldCaption;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
2015-06-15 17:15:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-26 12:50:05 +00:00
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public Ribbon Ribbon
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_ribbon == null)
|
|
|
|
|
{
|
|
|
|
|
_ribbon = new Ribbon();
|
|
|
|
|
}
|
|
|
|
|
return _ribbon;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Ribbon
|
|
|
|
|
|
|
|
|
|
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
|
|
|
|
|
{
|
|
|
|
|
return Ribbon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2015-07-27 08:10:18 +00:00
|
|
|
|
#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<ViewModelMessageContent> e)
|
|
|
|
|
{
|
|
|
|
|
UpdaterViewModel uvm = e.Content.ViewModel as UpdaterViewModel;
|
|
|
|
|
uvm.DestinationFolder = System.IO.Path.GetTempPath();
|
|
|
|
|
uvm.DownloadUpdateCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2015-07-26 12:50:05 +00:00
|
|
|
|
|
2015-07-27 20:14:18 +00:00
|
|
|
|
#region Exception handler
|
|
|
|
|
|
|
|
|
|
void CentralHandler_ManageExceptionCallback(object sender, Bovender.ExceptionHandler.ManageExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.IsHandled = true;
|
|
|
|
|
ExceptionViewModel vm = new ExceptionViewModel(e.Exception);
|
|
|
|
|
vm.InjectInto<ExceptionView>().ShowDialog();
|
|
|
|
|
}
|
2015-08-04 00:43:17 +00:00
|
|
|
|
|
2015-07-27 20:14:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2015-07-26 12:50:05 +00:00
|
|
|
|
#region Private fields
|
|
|
|
|
|
2015-07-27 08:10:18 +00:00
|
|
|
|
Ribbon _ribbon;
|
|
|
|
|
UpdaterViewModel _updaterVM;
|
2015-08-18 07:00:26 +00:00
|
|
|
|
string _oldCaption;
|
2015-07-26 12:50:05 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2015-06-15 17:15:52 +00:00
|
|
|
|
#region VSTO generated code
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required method for Designer support - do not modify
|
|
|
|
|
/// the contents of this method with the code editor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InternalStartup()
|
|
|
|
|
{
|
|
|
|
|
this.Startup += new System.EventHandler(ThisAddIn_Startup);
|
|
|
|
|
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|