284 lines
11 KiB
C#
284 lines
11 KiB
C#
|
|
using System;
|
||
|
|
using System.Diagnostics;
|
||
|
|
using System.IO;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows;
|
||
|
|
using Microsoft.Win32;
|
||
|
|
using Cvte.EasiNote;
|
||
|
|
using BetterEN5.Services;
|
||
|
|
|
||
|
|
namespace BetterEN5.UI
|
||
|
|
{
|
||
|
|
public partial class SettingsWindow : Window
|
||
|
|
{
|
||
|
|
private readonly InkService _inkService = new();
|
||
|
|
private readonly ConversionService _conversionService = new();
|
||
|
|
|
||
|
|
public SettingsWindow()
|
||
|
|
{
|
||
|
|
InitializeComponent();
|
||
|
|
Loaded += OnLoaded;
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void OnLoaded(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
LoadSettings();
|
||
|
|
await RefreshTouchStatusAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void LoadSettings()
|
||
|
|
{
|
||
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||
|
|
var settingsFile = Path.Combine(localAppData, "Seewo", "EasiNote5", "BetterEN5", "settings.json");
|
||
|
|
if (File.Exists(settingsFile))
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var json = File.ReadAllText(settingsFile);
|
||
|
|
var settings = System.Text.Json.JsonSerializer.Deserialize<SettingsData>(json);
|
||
|
|
if (settings != null)
|
||
|
|
{
|
||
|
|
AutoSaveInkCheckBox.IsChecked = settings.AutoSaveInk;
|
||
|
|
IncludeShapeInkCheckBox.IsChecked = settings.IncludeShapeInk;
|
||
|
|
ForceIWBModeCheckBox.IsChecked = settings.ForceIWB;
|
||
|
|
SkipTouchCheckCheckBox.IsChecked = settings.SkipTouchCheck;
|
||
|
|
SuppressTouchErrorsCheckBox.IsChecked = settings.SuppressTouchErrors;
|
||
|
|
EnableFallbackModeCheckBox.IsChecked = settings.EnableFallbackMode;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch { }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SaveSettings()
|
||
|
|
{
|
||
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||
|
|
var dir = Path.Combine(localAppData, "Seewo", "EasiNote5", "BetterEN5");
|
||
|
|
var settingsFile = Path.Combine(dir, "settings.json");
|
||
|
|
|
||
|
|
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
||
|
|
|
||
|
|
var settings = new SettingsData
|
||
|
|
{
|
||
|
|
AutoSaveInk = AutoSaveInkCheckBox.IsChecked ?? false,
|
||
|
|
IncludeShapeInk = IncludeShapeInkCheckBox.IsChecked ?? false,
|
||
|
|
ForceIWB = ForceIWBModeCheckBox.IsChecked ?? true,
|
||
|
|
SkipTouchCheck = SkipTouchCheckCheckBox.IsChecked ?? true,
|
||
|
|
SuppressTouchErrors = SuppressTouchErrorsCheckBox.IsChecked ?? true,
|
||
|
|
EnableFallbackMode = EnableFallbackModeCheckBox.IsChecked ?? true,
|
||
|
|
};
|
||
|
|
|
||
|
|
var json = System.Text.Json.JsonSerializer.Serialize(settings, new System.Text.Json.JsonSerializerOptions
|
||
|
|
{
|
||
|
|
WriteIndented = true
|
||
|
|
});
|
||
|
|
File.WriteAllText(settingsFile, json);
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ExportInk_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
var dialog = new SaveFileDialog
|
||
|
|
{
|
||
|
|
Title = "导出墨迹",
|
||
|
|
Filter = "墨迹文件|*.ink.json|JSON 文件|*.json|所有文件|*.*",
|
||
|
|
DefaultExt = ".ink.json"
|
||
|
|
};
|
||
|
|
|
||
|
|
if (dialog.ShowDialog() == true)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await _inkService.ExportInkAsync(dialog.FileName);
|
||
|
|
InkStatusText.Text = $"墨迹已导出至: {dialog.FileName}";
|
||
|
|
InkStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
InkStatusText.Text = $"导出失败: {ex.Message}";
|
||
|
|
InkStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ImportInk_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
var dialog = new OpenFileDialog
|
||
|
|
{
|
||
|
|
Title = "导入墨迹",
|
||
|
|
Filter = "墨迹文件|*.ink.json|JSON 文件|*.json|所有文件|*.*",
|
||
|
|
DefaultExt = ".ink.json"
|
||
|
|
};
|
||
|
|
|
||
|
|
if (dialog.ShowDialog() == true)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await _inkService.ImportInkAsync(dialog.FileName);
|
||
|
|
InkStatusText.Text = "墨迹已导入";
|
||
|
|
InkStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
InkStatusText.Text = $"导入失败: {ex.Message}";
|
||
|
|
InkStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SaveInkSettings_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
SaveSettings();
|
||
|
|
InkStatusText.Text = "墨迹设置已保存";
|
||
|
|
InkStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ConvertPptx_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
var dialog = new OpenFileDialog
|
||
|
|
{
|
||
|
|
Title = "选择 PowerPoint 文件",
|
||
|
|
Filter = "PowerPoint 文件|*.pptx|所有文件|*.*"
|
||
|
|
};
|
||
|
|
|
||
|
|
if (dialog.ShowDialog() == true)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var result = await _conversionService.ConvertPptxToEnbxAsync(dialog.FileName);
|
||
|
|
ConversionStatusText.Text = $"转换完成: {result}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ConversionStatusText.Text = $"转换失败: {ex.Message}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ConvertEnbx_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
var dialog = new OpenFileDialog
|
||
|
|
{
|
||
|
|
Title = "选择希沃白板课件",
|
||
|
|
Filter = "希沃课件|*.enbx|所有文件|*.*"
|
||
|
|
};
|
||
|
|
|
||
|
|
if (dialog.ShowDialog() == true)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var result = await _conversionService.ConvertEnbxToPptxAsync(dialog.FileName);
|
||
|
|
ConversionStatusText.Text = $"导出完成: {result}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ConversionStatusText.Text = $"导出失败: {ex.Message}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ClearConversionCache_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await _conversionService.FixConversionErrorsAsync();
|
||
|
|
ConversionStatusText.Text = "转换缓存已清理";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ConversionStatusText.Text = $"清理失败: {ex.Message}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ReRegisterConverter_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var converterPath = Path.Combine(
|
||
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
||
|
|
"Seewo", "EasiNote5", "EasiNote5_5.2.4.9855", "Main",
|
||
|
|
"EasiNote.OfficeDocumentConverter.exe");
|
||
|
|
|
||
|
|
if (File.Exists(converterPath))
|
||
|
|
{
|
||
|
|
Process.Start(converterPath, "/register");
|
||
|
|
await Task.Delay(1000);
|
||
|
|
ConversionStatusText.Text = "转换器已重新注册";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ConversionStatusText.Text = "未找到转换器";
|
||
|
|
}
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ConversionStatusText.Text = $"注册失败: {ex.Message}";
|
||
|
|
ConversionStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void CheckTouch_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
await RefreshTouchStatusAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void ApplyTouchFix_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
await TouchFixService.ApplyFixAsync();
|
||
|
|
TouchStatusText.Text = "触摸修复已应用,请重启希沃白板生效";
|
||
|
|
TouchStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
SaveSettings();
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
TouchStatusText.Text = $"修复失败: {ex.Message}";
|
||
|
|
TouchStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SaveTouchSettings_Click(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
SaveSettings();
|
||
|
|
TouchStatusText.Text = "触摸设置已保存";
|
||
|
|
TouchStatusText.Foreground = System.Windows.Media.Brushes.Green;
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task RefreshTouchStatusAsync()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var isIwb = await Task.Run(() => TouchFixService.IsTouchWorkingCorrectly());
|
||
|
|
TouchStatusText.Text = isIwb
|
||
|
|
? "触摸状态: 正常 (IWB 模式已启用)"
|
||
|
|
: "触摸状态: 非 IWB 模式 (可能存在问题)";
|
||
|
|
TouchStatusText.Foreground = isIwb
|
||
|
|
? System.Windows.Media.Brushes.Green
|
||
|
|
: System.Windows.Media.Brushes.Orange;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
TouchStatusText.Text = $"无法检测触摸状态: {ex.Message}";
|
||
|
|
TouchStatusText.Foreground = System.Windows.Media.Brushes.Red;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private class SettingsData
|
||
|
|
{
|
||
|
|
public bool AutoSaveInk { get; set; }
|
||
|
|
public bool IncludeShapeInk { get; set; }
|
||
|
|
public bool ForceIWB { get; set; } = true;
|
||
|
|
public bool SkipTouchCheck { get; set; } = true;
|
||
|
|
public bool SuppressTouchErrors { get; set; } = true;
|
||
|
|
public bool EnableFallbackMode { get; set; } = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|