100 lines
3.3 KiB
C#
100 lines
3.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BetterEN5.Services
|
|
{
|
|
public class ConversionService : IConversionService
|
|
{
|
|
public async Task<string> ConvertPptxToEnbxAsync(string pptxPath)
|
|
{
|
|
if (!File.Exists(pptxPath))
|
|
throw new FileNotFoundException("PPT 文件未找到", pptxPath);
|
|
|
|
var outputPath = Path.ChangeExtension(pptxPath, ".enbx");
|
|
|
|
var converterProcess = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
|
"Seewo", "EasiNote5", "EasiNote5_5.2.4.9855", "Main",
|
|
"EasiNote.OfficeDocumentConverter.exe");
|
|
|
|
if (File.Exists(converterProcess))
|
|
{
|
|
var psi = new ProcessStartInfo
|
|
{
|
|
FileName = converterProcess,
|
|
Arguments = $"\"{pptxPath}\" \"{outputPath}\"",
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
};
|
|
using var proc = Process.Start(psi);
|
|
if (proc != null)
|
|
{
|
|
await proc.WaitForExitAsync();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new FileNotFoundException("转换器未找到,请确认希沃白板安装完整", converterProcess);
|
|
}
|
|
|
|
return outputPath;
|
|
}
|
|
|
|
public async Task<string> ConvertEnbxToPptxAsync(string enbxPath)
|
|
{
|
|
if (!File.Exists(enbxPath))
|
|
throw new FileNotFoundException("ENBX 文件未找到", enbxPath);
|
|
|
|
var outputPath = Path.ChangeExtension(enbxPath, ".pptx");
|
|
|
|
var exporterProcess = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
|
"Seewo", "EasiNote5", "EasiNote5_5.2.4.9855", "Main",
|
|
"EasiNote.OfficeDocumentConverter.exe");
|
|
|
|
if (File.Exists(exporterProcess))
|
|
{
|
|
var psi = new ProcessStartInfo
|
|
{
|
|
FileName = exporterProcess,
|
|
Arguments = $"\"{enbxPath}\" \"{outputPath}\" /export",
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
};
|
|
using var proc = Process.Start(psi);
|
|
if (proc != null)
|
|
{
|
|
await proc.WaitForExitAsync();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new FileNotFoundException("转换器未找到,请确认希沃白板安装完整", exporterProcess);
|
|
}
|
|
|
|
return outputPath;
|
|
}
|
|
|
|
public async Task FixConversionErrorsAsync()
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
var en5Path = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
"Seewo", "EasiNote5");
|
|
|
|
if (Directory.Exists(en5Path))
|
|
{
|
|
var tempDir = Path.Combine(en5Path, "Temp", "Conversion");
|
|
if (Directory.Exists(tempDir))
|
|
{
|
|
try { Directory.Delete(tempDir, true); } catch { }
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|