From 1b7c8b2b3a0d271c4abd0caf1d33a9e9a1f11d35 Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Tue, 11 Mar 2025 11:37:28 +0000 Subject: [PATCH] add an export theme button --- .../Settings/Pages/AppearancePage.xaml | 5 ++- .../Settings/AppearanceViewModel.cs | 45 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Bloxstrap/UI/Elements/Settings/Pages/AppearancePage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/AppearancePage.xaml index 70ed555..3463389 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/AppearancePage.xaml +++ b/Bloxstrap/UI/Elements/Settings/Pages/AppearancePage.xaml @@ -99,9 +99,12 @@ + + - + + diff --git a/Bloxstrap/UI/ViewModels/Settings/AppearanceViewModel.cs b/Bloxstrap/UI/ViewModels/Settings/AppearanceViewModel.cs index 1f5f359..e4ca73f 100644 --- a/Bloxstrap/UI/ViewModels/Settings/AppearanceViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Settings/AppearanceViewModel.cs @@ -4,13 +4,13 @@ using System.Windows.Controls; using System.Windows.Input; using CommunityToolkit.Mvvm.Input; +using ICSharpCode.SharpZipLib.Zip; using Microsoft.Win32; using Bloxstrap.UI.Elements.Settings; using Bloxstrap.UI.Elements.Editor; using Bloxstrap.UI.Elements.Dialogs; -using System.Xml.Linq; namespace Bloxstrap.UI.ViewModels.Settings { @@ -25,6 +25,7 @@ namespace Bloxstrap.UI.ViewModels.Settings public ICommand DeleteCustomThemeCommand => new RelayCommand(DeleteCustomTheme); public ICommand RenameCustomThemeCommand => new RelayCommand(RenameCustomTheme); public ICommand EditCustomThemeCommand => new RelayCommand(EditCustomTheme); + public ICommand ExportCustomThemeCommand => new RelayCommand(ExportCustomTheme); private void PreviewBootstrapper() { @@ -225,6 +226,48 @@ namespace Bloxstrap.UI.ViewModels.Settings new BootstrapperEditorWindow(SelectedCustomTheme).ShowDialog(); } + private void ExportCustomTheme() + { + if (SelectedCustomTheme is null) + return; + + var dialog = new SaveFileDialog + { + FileName = $"{SelectedCustomTheme}.zip", + Filter = $"{Strings.FileTypes_ZipArchive}|*.zip" + }; + + if (dialog.ShowDialog() != true) + return; + + string themeDir = Path.Combine(Paths.CustomThemes, SelectedCustomTheme); + + using var memStream = new MemoryStream(); + using var zipStream = new ZipOutputStream(memStream); + + foreach (var filePath in Directory.EnumerateFiles(themeDir, "*.*", SearchOption.AllDirectories)) + { + string relativePath = filePath[(themeDir.Length + 1)..]; + + var entry = new ZipEntry(relativePath); + entry.DateTime = DateTime.Now; + + zipStream.PutNextEntry(entry); + + using var fileStream = File.OpenRead(filePath); + fileStream.CopyTo(zipStream); + } + + zipStream.CloseEntry(); + zipStream.Finish(); + memStream.Position = 0; + + using var outputStream = File.OpenWrite(dialog.FileName); + memStream.CopyTo(outputStream); + + Process.Start("explorer.exe", $"/select,\"{dialog.FileName}\""); + } + private void PopulateCustomThemes() { string? selected = App.Settings.Prop.SelectedCustomTheme;