feat: LD Converter v1.3.0 - FFmpeg auto-install on startup & Pandoc XeLaTeX equation engine
This commit is contained in:
parent
d26fca7680
commit
0bf0aff8f3
20 changed files with 797 additions and 33 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -7,7 +7,7 @@
|
|||
"targets": {
|
||||
".NETCoreApp,Version=v8.0": {},
|
||||
".NETCoreApp,Version=v8.0/win-x64": {
|
||||
"LDConverter/1.2.0": {
|
||||
"LDConverter/1.3.0": {
|
||||
"dependencies": {
|
||||
"Donustur.Core": "1.0.0",
|
||||
"Donustur.Engine": "1.0.0"
|
||||
|
|
@ -157,7 +157,7 @@
|
|||
}
|
||||
},
|
||||
"libraries": {
|
||||
"LDConverter/1.2.0": {
|
||||
"LDConverter/1.3.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -14,5 +14,6 @@ public sealed class AppPreferences
|
|||
public bool AutoOpenOutputFolder { get; set; } = false;
|
||||
public string? CustomFfmpegPath { get; set; }
|
||||
public string? CustomLibreOfficePath { get; set; }
|
||||
public string? CustomPandocPath { get; set; }
|
||||
public int DefaultImageQuality { get; set; } = 85;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public sealed class ConversionDispatcher
|
|||
|
||||
public ConversionDispatcher(AppPreferences preferences, HistoryStore? historyStore = null)
|
||||
{
|
||||
_officeEngine = new OfficeDocumentEngine(preferences.CustomLibreOfficePath);
|
||||
_officeEngine = new OfficeDocumentEngine(preferences.CustomLibreOfficePath, preferences.CustomPandocPath);
|
||||
_mediaEngine = new MediaEngine(preferences.CustomFfmpegPath);
|
||||
_historyStore = historyStore;
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ public sealed class ConversionDispatcher
|
|||
|
||||
// Ayarlar ekranından değiştirilmiş olabilecek harici motor yollarını senkronize et
|
||||
_officeEngine.SetCustomPath(preferences.CustomLibreOfficePath);
|
||||
_officeEngine.SetCustomPandocPath(preferences.CustomPandocPath);
|
||||
_mediaEngine.SetCustomPath(preferences.CustomFfmpegPath);
|
||||
|
||||
if (preferences.DefaultImageQuality is >= 10 and <= 100 && task.Options.ImageQuality == 85)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@ namespace Donustur.Engine.Documents;
|
|||
public sealed class OfficeDocumentEngine
|
||||
{
|
||||
private string? _customPath;
|
||||
private readonly PandocEngine _pandocEngine = new();
|
||||
|
||||
public OfficeDocumentEngine(string? customPath = null)
|
||||
public OfficeDocumentEngine(string? customPath = null, string? customPandocPath = null)
|
||||
{
|
||||
_customPath = customPath;
|
||||
_pandocEngine.SetCustomPath(customPandocPath);
|
||||
}
|
||||
|
||||
public void SetCustomPath(string? customPath)
|
||||
|
|
@ -23,6 +25,13 @@ public sealed class OfficeDocumentEngine
|
|||
_customPath = customPath;
|
||||
}
|
||||
|
||||
public void SetCustomPandocPath(string? customPandocPath)
|
||||
{
|
||||
_pandocEngine.SetCustomPath(customPandocPath);
|
||||
}
|
||||
|
||||
public PandocEngine Pandoc => _pandocEngine;
|
||||
|
||||
/// <summary>
|
||||
/// LibreOffice soffice.exe yolunu bulur.
|
||||
/// </summary>
|
||||
|
|
@ -96,24 +105,36 @@ public sealed class OfficeDocumentEngine
|
|||
|
||||
string? generatedPath = null;
|
||||
|
||||
// 1. Öncelik: LibreOffice kuruluysa izole profil ile çalıştır
|
||||
if (sofficePath != null)
|
||||
// 1. Öncelik: Markdown belgelerinde veya denklem içeren metinlerde Pandoc (XeLaTeX & LaTeX math desteği)
|
||||
if (sourceExt is "md" or "markdown" && _pandocEngine.IsAvailable)
|
||||
{
|
||||
generatedPath = await _pandocEngine.ConvertAsync(inputFile, formatKey, transaction, token);
|
||||
}
|
||||
|
||||
// 2. Öncelik: LibreOffice kuruluysa izole profil ile çalıştır
|
||||
if ((generatedPath == null || !File.Exists(generatedPath)) && sofficePath != null)
|
||||
{
|
||||
generatedPath = await TryConvertWithLibreOfficeAsync(sofficePath, inputFile, formatKey, transaction, token);
|
||||
}
|
||||
|
||||
// 2. Yedek: Yerel dönüştürücü (TXT, MD, HTML, DOCX <-> PDF, DOCX, TXT, HTML)
|
||||
// 3. Pandoc diğer formatlarda da alternatif olarak denenebilir
|
||||
if ((generatedPath == null || !File.Exists(generatedPath)) && _pandocEngine.IsAvailable)
|
||||
{
|
||||
generatedPath = await _pandocEngine.ConvertAsync(inputFile, formatKey, transaction, token);
|
||||
}
|
||||
|
||||
// 4. Yedek: Yerel dönüştürücü (TXT, MD, HTML, DOCX <-> PDF, DOCX, TXT, HTML)
|
||||
if (generatedPath == null || !File.Exists(generatedPath))
|
||||
{
|
||||
if (CanConvertNatively(sourceExt, formatKey))
|
||||
{
|
||||
generatedPath = await Task.Run(() => ConvertNatively(inputFile, sourceExt, formatKey, transaction), token);
|
||||
}
|
||||
else if (sofficePath == null)
|
||||
else if (sofficePath == null && !_pandocEngine.IsAvailable)
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
$"'{sourceExt.ToUpperInvariant()} → {formatKey.ToUpperInvariant()}' dönüşümü için LibreOffice gereklidir. " +
|
||||
"Lütfen LibreOffice'i yükleyin (www.libreoffice.org) veya Ayarlar ekranından soffice.exe yolunu belirtin.");
|
||||
$"'{sourceExt.ToUpperInvariant()} → {formatKey.ToUpperInvariant()}' dönüşümü için LibreOffice veya Pandoc gereklidir. " +
|
||||
"Lütfen LibreOffice ya da Pandoc yükleyin veya Ayarlar ekranından soffice.exe / pandoc.exe yolunu belirtin.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -242,7 +263,9 @@ public sealed class OfficeDocumentEngine
|
|||
sb.AppendLine(" <meta charset=\"UTF-8\">");
|
||||
sb.AppendLine(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
|
||||
sb.AppendLine($" <title>{WebUtility.HtmlEncode(title)}</title>");
|
||||
sb.AppendLine(" <style>body{font-family:'Segoe UI',system-ui,sans-serif;line-height:1.6;max-width:800px;margin:40px auto;padding:0 20px;color:#1f2937;background:#ffffff;}p{margin:0 0 12px 0;white-space:pre-wrap;}</style>");
|
||||
sb.AppendLine(" <style>body{font-family:'Segoe UI',system-ui,sans-serif;line-height:1.6;max-width:800px;margin:40px auto;padding:0 20px;color:#1f2937;background:#ffffff;}p{margin:0 0 12px 0;white-space:pre-wrap;}code{background:#f3f4f6;padding:2px 6px;border-radius:4px;font-family:monospace;}</style>");
|
||||
sb.AppendLine(" <script>window.MathJax = { tex: { inlineMath: [['$', '$'], ['\\\\(', '\\\\)']] } };</script>");
|
||||
sb.AppendLine(" <script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>");
|
||||
sb.AppendLine("</head>");
|
||||
sb.AppendLine("<body>");
|
||||
|
||||
|
|
|
|||
194
src/Donustur.Engine/Documents/PandocEngine.cs
Normal file
194
src/Donustur.Engine/Documents/PandocEngine.cs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
using System.Diagnostics;
|
||||
using Donustur.Core.Transactions;
|
||||
using Donustur.Core.Utils;
|
||||
|
||||
namespace Donustur.Engine.Documents;
|
||||
|
||||
public sealed class PandocEngine
|
||||
{
|
||||
private string? _customPath;
|
||||
|
||||
public PandocEngine(string? customPath = null)
|
||||
{
|
||||
_customPath = customPath;
|
||||
}
|
||||
|
||||
public void SetCustomPath(string? customPath)
|
||||
{
|
||||
_customPath = customPath;
|
||||
}
|
||||
|
||||
public string? ResolvePandocPath()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_customPath) && File.Exists(_customPath))
|
||||
{
|
||||
return _customPath;
|
||||
}
|
||||
|
||||
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
string progFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
|
||||
string progFilesX86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
|
||||
|
||||
string[] candidatePaths =
|
||||
{
|
||||
Path.Combine(progFiles, @"Pandoc\pandoc.exe"),
|
||||
Path.Combine(progFilesX86, @"Pandoc\pandoc.exe"),
|
||||
Path.Combine(localAppData, @"Pandoc\pandoc.exe"),
|
||||
Path.Combine(localAppData, @"Programs\Pandoc\pandoc.exe"),
|
||||
Path.Combine(localAppData, @"Microsoft\WinGet\Links\pandoc.exe")
|
||||
};
|
||||
|
||||
foreach (var path in candidatePaths)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
return path;
|
||||
}
|
||||
|
||||
// WinGet paket klasörünü dinamik tara
|
||||
string wingetPackages = Path.Combine(localAppData, @"Microsoft\WinGet\Packages");
|
||||
if (Directory.Exists(wingetPackages))
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var pkgDir in Directory.EnumerateDirectories(wingetPackages))
|
||||
{
|
||||
if (Path.GetFileName(pkgDir).Contains("pandoc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string direct = Path.Combine(pkgDir, "pandoc.exe");
|
||||
if (File.Exists(direct)) return direct;
|
||||
|
||||
string inBin = Path.Combine(pkgDir, "bin", "pandoc.exe");
|
||||
if (File.Exists(inBin)) return inBin;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Erişim hatasında devam et
|
||||
}
|
||||
}
|
||||
|
||||
// PATH çevre değişkenlerini Process, User ve Machine seviyelerinde kontrol et
|
||||
var pathTargets = new[] { EnvironmentVariableTarget.Process, EnvironmentVariableTarget.User, EnvironmentVariableTarget.Machine };
|
||||
foreach (var target in pathTargets)
|
||||
{
|
||||
try
|
||||
{
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("PATH", target);
|
||||
if (pathEnv != null)
|
||||
{
|
||||
foreach (var segment in pathEnv.Split(Path.PathSeparator))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment)) continue;
|
||||
string combined = Path.Combine(segment.Trim(), "pandoc.exe");
|
||||
if (File.Exists(combined))
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Sessizce geç
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sistemde xelatex, pdflatex veya alternatif bir pdf-engine motoru olup olmadığını tespit eder.
|
||||
/// </summary>
|
||||
public string? ResolvePdfEngine()
|
||||
{
|
||||
string[] candidates = { "xelatex", "pdflatex", "lualatex", "typst", "weasyprint", "wkhtmltopdf" };
|
||||
foreach (var eng in candidates)
|
||||
{
|
||||
if (FindExecutableInPath(eng + ".exe") != null)
|
||||
{
|
||||
return eng;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string? FindExecutableInPath(string exeName)
|
||||
{
|
||||
var pathTargets = new[] { EnvironmentVariableTarget.Process, EnvironmentVariableTarget.User, EnvironmentVariableTarget.Machine };
|
||||
foreach (var target in pathTargets)
|
||||
{
|
||||
try
|
||||
{
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("PATH", target);
|
||||
if (pathEnv != null)
|
||||
{
|
||||
foreach (var segment in pathEnv.Split(Path.PathSeparator))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment)) continue;
|
||||
string combined = Path.Combine(segment.Trim(), exeName);
|
||||
if (File.Exists(combined))
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Sessizce geç
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsAvailable => ResolvePandocPath() != null;
|
||||
|
||||
/// <summary>
|
||||
/// Pandoc kullanarak Markdown veya ofis belgesini yüksek sadakatle dönüştürür.
|
||||
/// Matematik denklemleri ($...$, $$...$$) için xelatex ve standart LaTeX desteği sağlar.
|
||||
/// </summary>
|
||||
public async Task<string?> ConvertAsync(
|
||||
string inputFile,
|
||||
string targetFormat,
|
||||
ExportTransaction transaction,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
string? pandocPath = ResolvePandocPath();
|
||||
if (pandocPath == null) return null;
|
||||
|
||||
string formatKey = targetFormat.ToLowerInvariant().TrimStart('.');
|
||||
string baseName = Path.GetFileNameWithoutExtension(inputFile);
|
||||
string outputPath = SafePaths.GetUniquePath(transaction.StagingDirectory, $"{baseName}.{formatKey}");
|
||||
|
||||
string arguments;
|
||||
string? pdfEngine = ResolvePdfEngine();
|
||||
|
||||
if (formatKey == "pdf")
|
||||
{
|
||||
// Kullanıcının paylaştığı kusursuz parametreler:
|
||||
// pandoc "belge.md" -o "belge.pdf" --pdf-engine=xelatex -V mainfont="Arial" -V geometry:margin=2.5cm
|
||||
string engineParam = pdfEngine != null ? $"--pdf-engine={pdfEngine}" : "";
|
||||
arguments = $"\"{inputFile}\" -o \"{outputPath}\" {engineParam} -V mainfont=\"Arial\" -V geometry:margin=2.5cm".Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
arguments = $"\"{inputFile}\" -o \"{outputPath}\"";
|
||||
}
|
||||
|
||||
var result = await ProcessRunner.RunAsync(pandocPath, arguments, token: token);
|
||||
if (result.ExitCode == 0 && File.Exists(outputPath))
|
||||
{
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
// Eğer xelatex ile denendi ve başarısız olduysa, varsayılan pandoc parametresiyle tekrar dene
|
||||
if (formatKey == "pdf" && !string.IsNullOrEmpty(pdfEngine))
|
||||
{
|
||||
string fallbackArgs = $"\"{inputFile}\" -o \"{outputPath}\" -V geometry:margin=2.5cm";
|
||||
var fallbackResult = await ProcessRunner.RunAsync(pandocPath, fallbackArgs, token: token);
|
||||
if (fallbackResult.ExitCode == 0 && File.Exists(outputPath))
|
||||
{
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
80
src/Donustur.Engine/Documents/PandocInstaller.cs
Normal file
80
src/Donustur.Engine/Documents/PandocInstaller.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System.Diagnostics;
|
||||
using Donustur.Engine.Media;
|
||||
|
||||
namespace Donustur.Engine.Documents;
|
||||
|
||||
public static class PandocInstaller
|
||||
{
|
||||
private static readonly object LockObj = new();
|
||||
private static Task<string?>? _activeInstallTask;
|
||||
|
||||
public static bool IsInstalling
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (LockObj)
|
||||
{
|
||||
return _activeInstallTask != null && !_activeInstallTask.IsCompleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pandoc kurulu değilse Windows winget üzerinden sessizce kurar.
|
||||
/// </summary>
|
||||
public static Task<string?> EnsureOrInstallPandocAsync(
|
||||
PandocEngine pandocEngine,
|
||||
IProgress<string>? progress = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
string? existing = pandocEngine.ResolvePandocPath();
|
||||
if (existing != null)
|
||||
{
|
||||
return Task.FromResult<string?>(existing);
|
||||
}
|
||||
|
||||
lock (LockObj)
|
||||
{
|
||||
if (_activeInstallTask != null && !_activeInstallTask.IsCompleted)
|
||||
{
|
||||
return _activeInstallTask;
|
||||
}
|
||||
|
||||
_activeInstallTask = Task.Run(async () =>
|
||||
{
|
||||
progress?.Report("Pandoc aranıyor...");
|
||||
string? found = pandocEngine.ResolvePandocPath();
|
||||
if (found != null) return found;
|
||||
|
||||
string? wingetPath = FfmpegInstaller.ResolveWingetPath();
|
||||
if (wingetPath != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
progress?.Report("Pandoc, Windows Paket Yöneticisi (winget) ile indiriliyor...");
|
||||
string args = "install --id JohnMacFarlane.Pandoc --accept-package-agreements --accept-source-agreements --silent";
|
||||
|
||||
var result = await ProcessRunner.RunAsync(wingetPath, args, outputProgress: progress, token: token);
|
||||
if (result.ExitCode == 0)
|
||||
{
|
||||
found = pandocEngine.ResolvePandocPath();
|
||||
if (found != null)
|
||||
{
|
||||
progress?.Report($"✓ Pandoc başarıyla kuruldu: {found}");
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
progress?.Report($"✕ Pandoc kurulum hatası: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return pandocEngine.ResolvePandocPath();
|
||||
}, token);
|
||||
|
||||
return _activeInstallTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
194
src/Donustur.Engine/Media/FfmpegInstaller.cs
Normal file
194
src/Donustur.Engine/Media/FfmpegInstaller.cs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http;
|
||||
using Donustur.Core.Utils;
|
||||
|
||||
namespace Donustur.Engine.Media;
|
||||
|
||||
public static class FfmpegInstaller
|
||||
{
|
||||
private static readonly object LockObj = new();
|
||||
private static Task<string?>? _activeInstallTask;
|
||||
|
||||
public static bool IsInstalling
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (LockObj)
|
||||
{
|
||||
return _activeInstallTask != null && !_activeInstallTask.IsCompleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FFmpeg kurulu değilse Windows winget veya doğrudan resmi GitHub kaynağından
|
||||
/// indirip kurar. Eşzamanlı çağrıları güvenle tek bir kuruluma yönlendirir.
|
||||
/// </summary>
|
||||
public static Task<string?> EnsureOrInstallFfmpegAsync(
|
||||
MediaEngine mediaEngine,
|
||||
IProgress<string>? progress = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
// 1. Zaten mevcutsa anında döndür
|
||||
string? existing = mediaEngine.ResolveFfmpegPath();
|
||||
if (existing != null)
|
||||
{
|
||||
return Task.FromResult<string?>(existing);
|
||||
}
|
||||
|
||||
lock (LockObj)
|
||||
{
|
||||
if (_activeInstallTask != null && !_activeInstallTask.IsCompleted)
|
||||
{
|
||||
return _activeInstallTask;
|
||||
}
|
||||
|
||||
_activeInstallTask = Task.Run(() => PerformInstallAsync(mediaEngine, progress, token), token);
|
||||
return _activeInstallTask;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string?> PerformInstallAsync(
|
||||
MediaEngine mediaEngine,
|
||||
IProgress<string>? progress,
|
||||
CancellationToken token)
|
||||
{
|
||||
progress?.Report("FFmpeg taranıyor...");
|
||||
|
||||
// 1. Derin tarama
|
||||
string? found = mediaEngine.ResolveFfmpegPath();
|
||||
if (found != null)
|
||||
{
|
||||
progress?.Report($"FFmpeg bulundu: {found}");
|
||||
return found;
|
||||
}
|
||||
|
||||
// 2. Yöntem 1: Windows Paket Yöneticisi (winget)
|
||||
string? wingetPath = ResolveWingetPath();
|
||||
if (wingetPath != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
progress?.Report("FFmpeg, Windows Paket Yöneticisi (winget) ile indiriliyor...");
|
||||
string args = "install --id Gyan.FFmpeg.Essentials --accept-package-agreements --accept-source-agreements --silent";
|
||||
|
||||
var result = await ProcessRunner.RunAsync(
|
||||
wingetPath,
|
||||
args,
|
||||
outputProgress: progress,
|
||||
token: token);
|
||||
|
||||
if (result.ExitCode == 0)
|
||||
{
|
||||
// Çevre değişkenlerini ve winget paket klasörünü yeniden tara
|
||||
found = mediaEngine.ResolveFfmpegPath();
|
||||
if (found != null)
|
||||
{
|
||||
progress?.Report($"✓ FFmpeg başarıyla kuruldu: {found}");
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Winget başarısız olursa doğrudan indirme yöntemine geç
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Yöntem 2: Doğrudan resmi GitHub sürümünden taşınabilir FFmpeg indirme
|
||||
try
|
||||
{
|
||||
progress?.Report("FFmpeg resmi sunucudan doğrudan indiriliyor...");
|
||||
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
string toolsDir = Path.Combine(localAppData, "LDConverter", "tools");
|
||||
Directory.CreateDirectory(toolsDir);
|
||||
|
||||
string zipPath = Path.Combine(toolsDir, "ffmpeg_download.zip");
|
||||
string targetExePath = Path.Combine(toolsDir, "ffmpeg.exe");
|
||||
|
||||
// GyanD / FFmpeg essentials build doğrudan indirme URL'si
|
||||
string downloadUrl = "https://github.com/GyanD/codexffmpeg/releases/download/7.1/ffmpeg-7.1-essentials_build.zip";
|
||||
|
||||
using (var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(5) })
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("LDConverter/1.3.0");
|
||||
|
||||
using var response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, token);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
long? totalBytes = response.Content.Headers.ContentLength;
|
||||
await using (var contentStream = await response.Content.ReadAsStreamAsync(token))
|
||||
await using (var fileStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write, FileShare.None, 81920, true))
|
||||
{
|
||||
var buffer = new byte[81920];
|
||||
long totalRead = 0;
|
||||
int read;
|
||||
|
||||
while ((read = await contentStream.ReadAsync(buffer, token)) > 0)
|
||||
{
|
||||
await fileStream.WriteAsync(buffer.AsMemory(0, read), token);
|
||||
totalRead += read;
|
||||
|
||||
if (totalBytes.HasValue && totalBytes.Value > 0)
|
||||
{
|
||||
double pct = (double)totalRead / totalBytes.Value * 100.0;
|
||||
progress?.Report($"FFmpeg indiriliyor: %{pct:F0}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
progress?.Report("FFmpeg paketi açılıyor...");
|
||||
using (var archive = ZipFile.OpenRead(zipPath))
|
||||
{
|
||||
var ffmpegEntry = archive.Entries.FirstOrDefault(e => e.Name.Equals("ffmpeg.exe", StringComparison.OrdinalIgnoreCase));
|
||||
if (ffmpegEntry != null)
|
||||
{
|
||||
ffmpegEntry.ExtractToFile(targetExePath, overwrite: true);
|
||||
}
|
||||
}
|
||||
|
||||
try { File.Delete(zipPath); } catch { }
|
||||
|
||||
if (File.Exists(targetExePath))
|
||||
{
|
||||
mediaEngine.SetCustomPath(targetExePath);
|
||||
progress?.Report($"✓ FFmpeg başarıyla hazırlandı: {targetExePath}");
|
||||
return targetExePath;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
progress?.Report($"✕ FFmpeg indirme hatası: {ex.Message}");
|
||||
}
|
||||
|
||||
return mediaEngine.ResolveFfmpegPath();
|
||||
}
|
||||
|
||||
public static string? ResolveWingetPath()
|
||||
{
|
||||
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
string defaultWinget = Path.Combine(localAppData, @"Microsoft\WindowsApps\winget.exe");
|
||||
if (File.Exists(defaultWinget))
|
||||
{
|
||||
return defaultWinget;
|
||||
}
|
||||
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("PATH");
|
||||
if (pathEnv != null)
|
||||
{
|
||||
foreach (var segment in pathEnv.Split(Path.PathSeparator))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment)) continue;
|
||||
string candidate = Path.Combine(segment.Trim(), "winget.exe");
|
||||
if (File.Exists(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,12 +34,16 @@ public sealed class MediaEngine
|
|||
|
||||
string[] candidatePaths =
|
||||
{
|
||||
Path.Combine(localAppData, @"LDConverter\tools\ffmpeg.exe"),
|
||||
Path.Combine(baseDir, "tools", "ffmpeg.exe"),
|
||||
Path.Combine(baseDir, "ffmpeg.exe"),
|
||||
Path.Combine(localAppData, @"Microsoft\WindowsApps\ffmpeg.exe"),
|
||||
Path.Combine(localAppData, @"Microsoft\WinGet\Links\ffmpeg.exe"),
|
||||
Path.Combine(userProfile, @"scoop\shims\ffmpeg.exe"),
|
||||
@"C:\ffmpeg\bin\ffmpeg.exe",
|
||||
@"C:\ffmpeg\ffmpeg.exe",
|
||||
@"C:\Program Files\ffmpeg\bin\ffmpeg.exe",
|
||||
@"C:\Program Files\ffmpeg\ffmpeg.exe",
|
||||
@"C:\ProgramData\chocolatey\bin\ffmpeg.exe"
|
||||
};
|
||||
|
||||
|
|
@ -49,17 +53,22 @@ public sealed class MediaEngine
|
|||
return path;
|
||||
}
|
||||
|
||||
// WinGet paket klasörlerini dinamik tara
|
||||
// WinGet paket klasörlerini dinamik ve güvenli (hata fırlatmayan) tara
|
||||
string wingetPackages = Path.Combine(localAppData, @"Microsoft\WinGet\Packages");
|
||||
if (Directory.Exists(wingetPackages))
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var pkgDir in Directory.EnumerateDirectories(wingetPackages, "*FFmpeg*"))
|
||||
foreach (var pkgDir in Directory.EnumerateDirectories(wingetPackages))
|
||||
{
|
||||
var found = Directory.EnumerateFiles(pkgDir, "ffmpeg.exe", SearchOption.AllDirectories).FirstOrDefault();
|
||||
if (found != null)
|
||||
return found;
|
||||
string dirName = Path.GetFileName(pkgDir);
|
||||
if (dirName.Contains("ffmpeg", StringComparison.OrdinalIgnoreCase) ||
|
||||
dirName.Contains("gyan", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var found = SafeFindFile(pkgDir, "ffmpeg.exe", maxDepth: 4);
|
||||
if (found != null)
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
|
@ -68,25 +77,62 @@ public sealed class MediaEngine
|
|||
}
|
||||
}
|
||||
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("PATH");
|
||||
if (pathEnv != null)
|
||||
// PATH çevre değişkenlerini Process, User ve Machine seviyelerinde kontrol et
|
||||
var pathTargets = new[] { EnvironmentVariableTarget.Process, EnvironmentVariableTarget.User, EnvironmentVariableTarget.Machine };
|
||||
foreach (var target in pathTargets)
|
||||
{
|
||||
foreach (var segment in pathEnv.Split(Path.PathSeparator))
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment)) continue;
|
||||
string combined = Path.Combine(segment.Trim(), "ffmpeg.exe");
|
||||
if (File.Exists(combined))
|
||||
return combined;
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("PATH", target);
|
||||
if (pathEnv != null)
|
||||
{
|
||||
foreach (var segment in pathEnv.Split(Path.PathSeparator))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment)) continue;
|
||||
string combined = Path.Combine(segment.Trim(), "ffmpeg.exe");
|
||||
if (File.Exists(combined))
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Sessizce geç
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string? SafeFindFile(string rootDir, string targetFileName, int maxDepth)
|
||||
{
|
||||
if (!Directory.Exists(rootDir) || maxDepth < 0) return null;
|
||||
try
|
||||
{
|
||||
string direct = Path.Combine(rootDir, targetFileName);
|
||||
if (File.Exists(direct)) return direct;
|
||||
|
||||
string inBin = Path.Combine(rootDir, "bin", targetFileName);
|
||||
if (File.Exists(inBin)) return inBin;
|
||||
|
||||
foreach (var subDir in Directory.EnumerateDirectories(rootDir))
|
||||
{
|
||||
var found = SafeFindFile(subDir, targetFileName, maxDepth - 1);
|
||||
if (found != null) return found;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Erişim izin hatalarını yut
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsAvailable => ResolveFfmpegPath() != null;
|
||||
|
||||
/// <summary>
|
||||
/// Video veya ses dosyasını hedef formata dönüştürür.
|
||||
/// FFmpeg eksikse otomatik kurulum dener; bulunamazsa kullanıcıya yol gösterir.
|
||||
/// </summary>
|
||||
public async Task<IReadOnlyList<string>> ConvertMediaAsync(
|
||||
IReadOnlyList<string> inputFiles,
|
||||
|
|
@ -97,10 +143,16 @@ public sealed class MediaEngine
|
|||
CancellationToken token = default)
|
||||
{
|
||||
string? ffmpegPath = ResolveFfmpegPath();
|
||||
if (ffmpegPath == null)
|
||||
{
|
||||
// Eksikse son anda otomatik kurulumu tetikle
|
||||
ffmpegPath = await FfmpegInstaller.EnsureOrInstallFfmpegAsync(this, null, token);
|
||||
}
|
||||
|
||||
if (ffmpegPath == null)
|
||||
{
|
||||
throw new FileNotFoundException(
|
||||
"FFmpeg bulunamadı. Medya dönüştürme için FFmpeg gereklidir. Lütfen Ayarlar ekranından ffmpeg.exe yolunu seçin veya 'winget install Gyan.FFmpeg' komutuyla yükleyin.");
|
||||
"FFmpeg bulunamadı ve otomatik indirilemedi. Video & ses dönüştürmeleri için lütfen Ayarlar ekranından FFmpeg indir butonuna tıklayın veya ffmpeg.exe yolunu seçin.");
|
||||
}
|
||||
|
||||
var outputFiles = new List<string>();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<AssemblyName>LDConverter</AssemblyName>
|
||||
<Product>LD Converter</Product>
|
||||
<Title>LD Converter</Title>
|
||||
<Version>1.2.0</Version>
|
||||
<Version>1.3.0</Version>
|
||||
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Donustur.Core.Services;
|
|||
using Donustur.Core.Transactions;
|
||||
using Donustur.Core.Utils;
|
||||
using Donustur.Engine;
|
||||
using Donustur.Engine.Media;
|
||||
using Donustur.Engine.Qr;
|
||||
using Donustur.UI.Services;
|
||||
using Donustur.UI.Windows;
|
||||
|
|
@ -49,7 +50,11 @@ public partial class MainWindow : Window
|
|||
_preferencesStore.Changed += _ => Dispatcher.Invoke(UpdateWheelStatusDisplay);
|
||||
_historyStore.Changed += () => Dispatcher.Invoke(RenderHistory);
|
||||
|
||||
Loaded += (_, _) => RenderHistory();
|
||||
Loaded += (_, _) =>
|
||||
{
|
||||
RenderHistory();
|
||||
CheckAndEnsureFfmpegOnStartup();
|
||||
};
|
||||
Closing += OnWindowClosing;
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +68,52 @@ public partial class MainWindow : Window
|
|||
WheelStatusLabel.Text = enabled ? $"Çark: {mod} (Aktif)" : "Çark: Kapalı";
|
||||
}
|
||||
|
||||
private void CheckAndEnsureFfmpegOnStartup()
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
var mediaEngine = new MediaEngine(_preferencesStore.Current.CustomFfmpegPath);
|
||||
string? found = mediaEngine.ResolveFfmpegPath();
|
||||
if (found != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Bilgisayarda FFmpeg bulunamadı, kullanıcıya bildir ve otomatik kurulumu arka planda başlat
|
||||
_ = Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
FooterStatusLabel.Text = "ℹ Video & ses dönüşümleri için FFmpeg taranıyor / indiriliyor...";
|
||||
});
|
||||
|
||||
var progress = new Progress<string>(msg =>
|
||||
{
|
||||
_ = Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
FooterStatusLabel.Text = $"📥 {msg}";
|
||||
});
|
||||
});
|
||||
|
||||
string? installedPath = await FfmpegInstaller.EnsureOrInstallFfmpegAsync(mediaEngine, progress);
|
||||
_ = Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (installedPath != null)
|
||||
{
|
||||
FooterStatusLabel.Text = $"✓ FFmpeg hazırlandı ({Path.GetFileName(installedPath)}). Video ve ses dönüşümleri aktif!";
|
||||
if (string.IsNullOrWhiteSpace(_preferencesStore.Current.CustomFfmpegPath))
|
||||
{
|
||||
var prefs = _preferencesStore.Current;
|
||||
prefs.CustomFfmpegPath = installedPath;
|
||||
_preferencesStore.Save(prefs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FooterStatusLabel.Text = "ℹ FFmpeg otomatik kurulamadı. Ayarlar ekranından manuel yükleyebilirsiniz.";
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void OnToggleWheelClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var prefs = _preferencesStore.Current;
|
||||
|
|
|
|||
|
|
@ -321,11 +321,18 @@
|
|||
|
||||
<!-- FFmpeg -->
|
||||
<DockPanel Margin="0,0,0,8">
|
||||
<Button Content="ffmpeg.exe Seç..." DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center" Background="#2D3548" Foreground="#FFFFFF" BorderThickness="0" Padding="10,5" Cursor="Hand" Click="OnBrowseFfmpegClick">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border"><Setter Property="CornerRadius" Value="6"/></Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||
<Button x:Name="InstallFfmpegBtn" Content="📥 İndir & Kur" Background="#4F46E5" Foreground="#FFFFFF" BorderThickness="0" Padding="10,5" Margin="0,0,6,0" Cursor="Hand" Click="OnInstallFfmpegClick">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border"><Setter Property="CornerRadius" Value="6"/></Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
<Button Content="ffmpeg.exe Seç..." Background="#2D3548" Foreground="#FFFFFF" BorderThickness="0" Padding="10,5" Cursor="Hand" Click="OnBrowseFfmpegClick">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border"><Setter Property="CornerRadius" Value="6"/></Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="FFmpeg (Video & Ses Motoru)" Style="{StaticResource SettingLabel}"/>
|
||||
<TextBlock x:Name="FfmpegStatusText" Text="Kontrol ediliyor..." Style="{StaticResource SettingDesc}" TextTrimming="CharacterEllipsis"/>
|
||||
|
|
@ -334,6 +341,28 @@
|
|||
|
||||
<Separator Background="#2D3343" Margin="0,4,0,10"/>
|
||||
|
||||
<!-- Pandoc -->
|
||||
<DockPanel Margin="0,0,0,8">
|
||||
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||
<Button x:Name="InstallPandocBtn" Content="📥 İndir & Kur" Background="#4F46E5" Foreground="#FFFFFF" BorderThickness="0" Padding="10,5" Margin="0,0,6,0" Cursor="Hand" Click="OnInstallPandocClick">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border"><Setter Property="CornerRadius" Value="6"/></Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
<Button Content="pandoc.exe Seç..." Background="#2D3548" Foreground="#FFFFFF" BorderThickness="0" Padding="10,5" Cursor="Hand" Click="OnBrowsePandocClick">
|
||||
<Button.Resources>
|
||||
<Style TargetType="Border"><Setter Property="CornerRadius" Value="6"/></Style>
|
||||
</Button.Resources>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Pandoc & XeLaTeX (Markdown & Matematik Denklem Motoru)" Style="{StaticResource SettingLabel}"/>
|
||||
<TextBlock x:Name="PandocStatusText" Text="Kontrol ediliyor..." Style="{StaticResource SettingDesc}" TextTrimming="CharacterEllipsis"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
<Separator Background="#2D3343" Margin="0,4,0,10"/>
|
||||
|
||||
<!-- 7-Zip & Yerel Motorlar -->
|
||||
<DockPanel>
|
||||
<StackPanel>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public partial class SettingsWindow : Window
|
|||
private const string AppName = "LDConverter";
|
||||
|
||||
private readonly PreferencesStore _preferencesStore;
|
||||
private string? _customPandocPath;
|
||||
|
||||
public SettingsWindow(PreferencesStore preferencesStore)
|
||||
{
|
||||
|
|
@ -30,6 +31,7 @@ public partial class SettingsWindow : Window
|
|||
private void LoadValues()
|
||||
{
|
||||
var prefs = _preferencesStore.Current;
|
||||
_customPandocPath = prefs.CustomPandocPath;
|
||||
|
||||
EnableWheelCheck.IsChecked = prefs.Enabled;
|
||||
|
||||
|
|
@ -69,11 +71,12 @@ public partial class SettingsWindow : Window
|
|||
// Harici Motor Kontrolleri (UI thread'i kilitlememesi için arka planda tara)
|
||||
LibreOfficeStatusText.Text = "ℹ Kontrol ediliyor...";
|
||||
FfmpegStatusText.Text = "ℹ Kontrol ediliyor...";
|
||||
PandocStatusText.Text = "ℹ Kontrol ediliyor...";
|
||||
NativeEnginesStatusText.Text = "✓ Magick.NET, PdfPig ve SharpCompress hazır";
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var officeEngine = new OfficeDocumentEngine(prefs.CustomLibreOfficePath);
|
||||
var officeEngine = new OfficeDocumentEngine(prefs.CustomLibreOfficePath, _customPandocPath);
|
||||
bool officeAvailable = officeEngine.IsAvailable;
|
||||
string? sofficePath = officeAvailable ? officeEngine.ResolveSofficePath() : null;
|
||||
|
||||
|
|
@ -81,6 +84,11 @@ public partial class SettingsWindow : Window
|
|||
bool mediaAvailable = mediaEngine.IsAvailable;
|
||||
string? ffmpegPath = mediaAvailable ? mediaEngine.ResolveFfmpegPath() : null;
|
||||
|
||||
var pandocEngine = new PandocEngine(_customPandocPath);
|
||||
bool pandocAvailable = pandocEngine.IsAvailable;
|
||||
string? pandocPath = pandocAvailable ? pandocEngine.ResolvePandocPath() : null;
|
||||
string? pdfEngine = pandocAvailable ? pandocEngine.ResolvePdfEngine() : null;
|
||||
|
||||
string? sevenZip = ArchiveEngine.Resolve7ZipPath();
|
||||
|
||||
Dispatcher.BeginInvoke(() =>
|
||||
|
|
@ -100,11 +108,27 @@ public partial class SettingsWindow : Window
|
|||
{
|
||||
FfmpegStatusText.Text = $"✓ Hazır ({ffmpegPath})";
|
||||
FfmpegStatusText.Foreground = System.Windows.Media.Brushes.LightGreen;
|
||||
InstallFfmpegBtn.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
FfmpegStatusText.Text = "✕ Bulunamadı (Video & ses dönüşümleri için ffmpeg.exe seçin veya winget ile kurun)";
|
||||
FfmpegStatusText.Text = "✕ Bulunamadı (Video & ses dönüşümleri için FFmpeg gereklidir)";
|
||||
FfmpegStatusText.Foreground = System.Windows.Media.Brushes.IndianRed;
|
||||
InstallFfmpegBtn.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
if (pandocAvailable)
|
||||
{
|
||||
string engineInfo = pdfEngine != null ? $" [PDF Motoru: {pdfEngine}]" : "";
|
||||
PandocStatusText.Text = $"✓ Hazır ({pandocPath}){engineInfo}";
|
||||
PandocStatusText.Foreground = System.Windows.Media.Brushes.LightGreen;
|
||||
InstallPandocBtn.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
PandocStatusText.Text = "ℹ Kurulu değil (Markdown & LaTeX denklem dönüşümleri için kurabilirsiniz)";
|
||||
PandocStatusText.Foreground = System.Windows.Media.Brushes.Khaki;
|
||||
InstallPandocBtn.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
NativeEnginesStatusText.Text = sevenZip != null
|
||||
|
|
@ -182,6 +206,74 @@ public partial class SettingsWindow : Window
|
|||
}
|
||||
}
|
||||
|
||||
private async void OnInstallFfmpegClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
InstallFfmpegBtn.IsEnabled = false;
|
||||
FfmpegStatusText.Text = "📥 FFmpeg indiriliyor ve kuruluyor...";
|
||||
FfmpegStatusText.Foreground = System.Windows.Media.Brushes.Khaki;
|
||||
|
||||
var progress = new Progress<string>(msg =>
|
||||
{
|
||||
Dispatcher.BeginInvoke(() => FfmpegStatusText.Text = msg);
|
||||
});
|
||||
|
||||
var mediaEngine = new MediaEngine(_preferencesStore.Current.CustomFfmpegPath);
|
||||
string? result = await FfmpegInstaller.EnsureOrInstallFfmpegAsync(mediaEngine, progress);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
var prefs = _preferencesStore.Current;
|
||||
prefs.CustomFfmpegPath = result;
|
||||
_preferencesStore.Save(prefs);
|
||||
}
|
||||
|
||||
InstallFfmpegBtn.IsEnabled = true;
|
||||
LoadValues();
|
||||
}
|
||||
|
||||
private void OnBrowsePandocClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new Microsoft.Win32.OpenFileDialog
|
||||
{
|
||||
Filter = "pandoc.exe|pandoc.exe|Tüm Dosyalar (*.*)|*.*",
|
||||
Title = "Pandoc pandoc.exe dosyasını seçin"
|
||||
};
|
||||
if (dlg.ShowDialog() == true)
|
||||
{
|
||||
_customPandocPath = dlg.FileName;
|
||||
var prefs = _preferencesStore.Current;
|
||||
prefs.CustomPandocPath = dlg.FileName;
|
||||
_preferencesStore.Save(prefs);
|
||||
LoadValues();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnInstallPandocClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
InstallPandocBtn.IsEnabled = false;
|
||||
PandocStatusText.Text = "📥 Pandoc indiriliyor ve kuruluyor...";
|
||||
PandocStatusText.Foreground = System.Windows.Media.Brushes.Khaki;
|
||||
|
||||
var progress = new Progress<string>(msg =>
|
||||
{
|
||||
Dispatcher.BeginInvoke(() => PandocStatusText.Text = msg);
|
||||
});
|
||||
|
||||
var pandocEngine = new PandocEngine(_customPandocPath);
|
||||
string? result = await PandocInstaller.EnsureOrInstallPandocAsync(pandocEngine, progress);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
_customPandocPath = result;
|
||||
var prefs = _preferencesStore.Current;
|
||||
prefs.CustomPandocPath = result;
|
||||
_preferencesStore.Save(prefs);
|
||||
}
|
||||
|
||||
InstallPandocBtn.IsEnabled = true;
|
||||
LoadValues();
|
||||
}
|
||||
|
||||
private void OnStartupToggle(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SetStartupEnabled(RunAtStartupCheck.IsChecked == true);
|
||||
|
|
@ -236,6 +328,7 @@ public partial class SettingsWindow : Window
|
|||
prefs.MinimizeToTray = MinimizeToTrayCheck.IsChecked == true;
|
||||
prefs.AutoOpenOutputFolder = AutoOpenCheck.IsChecked == true;
|
||||
prefs.RunAtStartup = RunAtStartupCheck.IsChecked == true;
|
||||
prefs.CustomPandocPath = _customPandocPath;
|
||||
|
||||
prefs.OutputDirectoryMode = OutputModeCombo.SelectedIndex switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -392,3 +392,49 @@ public class QrEngineTests
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PandocEngineTests
|
||||
{
|
||||
[Fact]
|
||||
public void PandocEngine_ResolvesCustomPathWhenProvided()
|
||||
{
|
||||
var tempFile = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
var engine = new PandocEngine(tempFile);
|
||||
Assert.Equal(tempFile, engine.ResolvePandocPath());
|
||||
Assert.True(engine.IsAvailable);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(tempFile)) File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FfmpegResolutionTests
|
||||
{
|
||||
[Fact]
|
||||
public void WingetOrSystemFfmpeg_CanBeResolved()
|
||||
{
|
||||
var mediaEngine = new Donustur.Engine.Media.MediaEngine();
|
||||
string? resolved = mediaEngine.ResolveFfmpegPath();
|
||||
if (resolved != null)
|
||||
{
|
||||
Assert.True(File.Exists(resolved));
|
||||
Assert.EndsWith("ffmpeg.exe", resolved, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WingetPath_CanBeResolvedIfInstalled()
|
||||
{
|
||||
string? winget = Donustur.Engine.Media.FfmpegInstaller.ResolveWingetPath();
|
||||
if (winget != null)
|
||||
{
|
||||
Assert.True(File.Exists(winget));
|
||||
Assert.EndsWith("winget.exe", winget, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue