feat: 管理器支持深浅主题切换,发布 exe

- 新增 LightTheme.xaml 浅色主题资源
- 标题栏添加主题切换按钮(☀️/🌙)
- Manager 支持深浅主题互换
- 发布 Manager.exe (292KB) 和 Installer.exe (171KB)
- 插件安装包 Better-Seewo.2.0.0.exe (11.6MB)
This commit is contained in:
雾启工作室
2026-06-28 12:43:17 +08:00
parent fb7b924c0d
commit 65d61b44d9
12 changed files with 432 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
using System;
namespace BetterEN5.Services.Conversion;
public class ConversionEngine
{
private readonly PptxImporter _importer = new();
private readonly EnbxWriter _writer = new();
public bool Convert(string pptxPath, string enbxPath)
{
try
{
var doc = _importer.Import(pptxPath);
_writer.Write(doc, enbxPath);
return true;
}
catch (Exception ex)
{
Console.Error.WriteLine($"Conversion failed: {ex}");
return false;
}
}
}

View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
namespace BetterEN5.Services.Conversion;
public class DocumentModel
{
public string Title { get; set; } = "";
public string Author { get; set; } = "";
public long SlideWidth { get; set; } = 12192000;
public long SlideHeight { get; set; } = 6858000;
public List<SlideModel> Slides { get; set; } = new();
}
public class SlideModel
{
public string Name { get; set; } = "";
public long Width { get; set; }
public long Height { get; set; }
public List<ElementModel> Elements { get; set; } = new();
}
public abstract class ElementModel
{
}
public class TextElement : ElementModel
{
public string Text { get; set; } = "";
public long X { get; set; }
public long Y { get; set; }
public long Width { get; set; }
public long Height { get; set; }
public string FontName { get; set; } = "微软雅黑";
public double FontSize { get; set; } = 18;
public string FontColor { get; set; } = "#FF000000";
public bool IsBold { get; set; }
}
public class ImageElement : ElementModel
{
public byte[]? Data { get; set; }
public string ContentType { get; set; } = "image/png";
public string FileName { get; set; } = "";
public long X { get; set; }
public long Y { get; set; }
public long Width { get; set; }
public long Height { get; set; }
}
public class ShapeElement : ElementModel
{
public long X { get; set; }
public long Y { get; set; }
public long Width { get; set; }
public long Height { get; set; }
}

View File

@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Xml.Linq;
namespace BetterEN5.Services.Conversion;
public class EnbxWriter
{
private static readonly XNamespace En = "http://schemas.seewo.com/easinote/2016/document";
private static readonly XNamespace Dc = "http://purl.org/dc/elements/1.1/";
public void Write(DocumentModel doc, string outputPath)
{
if (File.Exists(outputPath)) File.Delete(outputPath);
using var package = Package.Open(outputPath, FileMode.Create);
var docPart = package.CreatePart(
PackUriHelper.CreatePartUri(new Uri("/document.xml", UriKind.Relative)),
"application/xml");
var slideTargets = new List<string>();
int slideIndex = 0;
foreach (var slide in doc.Slides)
{
slideIndex++;
var slideName = $"slides/slide{slideIndex}.xml";
slideTargets.Add(slideName);
var slidePart = package.CreatePart(
PackUriHelper.CreatePartUri(new Uri($"/{slideName}", UriKind.Relative)),
"application/xml");
int imgIdx = 0;
foreach (var elem in slide.Elements)
{
if (elem is ImageElement img && img.Data != null && img.Data.Length > 0)
{
imgIdx++;
var ext = Path.GetExtension(img.FileName);
if (string.IsNullOrEmpty(ext)) ext = ".png";
var mediaName = $"media/{Guid.NewGuid():N}{ext}";
var imagePart = package.CreatePart(
PackUriHelper.CreatePartUri(new Uri($"/{mediaName}", UriKind.Relative)),
img.ContentType);
using (var s = imagePart.GetStream())
s.Write(img.Data, 0, img.Data.Length);
slidePart.CreateRelationship(
PackUriHelper.CreatePartUri(new Uri($"/{mediaName}", UriKind.Relative)),
TargetMode.Internal,
"http://schemas.seewo.com/easinote/relationships/image",
$"r{imgIdx}");
img.FileName = mediaName;
}
}
WriteSlideXml(slidePart, slide);
docPart.CreateRelationship(
PackUriHelper.CreatePartUri(new Uri($"/{slideName}", UriKind.Relative)),
TargetMode.Internal,
"http://schemas.seewo.com/easinote/relationships/slide",
$"r{slideIndex}");
}
WriteDocumentXml(docPart, doc, slideTargets);
package.CreateRelationship(
PackUriHelper.CreatePartUri(new Uri("/document.xml", UriKind.Relative)),
TargetMode.Internal,
"http://schemas.seewo.com/easinote/relationships/document",
"rId1");
}
private void WriteDocumentXml(PackagePart docPart, DocumentModel doc, List<string> slideTargets)
{
var docXml = new XDocument(
new XElement(En + "Document",
new XAttribute(XNamespace.Xmlns + "en", En.NamespaceName),
new XAttribute(XNamespace.Xmlns + "dc", Dc.NamespaceName),
new XElement(En + "Properties",
new XElement(En + "Title", doc.Title),
new XElement(En + "Author", doc.Author),
new XElement(En + "Created", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")),
new XElement(En + "Application", "Better-Seewo"),
new XElement(En + "Version", "5.2.4.9855"),
new XElement(En + "SlideWidth", doc.SlideWidth),
new XElement(En + "SlideHeight", doc.SlideHeight)),
new XElement(En + "Slides",
slideTargets.Select((t, i) =>
new XElement(En + "Slide",
new XAttribute("RId", $"r{i + 1}"),
new XAttribute("Source", t))))));
using var stream = docPart.GetStream(FileMode.Create);
docXml.Save(stream);
}
private void WriteSlideXml(PackagePart slidePart, SlideModel slide)
{
var elems = new List<XElement>();
int imgIdx = 0;
foreach (var e in slide.Elements)
{
switch (e)
{
case TextElement t:
elems.Add(new XElement(En + "TextElement",
new XAttribute("X", t.X),
new XAttribute("Y", t.Y),
new XAttribute("Width", t.Width),
new XAttribute("Height", t.Height),
new XAttribute("FontSize", t.FontSize),
new XAttribute("IsBold", t.IsBold),
new XAttribute("FontName", t.FontName),
new XAttribute("FontColor", t.FontColor),
new XElement(En + "Text", t.Text)));
break;
case ImageElement img:
imgIdx++;
elems.Add(new XElement(En + "ImageElement",
new XAttribute("X", img.X),
new XAttribute("Y", img.Y),
new XAttribute("Width", img.Width),
new XAttribute("Height", img.Height),
new XAttribute("Source", img.FileName),
new XAttribute("RId", $"r{imgIdx}")));
break;
}
}
var slideXml = new XDocument(
new XElement(En + "Slide",
new XAttribute(XNamespace.Xmlns + "en", En.NamespaceName),
new XAttribute("Width", slide.Width),
new XAttribute("Height", slide.Height),
new XElement(En + "Elements", elems)));
using var stream = slidePart.GetStream(FileMode.Create);
slideXml.Save(stream);
}
}

View File

@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using D = DocumentFormat.OpenXml.Drawing;
namespace BetterEN5.Services.Conversion;
public class PptxImporter
{
public DocumentModel Import(string pptxPath)
{
var doc = new DocumentModel();
using var presentation = PresentationDocument.Open(pptxPath, false);
var presPart = presentation.PresentationPart!;
var pres = presPart.Presentation;
var slideSize = pres.SlideSize!;
doc.SlideWidth = slideSize.Cx!.Value;
doc.SlideHeight = slideSize.Cy!.Value;
int slideIndex = 0;
foreach (var slideId in pres.SlideIdList!.ChildElements.OfType<SlideId>())
{
slideIndex++;
var slidePart = presPart.GetPartById(slideId.RelationshipId!) as SlidePart;
if (slidePart == null) continue;
var slide = slidePart.Slide;
var slideModel = new SlideModel
{
Name = $"Slide{slideIndex}",
Width = doc.SlideWidth,
Height = doc.SlideHeight
};
ParseSlideElements(slidePart, slide, slideModel, doc);
doc.Slides.Add(slideModel);
}
return doc;
}
private void ParseSlideElements(SlidePart slidePart, Slide slide, SlideModel slideModel, DocumentModel doc)
{
if (slide.CommonSlideData?.ShapeTree == null) return;
foreach (var element in slide.CommonSlideData.ShapeTree.ChildElements)
{
switch (element)
{
case Picture pic:
ParsePicture(slidePart, pic, slideModel);
break;
case Shape shape:
ParseShape(shape, slideModel);
break;
}
}
}
private void ParsePicture(SlidePart slidePart, Picture pic, SlideModel slideModel)
{
var blipFill = pic.BlipFill;
if (blipFill?.Blip == null) return;
var embed = blipFill.Blip.Embed?.Value;
if (string.IsNullOrEmpty(embed)) return;
var imagePart = slidePart.GetPartById(embed) as ImagePart;
if (imagePart == null) return;
using var stream = imagePart.GetStream();
var data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
var transform = pic.ShapeProperties?.Transform2D;
var img = new ImageElement
{
Data = data,
ContentType = imagePart.ContentType,
FileName = $"image{slideModel.Elements.Count + 1}{GetExtension(imagePart.ContentType)}",
X = transform?.Offset?.X?.Value ?? 0,
Y = transform?.Offset?.Y?.Value ?? 0,
Width = transform?.Extents?.Cx?.Value ?? 0,
Height = transform?.Extents?.Cy?.Value ?? 0
};
slideModel.Elements.Add(img);
}
private void ParseShape(Shape shape, SlideModel slideModel)
{
var textBody = shape.TextBody;
if (textBody == null) return;
var text = string.Concat(
textBody.Descendants<D.Text>().Select(t => t.Text));
if (string.IsNullOrWhiteSpace(text)) return;
var transform = shape.ShapeProperties?.Transform2D;
var textElem = new TextElement
{
Text = text.Trim(),
X = transform?.Offset?.X?.Value ?? 0,
Y = transform?.Offset?.Y?.Value ?? 0,
Width = transform?.Extents?.Cx?.Value ?? 0,
Height = transform?.Extents?.Cy?.Value ?? 0
};
var firstRun = textBody.Descendants<D.Run>().FirstOrDefault();
if (firstRun?.RunProperties != null)
{
var rp = firstRun.RunProperties;
textElem.FontSize = (rp.FontSize?.Value ?? 1800) / 100.0;
textElem.IsBold = rp.Bold?.Value ?? false;
var solidFill = rp.GetFirstChild<D.SolidFill>();
if (solidFill?.RgbColorModelHex?.Val?.Value != null)
textElem.FontColor = $"#{solidFill.RgbColorModelHex.Val.Value}";
else if (solidFill?.SchemeColor?.Val?.Value != null)
textElem.FontColor = $"#{solidFill.SchemeColor.Val}";
}
slideModel.Elements.Add(textElem);
}
private static string GetExtension(string contentType)
{
return contentType switch
{
"image/png" => ".png",
"image/jpeg" => ".jpg",
"image/gif" => ".gif",
"image/bmp" => ".bmp",
"image/tiff" => ".tiff",
_ => ".bin"
};
}
}

View File

@@ -57,7 +57,12 @@
<TextBlock Text="Better-Seewo" FontSize="18" FontWeight="SemiBold" Foreground="{StaticResource AccentBrush}" VerticalAlignment="Center"/>
<TextBlock Text=" 管理器" FontSize="14" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock Text="v2.0.0" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
<TextBlock Text="v2.0.0" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" Margin="0,0,12,0"/>
<Button x:Name="BtnThemeToggle" Content="🌙" Width="28" Height="28" FontSize="14"
Background="Transparent" Foreground="{StaticResource TextPrimaryBrush}" BorderThickness="0"
Cursor="Hand" Click="BtnThemeToggle_Click"/>
</StackPanel>
</Grid>
</Border>

View File

@@ -1,3 +1,4 @@
using System;
using System.Windows;
using System.Windows.Controls;
@@ -5,18 +6,42 @@ namespace BetterSeewoManager;
public partial class MainWindow : Window
{
private bool _isDarkTheme = true;
public MainWindow()
{
InitializeComponent();
ContentFrame.Navigate(new System.Uri("Pages/InstallPage.xaml", System.UriKind.Relative));
ApplyTheme();
ContentFrame.Navigate(new Uri("Pages/InstallPage.xaml", UriKind.Relative));
}
private void Tab_Click(object sender, RoutedEventArgs e)
{
if (sender is RadioButton rb && rb.Tag is string pageName)
{
var pageUri = new System.Uri($"Pages/{pageName}.xaml", System.UriKind.Relative);
var pageUri = new Uri($"Pages/{pageName}.xaml", UriKind.Relative);
ContentFrame.Navigate(pageUri);
}
}
private void BtnThemeToggle_Click(object sender, RoutedEventArgs e)
{
_isDarkTheme = !_isDarkTheme;
ApplyTheme();
}
private void ApplyTheme()
{
var app = (App)Application.Current;
app.Resources.MergedDictionaries.Clear();
app.Resources.MergedDictionaries.Add(new ResourceDictionary
{
Source = new Uri(_isDarkTheme
? "Themes/DarkTheme.xaml"
: "Themes/LightTheme.xaml", UriKind.Relative)
});
BtnThemeToggle.Content = _isDarkTheme ? "☀️" : "🌙";
StatusText.Text = _isDarkTheme ? "已切换到深色主题" : "已切换到浅色主题";
}
}

View File

@@ -0,0 +1,25 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="BackgroundBrush" Color="#F5F5F5"/>
<SolidColorBrush x:Key="SurfaceBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="CardBrush" Color="#FAFAFA"/>
<SolidColorBrush x:Key="BorderBrush" Color="#E0E0E0"/>
<SolidColorBrush x:Key="TextPrimaryBrush" Color="#1A1A1A"/>
<SolidColorBrush x:Key="TextSecondaryBrush" Color="#666666"/>
<SolidColorBrush x:Key="AccentBrush" Color="#7C6BF0"/>
<SolidColorBrush x:Key="AccentHoverBrush" Color="#6A5AD8"/>
<SolidColorBrush x:Key="SuccessBrush" Color="#4CAF50"/>
<SolidColorBrush x:Key="WarningBrush" Color="#FF9800"/>
<SolidColorBrush x:Key="DangerBrush" Color="#F44336"/>
<SolidColorBrush x:Key="TabActiveBrush" Color="#7C6BF0"/>
<SolidColorBrush x:Key="TabInactiveBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="ButtonSecondaryBrush" Color="#E8E8E8"/>
<CornerRadius x:Key="CornerRadiusSmall">4</CornerRadius>
<CornerRadius x:Key="CornerRadiusMedium">8</CornerRadius>
<CornerRadius x:Key="CornerRadiusLarge">12</CornerRadius>
<FontFamily x:Key="DefaultFont">Microsoft YaHei UI, Segoe UI</FontFamily>
</ResourceDictionary>

View File

@@ -23,6 +23,10 @@ if (success)
{
var rel = f.Substring(tmp.Length + 1);
Console.WriteLine($" {rel} ({new FileInfo(f).Length} bytes)");
if (rel.EndsWith(".xml"))
{
Console.WriteLine($" {File.ReadAllText(f)[..Math.Min(200, File.ReadAllText(f).Length)]}");
}
}
Directory.Delete(tmp, true);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.