mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 08:19:47 +00:00
WIP: implemented a static function to determine if pandoc is installed or not
This commit is contained in:
parent
f321d6982e
commit
266fdb9b96
64
app/MindWork AI Studio/Tools/Pandoc.cs
Normal file
64
app/MindWork AI Studio/Tools/Pandoc.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
|
public static partial class Pandoc
|
||||||
|
{
|
||||||
|
// Minimale erforderliche Version von Pandoc
|
||||||
|
private static readonly Version MINIMUM_REQUIRED_VERSION = new Version(3, 6, 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if pandoc is available on the system and can be started as a process
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True, if pandoc is available and the minimum required version is met, else False.</returns>
|
||||||
|
public static async Task<bool> IsPandocAvailableAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var startInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = GetPandocExecutableName(),
|
||||||
|
Arguments = "--version",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
using var process = Process.Start(startInfo);
|
||||||
|
if (process == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var output = await process.StandardOutput.ReadToEndAsync();
|
||||||
|
await process.WaitForExitAsync();
|
||||||
|
if (process.ExitCode != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var versionMatch = PandocRegex().Match(output);
|
||||||
|
if (!versionMatch.Success) return false;
|
||||||
|
var versions = versionMatch.Groups[1].Value.Split('.');
|
||||||
|
var major = int.Parse(versions[0]);
|
||||||
|
var minor = int.Parse(versions[1]);
|
||||||
|
var patch = int.Parse(versions[2]);
|
||||||
|
var installedVersion = new Version(major, minor, patch);
|
||||||
|
|
||||||
|
return installedVersion >= MINIMUM_REQUIRED_VERSION;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gibt den Namen der Pandoc-Executable basierend auf dem Betriebssystem zurück.
|
||||||
|
/// </summary>
|
||||||
|
private static string GetPandocExecutableName()
|
||||||
|
{
|
||||||
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "pandoc.exe" : "pandoc";
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+\.[0-9]+)")]
|
||||||
|
private static partial Regex PandocRegex();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user