mirror of
https://github.com/ckaczor/ProcessCpuUsageStatusWindow.git
synced 2026-02-07 01:25:40 -05:00
Workaround for Settings.Upgrade with Squirrel
This commit is contained in:
@@ -16,14 +16,7 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (Settings.Default.FirstRun)
|
SquirrelAwareApp.HandleEvents(onAppUpdate: version => SettingsExtensions.RestoreSettings());
|
||||||
{
|
|
||||||
Settings.Default.Upgrade();
|
|
||||||
Settings.Default.FirstRun = false;
|
|
||||||
Settings.Default.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
SquirrelAwareApp.HandleEvents();
|
|
||||||
|
|
||||||
var application = new App();
|
var application = new App();
|
||||||
application.InitializeComponent();
|
application.InitializeComponent();
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
<HintPath>packages\squirrel.windows.1.7.9\lib\Net45\Squirrel.dll</HintPath>
|
<HintPath>packages\squirrel.windows.1.7.9\lib\Net45\Squirrel.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<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>
|
<HintPath>packages\FloatingStatusWindow.1.0.0.9\lib\net45\System.Windows.Interactivity.dll</HintPath>
|
||||||
@@ -129,6 +130,7 @@
|
|||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="SettingsExtensions.cs" />
|
||||||
<Compile Include="WindowSource.cs" />
|
<Compile Include="WindowSource.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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;
|
return;
|
||||||
|
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
|
SettingsExtensions.BackupSettings();
|
||||||
|
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
await updateManager.DownloadReleases(new[] { lastVersion });
|
await updateManager.DownloadReleases(new[] { lastVersion });
|
||||||
await updateManager.ApplyReleases(updates);
|
await updateManager.ApplyReleases(updates);
|
||||||
await updateManager.UpdateApp();
|
await updateManager.UpdateApp();
|
||||||
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user