mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 10:39:47 +00:00
Removed patch level from version requirements and included more expressive log messages
This commit is contained in:
parent
e578796dbf
commit
62a4549f89
@ -1,13 +1,14 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using AIStudio.Components;
|
||||||
|
|
||||||
namespace AIStudio.Tools;
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
public static partial class Pandoc
|
public static partial class Pandoc
|
||||||
{
|
{
|
||||||
private static readonly Version MINIMUM_REQUIRED_VERSION = new Version(3, 6, 0);
|
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger("PluginFactory");
|
||||||
|
private static readonly Version MINIMUM_REQUIRED_VERSION = new Version(3, 6);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if pandoc is available on the system and can be started as a process
|
/// Checks if pandoc is available on the system and can be started as a process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,7 +28,8 @@ public static partial class Pandoc
|
|||||||
using var process = Process.Start(startInfo);
|
using var process = Process.Start(startInfo);
|
||||||
if (process == null)
|
if (process == null)
|
||||||
{
|
{
|
||||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.AppsOutage, $"Pandoc is not installed."));
|
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, "The pandoc process could not be started."));
|
||||||
|
LOG.LogInformation("The pandoc process was not started, it was null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,32 +37,35 @@ public static partial class Pandoc
|
|||||||
await process.WaitForExitAsync();
|
await process.WaitForExitAsync();
|
||||||
if (process.ExitCode != 0)
|
if (process.ExitCode != 0)
|
||||||
{
|
{
|
||||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.AppsOutage, $"Pandoc is not installed."));
|
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, $"The pandoc process exited unexpectedly."));
|
||||||
|
LOG.LogError("The pandoc process was exited with code {ProcessExitCode}", process.ExitCode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionMatch = PandocRegex().Match(output);
|
var versionMatch = PandocRegex().Match(output);
|
||||||
if (!versionMatch.Success)
|
if (!versionMatch.Success)
|
||||||
{
|
{
|
||||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.AppsOutage, $"Pandoc is not installed."));
|
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Terminal, $"pandoc --version returned an invalid format."));
|
||||||
|
LOG.LogError("pandoc --version returned an invalid format:\n {Output}", output);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var versions = versionMatch.Groups[1].Value.Split('.');
|
var versions = versionMatch.Groups[1].Value.Split('.');
|
||||||
var major = int.Parse(versions[0]);
|
var major = int.Parse(versions[0]);
|
||||||
var minor = int.Parse(versions[1]);
|
var minor = int.Parse(versions[1]);
|
||||||
var patch = int.Parse(versions[2]);
|
var installedVersion = new Version(major, minor);
|
||||||
var installedVersion = new Version(major, minor, patch);
|
|
||||||
|
|
||||||
if (installedVersion >= MINIMUM_REQUIRED_VERSION)
|
if (installedVersion >= MINIMUM_REQUIRED_VERSION)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.AppsOutage, $"Pandoc {installedVersion.ToString()} is installed, but it doesn't match the required version ({MINIMUM_REQUIRED_VERSION.ToString()}).\n"));
|
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Build, $"Pandoc {installedVersion.ToString()} is installed, but it doesn't match the required version ({MINIMUM_REQUIRED_VERSION.ToString()})."));
|
||||||
|
LOG.LogInformation("Pandoc {Installed} is installed, but it does not match the required version ({Requirement})", installedVersion.ToString(), MINIMUM_REQUIRED_VERSION.ToString());
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await MessageBus.INSTANCE.SendError(new (@Icons.Material.Filled.AppsOutage, "An unknown error occured while checking for Pandoc."));
|
await MessageBus.INSTANCE.SendError(new (@Icons.Material.Filled.AppsOutage, "Pandoc is not installed."));
|
||||||
|
LOG.LogError("Pandoc is not installed and threw an exception:\n {Message}", e.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,6 +75,6 @@ public static partial class Pandoc
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static string GetPandocExecutableName() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "pandoc.exe" : "pandoc";
|
private static string GetPandocExecutableName() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "pandoc.exe" : "pandoc";
|
||||||
|
|
||||||
[GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+\.[0-9]+)")]
|
[GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+)")]
|
||||||
private static partial Regex PandocRegex();
|
private static partial Regex PandocRegex();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user