Move settings backup/restore to Common

This commit is contained in:
2018-02-22 14:23:30 -05:00
parent 359ff583db
commit 9342c28ce8
7 changed files with 27 additions and 67 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "Common"]
path = Common
url = https://github.com/ckaczor/Common.git

View File

@@ -1,9 +1,9 @@
using FloatingStatusWindowLibrary; using FloatingStatusWindowLibrary;
using ProcessCpuUsageStatusWindow.Properties; using ProcessCpuUsageStatusWindow.Properties;
using Squirrel;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;
using Squirrel;
namespace ProcessCpuUsageStatusWindow namespace ProcessCpuUsageStatusWindow
{ {
@@ -16,7 +16,7 @@ namespace ProcessCpuUsageStatusWindow
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
SquirrelAwareApp.HandleEvents(onAppUpdate: version => SettingsExtensions.RestoreSettings()); SquirrelAwareApp.HandleEvents(onAppUpdate: version => Common.Settings.Extensions.RestoreSettings());
var application = new App(); var application = new App();
application.InitializeComponent(); application.InitializeComponent();

1
Common Submodule

Submodule Common added at ecd3717eab

View File

@@ -130,7 +130,6 @@
<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>
@@ -170,6 +169,12 @@
<None Include="README.md" /> <None Include="README.md" />
<None Include="Resources\ApplicationIcon.ico" /> <None Include="Resources\ApplicationIcon.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="Common\Common.csproj">
<Project>{17864d82-457d-4a0a-bc10-1d07f2b3a5d6}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessCpuUsageStatusWindow", "ProcessCpuUsageStatusWindow.csproj", "{C3C29363-2E3C-4478-B2A6-125DEA683E0D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessCpuUsageStatusWindow", "ProcessCpuUsageStatusWindow.csproj", "{C3C29363-2E3C-4478-B2A6-125DEA683E0D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,18 @@ Global
{C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x64.Build.0 = Release|Any CPU {C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x64.Build.0 = Release|Any CPU
{C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x86.ActiveCfg = Release|Any CPU {C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x86.ActiveCfg = Release|Any CPU
{C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x86.Build.0 = Release|Any CPU {C3C29363-2E3C-4478-B2A6-125DEA683E0D}.Release|x86.Build.0 = Release|Any CPU
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x64.ActiveCfg = Debug|x64
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x64.Build.0 = Debug|x64
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x86.ActiveCfg = Debug|x86
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x86.Build.0 = Debug|x86
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|Any CPU.Build.0 = Release|Any CPU
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x64.ActiveCfg = Release|x64
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x64.Build.0 = Release|x64
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x86.ActiveCfg = Release|x86
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,63 +0,0 @@
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);
}
}
}
}

View File

@@ -45,7 +45,7 @@ namespace ProcessCpuUsageStatusWindow
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating)); _dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
Thread.Sleep(500); Thread.Sleep(500);
SettingsExtensions.BackupSettings(); Common.Settings.Extensions.BackupSettings();
#if !DEBUG #if !DEBUG
await updateManager.DownloadReleases(new[] { lastVersion }); await updateManager.DownloadReleases(new[] { lastVersion });