Settings backup and restore (#20551)

* Merge and conflict resolution

* Messages good, backup/restore algo better.

* Start of "GetExportVerion"

* fixed spelling

* New backup/restore mode working.

* Rename a project

* Removed test project

* Switch to text.json

* Renamed BackupAndSync to BackupAndRestore

* Added IgnoredPTRunSettings and full merge

* Restored "fixed" settings that change for no reason

* Various UI updates.

* speling

* Some cleanup and zip support.

* Merge and clean

* code clean up

* code clean up

* code clean up

* Smarter settings compare and merge.

* config based file include/exclude

* Removed some "words"

* Code clean up

* cleanup

* cleanup

* cleanup

* cleanup

* fixed spelling.

* Fixed clean up 1

* more clean up

* Trying to add ptb as an OK word

* Some UI updates.

* UI tweaks and PR review items.

* UI tweaks

* Merge conflicts resolved.

* Added CurrentSettingMatchText

* PR review updates.

* Removed weird file.

* Review updates and fixes

* More UI tweaks.

* UI tweaks

* Set default backup location to "%USERPROFILE%\\Documents\\PowerToys\\Backup"

* settings ui tweaks

* Added ExpanderContentSettingStyle

* fix missing config file

* fix missing config file, part 2

* update ui, cleanup cope

* update ui, cleanup code - Part2

* update method comments

* code cleanup and adjust Backup message time

* fix changing backup location on empty Regsitry

* fix select location - part 2

* location input box min-width

* remove lastRestoreDate from ViewModel

* Code or backup timing, and error handling.

* Should fix file/folder name crash.

* Progress to instance class for backup/restore

* Persist backup status state, added refresh button.

* Better auto check for settings status

* Some UI/text updates.

* Clean up

* Added prefix for "General_Settings" to resources

* Code review updates.

* Code review changes.

* Changed to FolderPicker per review

* Fixed issue with early delete of cleanup.

* Testing issues with FolderPicker

* Removed WinForm req and fixed win10 issue.

* Review update.

* Review changes.

Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
Jeff Lord
2022-10-13 03:41:21 -04:00
committed by GitHub
parent 79e037eef4
commit ee904ae1b1
17 changed files with 1981 additions and 53 deletions

View File

@@ -14,6 +14,7 @@
<converters:BoolToVisibilityConverter x:Key="VisibleIfTrueConverter"/>
<converters:BoolNegationConverter x:Key="NegationConverter"/>
<localConverters:UpdateStateToBoolConverter x:Key="UpdateStateToBoolConverter" />
<localConverters:StringToInfoBarSeverityConverter x:Key="StringToInfoBarSeverityConverter"/>
</Page.Resources>
<controls:SettingsPageControl x:Uid="General"
@@ -24,11 +25,11 @@
<controls:Setting Header="{Binding PowerToysVersion}" Icon="&#xE895;">
<controls:Setting.Description>
<StackPanel Orientation="Vertical">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run x:Uid="General_VersionLastChecked" />
<Run Text="{Binding UpdateCheckedDate, Mode=OneWay}"/>
</TextBlock>
</TextBlock>
<HyperlinkButton x:Uid="ReleaseNotes"
NavigateUri="https://github.com/microsoft/PowerToys/releases/"
Margin="0,2,0,0"/>
@@ -76,7 +77,7 @@
Command="{Binding UpdateNowButtonEventHandler}"
IsEnabled="{Binding IsDownloadAllowed, Mode=OneWay}"
Visibility="{Binding Mode=OneWay, Path=IsNewVersionDownloading, Converter={StaticResource NegationConverter}}"/>
<!-- In progress panel -->
<StackPanel Visibility="{Binding Mode=OneWay, Path=IsNewVersionDownloading, Converter={StaticResource VisibleIfTrueConverter}}"
Orientation="Horizontal"
@@ -137,7 +138,7 @@
Command="{Binding UpdateNowButtonEventHandler}"
IsEnabled="{Binding IsDownloadAllowed, Mode=OneWay}"
Visibility="{Binding Mode=OneWay, Path=IsNewVersionDownloading, Converter={StaticResource NegationConverter}}"/>
<!-- In progress panel -->
<StackPanel Visibility="{Binding Mode=OneWay, Path=IsNewVersionDownloading, Converter={StaticResource VisibleIfTrueConverter}}"
Orientation="Horizontal"
@@ -167,7 +168,7 @@
<ToggleSwitch IsOn="{Binding Mode=TwoWay, Path=AutoDownloadUpdates}" x:Uid="ToggleSwitch"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
</controls:SettingsGroup>
@@ -207,26 +208,179 @@
<controls:SettingsGroup IsEnabled="True" x:Uid="ShortcutGuide_Appearance_Behavior">
<controls:Setting x:Uid="ColorModeHeader" Icon="&#xE790;">
<controls:Setting.Description>
<HyperlinkButton Click="OpenColorsSettings_Click"
<controls:Setting.Description>
<HyperlinkButton Click="OpenColorsSettings_Click"
x:Uid="Windows_Color_Settings"/>
</controls:Setting.Description>
<controls:Setting.ActionContent>
<ComboBox SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.ThemeIndex}" MinWidth="{StaticResource SettingActionControlMinWidth}">
<ComboBoxItem x:Uid="Radio_Theme_Dark"/>
<ComboBoxItem x:Uid="Radio_Theme_Light"/>
<ComboBoxItem x:Uid="Radio_Theme_Default"/>
</ComboBox>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:Setting.Description>
<controls:Setting.ActionContent>
<ComboBox SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.ThemeIndex}" MinWidth="{StaticResource SettingActionControlMinWidth}">
<ComboBoxItem x:Uid="Radio_Theme_Dark"/>
<ComboBoxItem x:Uid="Radio_Theme_Light"/>
<ComboBoxItem x:Uid="Radio_Theme_Default"/>
</ComboBox>
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="GeneralPage_RunAtStartUp">
<controls:Setting.ActionContent>
<ToggleSwitch IsOn="{Binding Mode=TwoWay, Path=Startup}" x:Uid="ToggleSwitch"/>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
<!-- Start General_SettingsBackupAndRestore -->
<controls:SettingsGroup x:Uid="General_SettingsBackupAndRestoreTitle" Visibility="Visible">
<controls:SettingExpander IsExpanded="True">
<controls:SettingExpander.Header>
<controls:Setting x:Uid="General_SettingsBackupAndRestore" Icon="&#xE777;" Style="{StaticResource ExpanderHeaderSettingStyle}">
<controls:Setting.Description>
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run x:Uid="General_SettingsBackupAndRestoreDescription" />
</TextBlock>
</controls:Setting.Description>
<controls:Setting.ActionContent>
<Grid Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Uid="General_SettingsBackupAndRestore_ButtonBackup"
Command="{Binding BackupConfigsEventHandler}"
IsEnabled="True"
Visibility="Visible"
HorizontalAlignment="Right"/>
<Button Grid.Column="2" x:Uid="General_SettingsBackupAndRestore_ButtonRestore"
Command="{Binding RestoreConfigsEventHandler}"
IsEnabled="True"
Visibility="Visible"
HorizontalAlignment="Right"/>
</Grid>
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingExpander.Header>
<controls:SettingExpander.Content>
<StackPanel Orientation="Vertical">
<controls:Setting x:Uid="General_SettingsBackupAndRestoreLocationText" Visibility="Visible" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
<Grid Padding="10,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock MaxWidth="350" Grid.Row="0" Grid.Column="1" Text="{x:Bind Mode=TwoWay, Path=ViewModel.SettingsBackupAndRestoreDir}" IsTextSelectionEnabled="True" MinWidth="350" />
<Button Grid.Row="0" Grid.Column="2" x:Uid="General_SettingsBackupAndRestore_ButtonSelectLocation"
Command="{Binding SelectSettingBackupDirEventHandler}"
IsEnabled="True"
Visibility="Visible"
HorizontalAlignment="Left"/>
</Grid>
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="General_SettingsBackupAndRestoreStatusInfo" Visibility="Visible" Style="{StaticResource ExpanderContentSettingStyle}"/>
<StackPanel>
<Grid Padding="55,0,10,10">
<Grid.Resources >
<Style TargetType="Border" >
<Setter Property="Padding" Value="2,0,5,0" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.Column="0">
<TextBlock Style="{StaticResource HeaderTextStyle}">
<Run x:Uid="General_SettingsBackupInfo_DateHeader" />
</TextBlock>
</Border>
<Border Grid.Row="0" Grid.Column="1">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run Text="{Binding LastSettingsBackupDate, Mode=OneWay}"/>
</TextBlock>
</Border>
<Border Grid.Row="1" Grid.Column="0">
<TextBlock Style="{StaticResource HeaderTextStyle}">
<Run x:Uid="General_SettingsBackupInfo_StatusHeader" />
</TextBlock>
</Border>
<Border Grid.Row="1" Grid.Column="1">
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run Text="{Binding CurrentSettingMatchText, Mode=OneWay}"/>
</TextBlock>
<TextBlock Padding="5,0,0,0" Style="{StaticResource SecondaryTextStyle}"><Hyperlink Click="UpdateBackupAndRestoreStatusText" TextDecorations="Underline">
<Run x:Uid="General_SettingsBackupAndRestore_LinkRefresh" />
</Hyperlink></TextBlock>
</StackPanel>
</Border>
<Border Grid.Row="2" Grid.Column="0">
<TextBlock Style="{StaticResource HeaderTextStyle}">
<Run x:Uid="General_SettingsBackupInfo_SourceHeader" />
</TextBlock>
</Border>
<Border Grid.Row="2" Grid.Column="1">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run Text="{Binding LastSettingsBackupSource, Mode=OneWay}"/>
</TextBlock>
</Border>
<Border Grid.Row="3" Grid.Column="0">
<TextBlock Style="{StaticResource HeaderTextStyle}">
<Run x:Uid="General_SettingsBackupInfo_FileNameHeader" />
</TextBlock>
</Border>
<Border Grid.Row="3" Grid.Column="1">
<TextBlock Style="{StaticResource SecondaryTextStyle}">
<Run Text="{Binding LastSettingsBackupFileName, Mode=OneWay}"/>
</TextBlock>
</Border>
</Grid>
</StackPanel>
</StackPanel>
</controls:SettingExpander.Content>
</controls:SettingExpander>
</controls:SettingsGroup>
<InfoBar x:Uid="General_SettingsBackupMessageResults"
IsClosable="False"
Severity="{Binding BackupRestoreMessageSeverity, Converter={StaticResource StringToInfoBarSeverityConverter}}"
IsTabStop="{Binding SettingsBackupRestoreMessageVisible, Mode=OneWay}"
IsOpen="{Binding SettingsBackupRestoreMessageVisible, Mode=OneWay}"
Title="{Binding SettingsBackupMessage}"/>
<!-- End General_SettingsBackupAndRestore -->
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>
<controls:PageLink x:Uid="GeneralPage_Documentation" Link="https://aka.ms/PowerToysOverview"/>

View File

@@ -3,12 +3,17 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.Resources;
using Windows.Storage;
using Windows.Storage.Pickers;
namespace Microsoft.PowerToys.Settings.UI.Views
{
@@ -17,6 +22,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// </summary>
public sealed partial class GeneralPage : Page
{
private static DateTime OkToHideBackupAndRestoreMessageTime { get; set; }
/// <summary>
/// Gets or sets view model.
/// </summary>
@@ -42,6 +49,25 @@ namespace Microsoft.PowerToys.Settings.UI.Views
});
};
Action hideBackupAndRestoreMessageArea = () =>
{
this.DispatcherQueue.TryEnqueue(async () =>
{
const int messageShowTimeIs = 10000;
// in order to keep the message for about 5 seconds after the last call
// and not need any lock/thread-synch, use an OK-To-Hide time, and wait just a little longer than that.
OkToHideBackupAndRestoreMessageTime = DateTime.UtcNow.AddMilliseconds(messageShowTimeIs - 16);
await System.Threading.Tasks.Task.Delay(messageShowTimeIs);
if (DateTime.UtcNow > OkToHideBackupAndRestoreMessageTime)
{
ViewModel.HideBackupAndRestoreMessageArea();
}
});
};
var doRefreshBackupRestoreStatus = new Action<int>(RefreshBackupRestoreStatus);
ViewModel = new GeneralViewModel(
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
loader.GetString("GeneralSettings_RunningAsAdminText"),
@@ -53,9 +79,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
ShellPage.SendRestartAdminIPCMessage,
ShellPage.SendCheckForUpdatesIPCMessage,
string.Empty,
stateUpdatingAction);
stateUpdatingAction,
hideBackupAndRestoreMessageArea,
doRefreshBackupRestoreStatus,
PickSingleFolderDialog,
loader);
DataContext = ViewModel;
doRefreshBackupRestoreStatus(100);
}
public static int UpdateUIThemeMethod(string themeName)
@@ -84,5 +116,38 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{
Helpers.StartProcessHelper.Start(Helpers.StartProcessHelper.ColorsSettings);
}
private void RefreshBackupRestoreStatus(int delayMs = 0)
{
Task.Run(() =>
{
if (delayMs > 0)
{
Thread.Sleep(delayMs);
}
var settingsBackupAndRestoreUtils = SettingsBackupAndRestoreUtils.Instance;
var results = settingsBackupAndRestoreUtils.DryRunBackup();
this.DispatcherQueue.TryEnqueue(() =>
{
ViewModel.NotifyAllBackupAndRestoreProperties();
});
});
}
private void UpdateBackupAndRestoreStatusText(Microsoft.UI.Xaml.Documents.Hyperlink sender, Microsoft.UI.Xaml.Documents.HyperlinkClickEventArgs args)
{
RefreshBackupRestoreStatus();
}
private async Task<string> PickSingleFolderDialog()
{
var openPicker = new FolderPicker();
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.GetSettingsWindow());
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hwnd);
openPicker.FileTypeFilter.Add("*");
var folder = await openPicker.PickSingleFolderAsync();
return folder?.Path;
}
}
}