2026-06-28 11:12:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2026-06-28 11:45:45 +08:00
|
|
|
|
using BetterSeewo.Manager.Services.Conversion;
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace BetterSeewo.Manager.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CustomConversionService : IConversionService
|
|
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
private readonly ConversionEngine _engine = new();
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task<string> ConvertPptxToEnbxAsync(string pptxPath)
|
|
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
return await _engine.ConvertPptxToEnbxAsync(pptxPath);
|
2026-06-28 11:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> ConvertEnbxToPptxAsync(string enbxPath)
|
|
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
return await _engine.ConvertEnbxToPptxAsync(enbxPath);
|
2026-06-28 11:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task FixConversionErrorsAsync()
|
|
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
_engine.FixConversionErrors();
|
2026-06-28 11:12:26 +08:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
public async Task<string> BatchConvertAsync(string[] inputPaths, string outputDir, bool toEnbx)
|
2026-06-28 11:12:26 +08:00
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
int success = 0;
|
|
|
|
|
|
int failed = 0;
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
if (!Directory.Exists(outputDir))
|
|
|
|
|
|
Directory.CreateDirectory(outputDir);
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
foreach (var input in inputPaths)
|
2026-06-28 11:12:26 +08:00
|
|
|
|
{
|
2026-06-28 11:45:45 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var fileName = Path.GetFileNameWithoutExtension(input);
|
|
|
|
|
|
var ext = toEnbx ? ".enbx" : ".pptx";
|
|
|
|
|
|
var output = Path.Combine(outputDir, fileName + ext);
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
if (toEnbx)
|
|
|
|
|
|
await _engine.ConvertPptxToEnbxAsync(input);
|
|
|
|
|
|
else
|
|
|
|
|
|
await _engine.ConvertEnbxToPptxAsync(input);
|
2026-06-28 11:12:26 +08:00
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
success++;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
failed++;
|
|
|
|
|
|
}
|
2026-06-28 11:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-28 11:45:45 +08:00
|
|
|
|
return $"批量转换完成,成功: {success},失败: {failed}";
|
2026-06-28 11:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|