using System; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using Microsoft.Win32; using BetterEN5.Services; namespace BetterEN5.UI { public partial class BetterSeewoMainWindow : Window { private readonly InkService _inkService = new(); private readonly ActivationService _activationService = new(); private readonly PatchService _patchService = new(); public BetterSeewoMainWindow() { InitializeComponent(); Loaded += OnLoaded; } private async void OnLoaded(object sender, RoutedEventArgs e) { await RefreshInstallStatusAsync(); } private void NavChanged(object sender, RoutedEventArgs e) { if (sender == NavInstall) ShowPanel(PanelInstall); else if (sender == NavInk) ShowPanel(PanelInk); else if (sender == NavConvert) ShowPanel(PanelConvert); else if (sender == NavTouch) ShowPanel(PanelTouch); else if (sender == NavActivate) ShowPanel(PanelActivate); } private void ShowPanel(StackPanel panel) { foreach (var p in new[] { PanelInstall, PanelInk, PanelConvert, PanelTouch, PanelActivate }) p.Visibility = p == panel ? Visibility.Visible : Visibility.Collapsed; } private async Task RefreshInstallStatusAsync() { var installed = await Task.Run(() => _patchService.IsInstalled()); InstallBtn.IsEnabled = !installed; UninstallBtn.IsEnabled = installed; InstallStatusText.Text = installed ? "✅ 补丁已安装" : "⚠️ 补丁未安装"; if (installed) { var m = await Task.Run(() => _patchService.GetManifest()); PatchDetailText.Text = $"版本: {m.Version} | 安装时间: {m.InstallTime} | 备份文件: {m.Backups.Count} 个 | 注册表项: {m.RegistryKeys.Count} 个"; } else { PatchDetailText.Text = "尚未安装补丁。点击「安装补丁」将备份关键配置并应用增强补丁。"; } } private async void InstallPatch_Click(object s, RoutedEventArgs e) { var progress = new Progress(msg => { Dispatcher.Invoke(() => PatchDetailText.Text = msg); }); InstallBtn.IsEnabled = false; UninstallBtn.IsEnabled = false; InstallStatusText.Text = "⏳ 正在安装..."; try { await _patchService.InstallAsync(progress); InstallStatusText.Text = "✅ 补丁已安装"; UninstallBtn.IsEnabled = true; } catch (Exception ex) { InstallStatusText.Text = "❌ 安装失败"; PatchDetailText.Text = ex.Message; InstallBtn.IsEnabled = true; } } private async void UninstallPatch_Click(object s, RoutedEventArgs e) { var result = MessageBox.Show(this, "确定要卸载 Better-Seewo 补丁吗?\n将还原备份文件并清除注册表修改。", "卸载确认", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result != MessageBoxResult.Yes) return; var progress = new Progress(msg => { Dispatcher.Invoke(() => PatchDetailText.Text = msg); }); InstallBtn.IsEnabled = false; UninstallBtn.IsEnabled = false; InstallStatusText.Text = "⏳ 正在卸载..."; try { await _patchService.UninstallAsync(progress); InstallStatusText.Text = "✅ 补丁已卸载"; InstallBtn.IsEnabled = true; PatchDetailText.Text = "卸载完成。建议重启希沃白板。"; } catch (Exception ex) { InstallStatusText.Text = "❌ 卸载失败"; PatchDetailText.Text = ex.Message; UninstallBtn.IsEnabled = true; } } private void Minimize_Click(object s, RoutedEventArgs e) => WindowState = WindowState.Minimized; private void Maximize_Click(object s, RoutedEventArgs e) => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; private void Close_Click(object s, RoutedEventArgs e) => Close(); private async void ExportInk_Click(object s, RoutedEventArgs e) { var dialog = new SaveFileDialog { Title = "导出墨迹", Filter = "墨迹文件|*.ink.json|JSON|*.json", DefaultExt = ".ink.json" }; if (dialog.ShowDialog() == true) { await ProgressDialog.Show(this, "导出墨迹", async p => { p.UpdateStatus("正在导出墨迹...", "读取课件笔迹数据"); await _inkService.ExportInkAsync(dialog.FileName); p.UpdateStatus("导出完成", $"已保存至 {Path.GetFileName(dialog.FileName)}"); }); InkStatus.Text = $"已导出: {Path.GetFileName(dialog.FileName)}"; } } private async void ImportInk_Click(object s, RoutedEventArgs e) { var dialog = new OpenFileDialog { Title = "导入墨迹", Filter = "墨迹文件|*.ink.json|JSON|*.json" }; if (dialog.ShowDialog() == true) { await ProgressDialog.Show(this, "导入墨迹", async p => { p.UpdateStatus("正在导入墨迹...", "写入课件笔迹"); await _inkService.ImportInkAsync(dialog.FileName); }); InkStatus.Text = "墨迹已导入"; } } private async void ConvertPptx_Click(object s, RoutedEventArgs e) { var dialog = new OpenFileDialog { Title = "选择 PPT", Filter = "PowerPoint|*.pptx" }; if (dialog.ShowDialog() == true) { await ProgressDialog.Show(this, "转换文件", async p => { p.UpdateStatus("正在转换 PPT → ENBX...", "调用转换器"); var result = await new ConversionService().ConvertPptxToEnbxAsync(dialog.FileName); p.UpdateStatus("转换完成", Path.GetFileName(result)); }); } } private async void ConvertEnbx_Click(object s, RoutedEventArgs e) { var dialog = new OpenFileDialog { Title = "选择 ENBX", Filter = "希沃课件|*.enbx" }; if (dialog.ShowDialog() == true) { await ProgressDialog.Show(this, "转换文件", async p => { p.UpdateStatus("正在转换 ENBX → PPT...", "调用转换器"); var result = await new ConversionService().ConvertEnbxToPptxAsync(dialog.FileName); p.UpdateStatus("导出完成", Path.GetFileName(result)); }); } } private async void CheckTouch_Click(object s, RoutedEventArgs e) { var ok = await Task.Run(() => TouchFixService.IsTouchWorkingCorrectly()); TouchStatus.Text = ok ? "✅ IWB 模式已启用" : "⚠️ 未启用 IWB 模式"; } private async void ApplyTouchFix_Click(object s, RoutedEventArgs e) { await ProgressDialog.Show(this, "触摸修复", async p => { p.UpdateStatus("正在写入注册表配置...", "ForceIWB"); await Task.Run(() => TouchFixService.ApplyFixAsync()); p.UpdateStatus("正在配置 IWB 模式...", "IWBConfig.json"); await Task.Delay(300); p.UpdateStatus("完成", "请重启希沃白板生效"); }); TouchStatus.Text = "修复已应用,请重启"; } private async void ActivatePro_Click(object s, RoutedEventArgs e) { var dlg = new ActivateDialog(); dlg.Owner = this; if (dlg.ShowDialog() == true) { await ProgressDialog.Show(this, "激活", async p => { p.UpdateStatus("正在验证激活码...", ""); var ok = await _activationService.ActivateProfessionalAsync(dlg.LicenseKey); if (ok) { p.UpdateStatus("激活成功", "专业版已启用"); ActivationStatusText.Text = "✅ 专业版已激活"; } else { p.UpdateStatus("激活失败", "激活码无效"); } }); } } private async void LaunchInstaller_Click(object s, RoutedEventArgs e) { var ok = await _activationService.LaunchBen5InstallerAsync(); if (!ok) MessageBox.Show(this, "未找到注册补丁安装程序", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } private async void CheckActivation_Click(object s, RoutedEventArgs e) { var info = await Task.Run(() => _activationService.GetCurrentStatus()); ActivationStatusText.Text = info.IsProfessional ? $"✅ 专业版 · {info.LastActivationDate}" : "🔓 社区版"; } public static void ShowWindow() { Application.Current.Dispatcher.Invoke(() => { var w = Application.Current.Windows.OfType().FirstOrDefault(); if (w != null) { w.Activate(); return; } new BetterSeewoMainWindow().Show(); }); } } }