diff --git a/publish/Donustur.Core.dll b/publish/Donustur.Core.dll
index 073a55c..574e476 100644
Binary files a/publish/Donustur.Core.dll and b/publish/Donustur.Core.dll differ
diff --git a/publish/Donustur.Core.pdb b/publish/Donustur.Core.pdb
index 3567d50..3be8875 100644
Binary files a/publish/Donustur.Core.pdb and b/publish/Donustur.Core.pdb differ
diff --git a/publish/Donustur.Engine.dll b/publish/Donustur.Engine.dll
index 09e2e02..4cb85f9 100644
Binary files a/publish/Donustur.Engine.dll and b/publish/Donustur.Engine.dll differ
diff --git a/publish/Donustur.Engine.pdb b/publish/Donustur.Engine.pdb
index 26ee774..1faeeac 100644
Binary files a/publish/Donustur.Engine.pdb and b/publish/Donustur.Engine.pdb differ
diff --git a/publish/LDConverter.deps.json b/publish/LDConverter.deps.json
index f701e41..e8fc0b4 100644
--- a/publish/LDConverter.deps.json
+++ b/publish/LDConverter.deps.json
@@ -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": ""
diff --git a/publish/LDConverter.dll b/publish/LDConverter.dll
index 05d4b17..06f4169 100644
Binary files a/publish/LDConverter.dll and b/publish/LDConverter.dll differ
diff --git a/publish/LDConverter.exe b/publish/LDConverter.exe
index e338991..8dc2fd7 100644
Binary files a/publish/LDConverter.exe and b/publish/LDConverter.exe differ
diff --git a/publish/LDConverter.pdb b/publish/LDConverter.pdb
index ff7625d..5ecd5fe 100644
Binary files a/publish/LDConverter.pdb and b/publish/LDConverter.pdb differ
diff --git a/src/Donustur.Core/Models/AppPreferences.cs b/src/Donustur.Core/Models/AppPreferences.cs
index 6ee43a2..ed8d26a 100644
--- a/src/Donustur.Core/Models/AppPreferences.cs
+++ b/src/Donustur.Core/Models/AppPreferences.cs
@@ -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;
}
diff --git a/src/Donustur.Engine/ConversionDispatcher.cs b/src/Donustur.Engine/ConversionDispatcher.cs
index b5673a6..232f584 100644
--- a/src/Donustur.Engine/ConversionDispatcher.cs
+++ b/src/Donustur.Engine/ConversionDispatcher.cs
@@ -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)
diff --git a/src/Donustur.Engine/Documents/OfficeDocumentEngine.cs b/src/Donustur.Engine/Documents/OfficeDocumentEngine.cs
index 0ef7a6a..5b69cd0 100644
--- a/src/Donustur.Engine/Documents/OfficeDocumentEngine.cs
+++ b/src/Donustur.Engine/Documents/OfficeDocumentEngine.cs
@@ -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;
+
///
/// LibreOffice soffice.exe yolunu bulur.
///
@@ -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(" ");
sb.AppendLine(" ");
sb.AppendLine($"
{WebUtility.HtmlEncode(title)}");
- sb.AppendLine(" ");
+ sb.AppendLine(" ");
+ sb.AppendLine(" ");
+ sb.AppendLine(" ");
sb.AppendLine("");
sb.AppendLine("");
diff --git a/src/Donustur.Engine/Documents/PandocEngine.cs b/src/Donustur.Engine/Documents/PandocEngine.cs
new file mode 100644
index 0000000..2b02c4c
--- /dev/null
+++ b/src/Donustur.Engine/Documents/PandocEngine.cs
@@ -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;
+ }
+
+ ///
+ /// Sistemde xelatex, pdflatex veya alternatif bir pdf-engine motoru olup olmadığını tespit eder.
+ ///
+ 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;
+
+ ///
+ /// 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.
+ ///
+ public async Task 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;
+ }
+}
diff --git a/src/Donustur.Engine/Documents/PandocInstaller.cs b/src/Donustur.Engine/Documents/PandocInstaller.cs
new file mode 100644
index 0000000..96c5b23
--- /dev/null
+++ b/src/Donustur.Engine/Documents/PandocInstaller.cs
@@ -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? _activeInstallTask;
+
+ public static bool IsInstalling
+ {
+ get
+ {
+ lock (LockObj)
+ {
+ return _activeInstallTask != null && !_activeInstallTask.IsCompleted;
+ }
+ }
+ }
+
+ ///
+ /// Pandoc kurulu değilse Windows winget üzerinden sessizce kurar.
+ ///
+ public static Task EnsureOrInstallPandocAsync(
+ PandocEngine pandocEngine,
+ IProgress? progress = null,
+ CancellationToken token = default)
+ {
+ string? existing = pandocEngine.ResolvePandocPath();
+ if (existing != null)
+ {
+ return Task.FromResult(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;
+ }
+ }
+}
diff --git a/src/Donustur.Engine/Media/FfmpegInstaller.cs b/src/Donustur.Engine/Media/FfmpegInstaller.cs
new file mode 100644
index 0000000..d8e9e41
--- /dev/null
+++ b/src/Donustur.Engine/Media/FfmpegInstaller.cs
@@ -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? _activeInstallTask;
+
+ public static bool IsInstalling
+ {
+ get
+ {
+ lock (LockObj)
+ {
+ return _activeInstallTask != null && !_activeInstallTask.IsCompleted;
+ }
+ }
+ }
+
+ ///
+ /// 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.
+ ///
+ public static Task EnsureOrInstallFfmpegAsync(
+ MediaEngine mediaEngine,
+ IProgress? progress = null,
+ CancellationToken token = default)
+ {
+ // 1. Zaten mevcutsa anında döndür
+ string? existing = mediaEngine.ResolveFfmpegPath();
+ if (existing != null)
+ {
+ return Task.FromResult(existing);
+ }
+
+ lock (LockObj)
+ {
+ if (_activeInstallTask != null && !_activeInstallTask.IsCompleted)
+ {
+ return _activeInstallTask;
+ }
+
+ _activeInstallTask = Task.Run(() => PerformInstallAsync(mediaEngine, progress, token), token);
+ return _activeInstallTask;
+ }
+ }
+
+ private static async Task PerformInstallAsync(
+ MediaEngine mediaEngine,
+ IProgress? 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;
+ }
+}
diff --git a/src/Donustur.Engine/Media/MediaEngine.cs b/src/Donustur.Engine/Media/MediaEngine.cs
index 90bc9e8..c85dea1 100644
--- a/src/Donustur.Engine/Media/MediaEngine.cs
+++ b/src/Donustur.Engine/Media/MediaEngine.cs
@@ -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;
///
/// Video veya ses dosyasını hedef formata dönüştürür.
+ /// FFmpeg eksikse otomatik kurulum dener; bulunamazsa kullanıcıya yol gösterir.
///
public async Task> ConvertMediaAsync(
IReadOnlyList 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();
diff --git a/src/Donustur.UI/Donustur.UI.csproj b/src/Donustur.UI/Donustur.UI.csproj
index 996ab3b..1562c5a 100644
--- a/src/Donustur.UI/Donustur.UI.csproj
+++ b/src/Donustur.UI/Donustur.UI.csproj
@@ -15,7 +15,7 @@
LDConverter
LD Converter
LD Converter
- 1.2.0
+ 1.3.0
Assets\app.ico
enable
enable
diff --git a/src/Donustur.UI/MainWindow.xaml.cs b/src/Donustur.UI/MainWindow.xaml.cs
index 0172a49..180f83d 100644
--- a/src/Donustur.UI/MainWindow.xaml.cs
+++ b/src/Donustur.UI/MainWindow.xaml.cs
@@ -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(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;
diff --git a/src/Donustur.UI/Windows/SettingsWindow.xaml b/src/Donustur.UI/Windows/SettingsWindow.xaml
index b749b3e..a3f7930 100644
--- a/src/Donustur.UI/Windows/SettingsWindow.xaml
+++ b/src/Donustur.UI/Windows/SettingsWindow.xaml
@@ -321,11 +321,18 @@
-
+
+
+
+
@@ -334,6 +341,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Donustur.UI/Windows/SettingsWindow.xaml.cs b/src/Donustur.UI/Windows/SettingsWindow.xaml.cs
index c7d8244..0625626 100644
--- a/src/Donustur.UI/Windows/SettingsWindow.xaml.cs
+++ b/src/Donustur.UI/Windows/SettingsWindow.xaml.cs
@@ -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(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(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
{
diff --git a/tests/Donustur.Tests/DonusturTests.cs b/tests/Donustur.Tests/DonusturTests.cs
index 36c43c6..0558210 100644
--- a/tests/Donustur.Tests/DonusturTests.cs
+++ b/tests/Donustur.Tests/DonusturTests.cs
@@ -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);
+ }
+ }
+}