mirror of
https://github.com/ckaczor/ProcessCpuUsageStatusWindow.git
synced 2026-01-13 17:23:02 -05:00
Workaround for Settings.Upgrade with Squirrel
This commit is contained in:
@@ -16,14 +16,7 @@ namespace ProcessCpuUsageStatusWindow
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
if (Settings.Default.FirstRun)
|
||||
{
|
||||
Settings.Default.Upgrade();
|
||||
Settings.Default.FirstRun = false;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
||||
SquirrelAwareApp.HandleEvents();
|
||||
SquirrelAwareApp.HandleEvents(onAppUpdate: version => SettingsExtensions.RestoreSettings());
|
||||
|
||||
var application = new App();
|
||||
application.InitializeComponent();
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
<HintPath>packages\squirrel.windows.1.7.9\lib\Net45\Squirrel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>packages\FloatingStatusWindow.1.0.0.9\lib\net45\System.Windows.Interactivity.dll</HintPath>
|
||||
@@ -129,6 +130,7 @@
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SettingsExtensions.cs" />
|
||||
<Compile Include="WindowSource.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
63
SettingsExtensions.cs
Normal file
63
SettingsExtensions.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ProcessCpuUsageStatusWindow
|
||||
{
|
||||
public static class SettingsExtensions
|
||||
{
|
||||
public static void BackupSettings()
|
||||
{
|
||||
Debugger.Launch();
|
||||
|
||||
var settingsFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
|
||||
var destination = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\last.config";
|
||||
File.Copy(settingsFile, destination, true);
|
||||
}
|
||||
|
||||
public static void RestoreSettings()
|
||||
{
|
||||
Debugger.Launch();
|
||||
|
||||
var destFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
|
||||
var sourceFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\last.config";
|
||||
|
||||
if (!File.Exists(sourceFile))
|
||||
return;
|
||||
|
||||
var destDirectory = Path.GetDirectoryName(destFile);
|
||||
|
||||
if (destDirectory == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(destDirectory);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Copy(sourceFile, destFile, true);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(sourceFile);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,14 +43,14 @@ namespace ProcessCpuUsageStatusWindow
|
||||
return;
|
||||
|
||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
||||
Thread.Sleep(1000);
|
||||
Thread.Sleep(500);
|
||||
|
||||
SettingsExtensions.BackupSettings();
|
||||
|
||||
#if !DEBUG
|
||||
await updateManager.DownloadReleases(new[] { lastVersion });
|
||||
await updateManager.ApplyReleases(updates);
|
||||
await updateManager.UpdateApp();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user