mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-13 17:22:48 -05:00
Move update message logic to common and remove restarting on update (installer will do that)
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
using System;
|
||||
using Common.Debug;
|
||||
using Common.Helpers;
|
||||
using Common.IO;
|
||||
using Common.Settings;
|
||||
using Common.Wpf.Extensions;
|
||||
using FeedCenter.Properties;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Microsoft.Win32;
|
||||
|
||||
using Common.Debug;
|
||||
using Common.Helpers;
|
||||
using Common.IO;
|
||||
using Common.Wpf.Extensions;
|
||||
using Common.Settings;
|
||||
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
@@ -20,13 +17,7 @@ namespace FeedCenter
|
||||
{
|
||||
#region Debug properties
|
||||
|
||||
public static bool UseDebugPath;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public bool Restart;
|
||||
private static bool _useDebugPath;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,12 +26,14 @@ namespace FeedCenter
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
_useDebugPath = Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1;
|
||||
|
||||
// Create and initialize the app object
|
||||
App app = new App();
|
||||
var app = new App();
|
||||
app.InitializeComponent();
|
||||
|
||||
// Create an isolation handle to see if we are already running
|
||||
IDisposable isolationHandle = ApplicationIsolation.GetIsolationHandle(FeedCenter.Properties.Resources.ApplicationName);
|
||||
var isolationHandle = ApplicationIsolation.GetIsolationHandle(FeedCenter.Properties.Resources.ApplicationName);
|
||||
|
||||
// If there is another copy then pass it the command line and exit
|
||||
if (isolationHandle == null)
|
||||
@@ -54,7 +47,7 @@ namespace FeedCenter
|
||||
{
|
||||
// Set the data directory based on debug or not
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory",
|
||||
UseDebugPath
|
||||
_useDebugPath
|
||||
? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
||||
: UserSettingsPath);
|
||||
|
||||
@@ -87,35 +80,21 @@ namespace FeedCenter
|
||||
}
|
||||
|
||||
// Create the main window before the splash otherwise WPF gets messed up
|
||||
MainWindow mainWindow = new MainWindow();
|
||||
var mainWindow = new MainWindow();
|
||||
|
||||
// Show the splash window
|
||||
SplashWindow splashWindow = new SplashWindow();
|
||||
var splashWindow = new SplashWindow();
|
||||
splashWindow.ShowDialog();
|
||||
|
||||
// If we don't need to restart then fire up the main window
|
||||
if (!app.Restart)
|
||||
{
|
||||
// Update the registry settings
|
||||
SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||
SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
||||
// Update the registry settings
|
||||
SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||
SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
||||
|
||||
// Initialize the window
|
||||
mainWindow.Initialize();
|
||||
// Initialize the window
|
||||
mainWindow.Initialize();
|
||||
|
||||
// Run the app
|
||||
app.Run(mainWindow);
|
||||
}
|
||||
|
||||
// If we need to restart
|
||||
if (app.Restart)
|
||||
{
|
||||
// Wait a bit to make sure any previous upgrade has settled
|
||||
Thread.Sleep(2000);
|
||||
|
||||
// Restart the application
|
||||
Current.Restart();
|
||||
}
|
||||
// Run the app
|
||||
app.Run(mainWindow);
|
||||
|
||||
// Terminate the tracer
|
||||
Tracer.Dispose();
|
||||
@@ -143,11 +122,11 @@ namespace FeedCenter
|
||||
get
|
||||
{
|
||||
// If we're running in debug mode then use a local path for the database and logs
|
||||
if (UseDebugPath)
|
||||
if (_useDebugPath)
|
||||
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
// Get the path to the local application data directory
|
||||
string path = Path.Combine(
|
||||
var path = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
FeedCenter.Properties.Resources.ApplicationName);
|
||||
|
||||
@@ -162,13 +141,13 @@ namespace FeedCenter
|
||||
public static void SetStartWithWindows(bool value)
|
||||
{
|
||||
// Get the application name
|
||||
string applicationName = FeedCenter.Properties.Resources.ApplicationDisplayName;
|
||||
var applicationName = FeedCenter.Properties.Resources.ApplicationDisplayName;
|
||||
|
||||
// Get application details
|
||||
string publisherName = applicationName;
|
||||
string productName = applicationName;
|
||||
string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
||||
string shortcutPath = Path.Combine(allProgramsPath, publisherName);
|
||||
var publisherName = applicationName;
|
||||
var productName = applicationName;
|
||||
var allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
||||
var shortcutPath = Path.Combine(allProgramsPath, publisherName);
|
||||
|
||||
// Build the auto start path
|
||||
shortcutPath = "\"" + Path.Combine(shortcutPath, productName) + ".appref-ms\"";
|
||||
@@ -180,10 +159,10 @@ namespace FeedCenter
|
||||
public static void SetDefaultFeedReader(bool value)
|
||||
{
|
||||
// Get the location of the assembly
|
||||
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||
|
||||
// Open the registry key (creating if needed)
|
||||
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
using (var registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
{
|
||||
if (registryKey == null)
|
||||
return;
|
||||
@@ -193,7 +172,7 @@ namespace FeedCenter
|
||||
registryKey.SetValue("URL Protocol", string.Empty);
|
||||
|
||||
// Open the icon subkey (creating if needed)
|
||||
using (RegistryKey subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
using (var subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
{
|
||||
if (subKey != null)
|
||||
{
|
||||
@@ -206,7 +185,7 @@ namespace FeedCenter
|
||||
}
|
||||
|
||||
// Open the subkey for the command (creating if needed)
|
||||
using (RegistryKey subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
using (var subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
{
|
||||
if (subKey != null)
|
||||
{
|
||||
|
||||
@@ -66,6 +66,14 @@ namespace FeedCenter
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
// Setup the update message properties and callbacks
|
||||
UpdateCheck.ApplicationName = Properties.Resources.ApplicationDisplayName;
|
||||
UpdateCheck.UpdateServer = Settings.Default.VersionLocation;
|
||||
UpdateCheck.UpdateFile = Settings.Default.VersionFile;
|
||||
UpdateCheck.ApplicationShutdown = ApplicationShutdown;
|
||||
UpdateCheck.ApplicationCurrentMessage = ApplicationCurrentMessage;
|
||||
UpdateCheck.ApplicationUpdateMessage = ApplicationUpdateMessage;
|
||||
|
||||
// Show the notification icon
|
||||
NotificationIcon.Initialize(this);
|
||||
|
||||
@@ -105,6 +113,21 @@ namespace FeedCenter
|
||||
Tracer.WriteLine("MainForm creation finished");
|
||||
}
|
||||
|
||||
private static bool ApplicationUpdateMessage(string title, string message)
|
||||
{
|
||||
return MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes;
|
||||
}
|
||||
|
||||
private static void ApplicationCurrentMessage(string title, string message)
|
||||
{
|
||||
MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
private static void ApplicationShutdown()
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Window overrides
|
||||
@@ -385,7 +408,7 @@ namespace FeedCenter
|
||||
// Increment the index and adjust if we've gone around the end
|
||||
_feedIndex = (_feedIndex + 1) % feedCount;
|
||||
}
|
||||
while (startIndex != _feedIndex);
|
||||
while (_feedIndex != startIndex);
|
||||
|
||||
// If nothing was found then clear the current feed
|
||||
if (!found)
|
||||
@@ -456,7 +479,7 @@ namespace FeedCenter
|
||||
if (_feedIndex < 0)
|
||||
_feedIndex = feedCount - 1;
|
||||
}
|
||||
while (startIndex != _feedIndex);
|
||||
while (_feedIndex != startIndex);
|
||||
|
||||
// If nothing was found then clear the current feed
|
||||
if (!found)
|
||||
@@ -690,7 +713,7 @@ namespace FeedCenter
|
||||
if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval)
|
||||
{
|
||||
// Get the update information
|
||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||
UpdateCheck.CheckForUpdate();
|
||||
|
||||
// Update the last check time
|
||||
Settings.Default.LastVersionCheck = DateTime.Now;
|
||||
@@ -1192,7 +1215,7 @@ namespace FeedCenter
|
||||
|
||||
private void HandleOpenAllToolbarButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var multipleOpenAction = (MultipleOpenAction) _currentFeed.MultipleOpenAction;
|
||||
var multipleOpenAction = _currentFeed.MultipleOpenAction;
|
||||
|
||||
switch (multipleOpenAction)
|
||||
{
|
||||
@@ -1321,7 +1344,7 @@ namespace FeedCenter
|
||||
private void HandleNewVersionLinkClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Display update information
|
||||
VersionCheck.DisplayUpdateInformation(true);
|
||||
UpdateCheck.DisplayUpdateInformation(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace FeedCenter.Options
|
||||
|
||||
applicationNameLabel.Text = Properties.Resources.ApplicationDisplayName;
|
||||
|
||||
string version = UpdateCheck.CurrentVersion.ToString();
|
||||
string version = UpdateCheck.LocalVersion.ToString();
|
||||
versionLabel.Text = string.Format(Properties.Resources.Version, version);
|
||||
|
||||
companyLabel.Text = ((AssemblyCompanyAttribute) Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0]).Company;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace FeedCenter.Options
|
||||
using Common.Update;
|
||||
|
||||
namespace FeedCenter.Options
|
||||
{
|
||||
public partial class UpdateOptionsPanel
|
||||
{
|
||||
@@ -32,7 +34,7 @@
|
||||
|
||||
private void HandleCheckVersionNowButtonClick(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
VersionCheck.DisplayUpdateInformation(true);
|
||||
UpdateCheck.DisplayUpdateInformation(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
Application/Properties/Resources.Designer.cs
generated
42
Application/Properties/Resources.Designer.cs
generated
@@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
// Runtime Version:4.0.30319.34014
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@@ -1360,46 +1360,6 @@ namespace FeedCenter.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An update to version {0} is now available..
|
||||
/// </summary>
|
||||
public static string UpdateAvailable {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateAvailable", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You are already running the most recent version.
|
||||
///
|
||||
///No updates are available at this time..
|
||||
/// </summary>
|
||||
public static string UpdateCheckCurrent {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Version {1} of {0} is now available.
|
||||
///
|
||||
///Would you like to download and install it now?.
|
||||
/// </summary>
|
||||
public static string UpdateCheckNewVersion {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} Update.
|
||||
/// </summary>
|
||||
public static string UpdateCheckTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateCheckTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Version: {0}.
|
||||
/// </summary>
|
||||
|
||||
@@ -184,22 +184,6 @@
|
||||
<data name="ApplicationName" xml:space="preserve">
|
||||
<value>FeedCenter</value>
|
||||
</data>
|
||||
<data name="UpdateCheckNewVersion" xml:space="preserve">
|
||||
<value>Version {1} of {0} is now available.
|
||||
|
||||
Would you like to download and install it now?</value>
|
||||
</data>
|
||||
<data name="UpdateCheckCurrent" xml:space="preserve">
|
||||
<value>You are already running the most recent version.
|
||||
|
||||
No updates are available at this time.</value>
|
||||
</data>
|
||||
<data name="UpdateCheckTitle" xml:space="preserve">
|
||||
<value>{0} Update</value>
|
||||
</data>
|
||||
<data name="UpdateAvailable" xml:space="preserve">
|
||||
<value>An update to version {0} is now available.</value>
|
||||
</data>
|
||||
<data name="FeedAddedNotification" xml:space="preserve">
|
||||
<value>"{0}" has been successfully added to your feed list.</value>
|
||||
</data>
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace FeedCenter
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
|
||||
// Get the version to display
|
||||
string version = UpdateCheck.CurrentVersion.ToString();
|
||||
string version = UpdateCheck.LocalVersion.ToString();
|
||||
|
||||
// Show the version
|
||||
lblVersion.Content = string.Format(Properties.Resources.Version, version);
|
||||
@@ -198,7 +198,7 @@ namespace FeedCenter
|
||||
return false;
|
||||
|
||||
// Return if the check worked and an update is available
|
||||
return UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile) && UpdateCheck.UpdateAvailable;
|
||||
return UpdateCheck.CheckForUpdate() && UpdateCheck.UpdateAvailable;
|
||||
}
|
||||
|
||||
private static bool CheckDatabase()
|
||||
|
||||
@@ -1,111 +1,10 @@
|
||||
using Common.Debug;
|
||||
using Common.Update;
|
||||
using Common.Update;
|
||||
using FeedCenter.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
internal static class VersionCheck
|
||||
{
|
||||
public static async void DisplayUpdateInformation(bool showIfCurrent)
|
||||
{
|
||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||
|
||||
// Check for an update
|
||||
if (UpdateCheck.UpdateAvailable)
|
||||
{
|
||||
// Load the version string from the server
|
||||
Version serverVersion = UpdateCheck.VersionInfo.Version;
|
||||
|
||||
// Format the check title
|
||||
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
||||
|
||||
// Format the message
|
||||
string updateCheckMessage = string.Format(Resources.UpdateCheckNewVersion, Resources.ApplicationDisplayName, serverVersion);
|
||||
|
||||
// Ask the user to update
|
||||
if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
// Get the update
|
||||
await UpdateCheck.DownloadUpdate();
|
||||
|
||||
// Install the update
|
||||
UpdateCheck.InstallUpdate();
|
||||
|
||||
// Set to restart
|
||||
((App) System.Windows.Application.Current).Restart = true;
|
||||
|
||||
// Restart the application
|
||||
System.Windows.Application.Current.Shutdown();
|
||||
}
|
||||
else if (showIfCurrent)
|
||||
{
|
||||
// Format the check title
|
||||
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
||||
|
||||
// Format the message
|
||||
string updateCheckMessage = string.Format(Resources.UpdateCheckCurrent, Resources.ApplicationDisplayName);
|
||||
|
||||
MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
|
||||
#region Background checking
|
||||
|
||||
private static BackgroundWorker _backgroundWorker;
|
||||
|
||||
public static void DisplayUpdateInformationAsync()
|
||||
{
|
||||
// Do nothing if we already have a worker
|
||||
if (_backgroundWorker != null)
|
||||
return;
|
||||
|
||||
// Create a new worker
|
||||
_backgroundWorker = new BackgroundWorker();
|
||||
|
||||
// Setup worker events
|
||||
_backgroundWorker.DoWork += HandleBackgroundWorkerDoWork;
|
||||
_backgroundWorker.RunWorkerCompleted += HandleBackgroundWorkerCompleted;
|
||||
|
||||
// Run the worker
|
||||
_backgroundWorker.RunWorkerAsync();
|
||||
|
||||
// Wait for the worker
|
||||
while (_backgroundWorker.IsBusy)
|
||||
Application.DoEvents();
|
||||
|
||||
// Clear out the worker
|
||||
_backgroundWorker.Dispose();
|
||||
_backgroundWorker = null;
|
||||
}
|
||||
|
||||
private static void HandleBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
e.Result = null;
|
||||
|
||||
try
|
||||
{
|
||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||
|
||||
// Get the update information and set it into the result
|
||||
e.Result = UpdateCheck.UpdateAvailable;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Tracer.WriteException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleBackgroundWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
// Display any update info
|
||||
DisplayUpdateInformation(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user