Skip to content

Commit

Permalink
added import settings feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkadySK committed Jan 3, 2022
1 parent 295a8dc commit 23aa573
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async Task SaveToTheme()

#region Restore

void RunRegFile(string path)
public void RunRegFile(string path)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "reg.exe";
Expand Down
40 changes: 37 additions & 3 deletions RestoreWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -20,6 +22,8 @@ namespace AdvancedWindowsAppearence
public partial class RestoreWindow : Window
{
GeneralViewModel Settings;
readonly string savePath = Environment.CurrentDirectory + @"\Exported Settings";

public RestoreWindow(GeneralViewModel generalViewModel)
{
InitializeComponent();
Expand Down Expand Up @@ -90,8 +94,38 @@ private void RadioButton_Click(object sender, RoutedEventArgs e)
private async void exportToReg_Click(object sender, RoutedEventArgs e)
{
await Settings.ExportToReg();
string savedPath = Environment.CurrentDirectory + @"\Exported Settings";
MessageBox.Show(("Export was successful!\nThe exported file is saved in: " + savedPath + Environment.NewLine + "You can restore the settings just by opening the settings-export file."), "Export Finished", MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show(("Export was successful!\nThe exported file is saved in: " + savePath + Environment.NewLine + "You can restore the settings just by opening the settings-export file."), "Export Finished", MessageBoxButton.OK, MessageBoxImage.Information);
}

private void openRestoreFolder_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "explorer";
startInfo.Arguments = savePath;
Process.Start(startInfo);
}

private void importReg_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "registry files|*.reg";
dialog.Title = "Choose a restore file";
dialog.InitialDirectory = savePath;

var result = dialog.ShowDialog();

if (result.Value == false)
return;

string fileName = dialog.SafeFileName;
Settings.RunRegFile(savePath + "\\" + fileName);

var confirmResult = MessageBox.Show("Are you sure to load settings from this file?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (confirmResult == MessageBoxResult.No)
return;

MessageBox.Show("Settings restored successfully. \n\nThe program will now close. You should restart the device to apply changes.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
App.Current.Shutdown();
}
}
}

0 comments on commit 23aa573

Please sign in to comment.