Add config import and export

This commit is contained in:
Ray Berezowski
2026-06-02 21:28:59 -04:00
parent 835ce2159b
commit b0fc1b4679
3 changed files with 153 additions and 8 deletions

View File

@@ -636,6 +636,77 @@ public partial class MainWindow : Window
}
}
private void ExportConfig_Click(object sender, RoutedEventArgs e)
{
if (controller is null)
{
return;
}
ApplyConfigFields();
using SaveFileDialog dialog = new()
{
Title = "Export launcher config",
Filter = "JSON config files|*.json|All files|*.*",
FileName = $"TaskbarLauncher-config-{DateTime.Now:yyyyMMdd-HHmmss}.json",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
try
{
string exportPath = ConfigService.ExportTo(dialog.FileName, controller.Config);
StatusText.Text = $"Exported config to {exportPath}";
}
catch (Exception ex)
{
MessageBox.Show($"Could not export config.\n\n{ex.Message}", "Taskbar Launcher");
}
}
private void ImportConfig_Click(object sender, RoutedEventArgs e)
{
using OpenFileDialog dialog = new()
{
Title = "Import launcher config",
Filter = "JSON config files|*.json|All files|*.*",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
MessageBoxResult result = MessageBox.Show(
"Import this config file and replace the current launcher config?\n\nA local backup will be created first.",
"Taskbar Launcher",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result != MessageBoxResult.Yes)
{
return;
}
try
{
string backupPath = ConfigService.Backup();
ConfigService.ImportFrom(dialog.FileName);
controller?.ReloadConfig();
RefreshView();
StatusText.Text = $"Imported config from {dialog.FileName}. Previous config backed up to {backupPath}";
}
catch (Exception ex)
{
MessageBox.Show($"Could not import config.\n\n{ex.Message}", "Taskbar Launcher");
}
}
private List<int>? FindItemPath(LauncherItem item)
{
if (controller is null)