Finished dialog; installation and availability check logic

This commit is contained in:
nilsk 2025-05-27 14:14:37 +02:00
parent 012b28da27
commit 81b276be69
3 changed files with 84 additions and 46 deletions

View File

@ -7,14 +7,14 @@
{ {
<div class="mb-4"> <div class="mb-4">
<MudText Class="mb-2"> <MudText Class="mb-2">
AI Studio relies on the third-party app <strong>Pandoc</strong> to process and retrieve data from AI Studio relies on the <strong>free and open-sourced</strong> third-party app <strong>Pandoc</strong> to process and retrieve data from local
local
Office files (ex. <strong>Word</strong>) and later other text formats like LaTeX. Office files (ex. <strong>Word</strong>) and later other text formats like LaTeX.
</MudText> </MudText>
<MudText> <MudText>
Unfortunately Pandocs GPL license is not compatible with AI Studios licences. Unfortunately Pandoc's GPL license is not compatible with AI Studios licences, nonetheless software under GPL is generally free to use and
Therefore you have to accept Pandocs GPL license before we can download and install Pandoc free of charge as well.
automatically for you (recommended). Therefore you have to accept Pandoc's GPL license before we can download and install Pandoc for free
automatically for you <strong>(recommended)</strong>.
However you can download it yourself manually with the instructions below. However you can download it yourself manually with the instructions below.
</MudText> </MudText>
<MudExpansionPanels> <MudExpansionPanels>
@ -27,7 +27,7 @@
} }
else if (!string.IsNullOrEmpty(this.licenseText)) else if (!string.IsNullOrEmpty(this.licenseText))
{ {
<div>@this.licenseText</div> <MudJustifiedText>@this.licenseText</MudJustifiedText>
} }
</MudExpansionPanel> </MudExpansionPanel>
</MudExpansionPanels> </MudExpansionPanels>
@ -38,10 +38,10 @@
Pandoc is distributed under the Pandoc is distributed under the
<MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>. <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
By clicking "Accept GPL and Install", you agree to the terms of the GPL license <br/> and Pandoc By clicking "Accept GPL and Install", you agree to the terms of the GPL license <br/> and Pandoc
will be installed automatically for you.<br/> will be installed automatically for you. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
</MudText> </MudText>
<MudButton OnClick="InstallPandocAsync" Color="Color.Primary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.InstallDesktop"> <MudButton OnClick="InstallPandocAsync" Color="Color.Primary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.InstallDesktop">
Accept GPL and Install Accept GPL and install for free
</MudButton> </MudButton>
</ExpansionPanel> </ExpansionPanel>
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Build" HeaderText="Manual installation"> <ExpansionPanel HeaderIcon="@Icons.Material.Filled.Build" HeaderText="Manual installation">
@ -51,7 +51,7 @@
<MudExpansionPanels Outlined="false" Elevation="0"> <MudExpansionPanels Outlined="false" Elevation="0">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.AppRegistration" HeaderText="Download with installer" IsExpanded="true"> <ExpansionPanel HeaderIcon="@Icons.Material.Filled.AppRegistration" HeaderText="Download with installer" IsExpanded="true">
<MudList T="string"> <MudList T="string">
<MudListItem T="string" Class="mb-4"> <MudListItem T="string" Class="mb-2">
Accept the terms of the GPL license and download the latest installer with the download button below. Accept the terms of the GPL license and download the latest installer with the download button below.
Eventually you need to allow the download of the installer in the download window. Eventually you need to allow the download of the installer in the download window.
<CodeTabs> <CodeTabs>
@ -66,7 +66,7 @@
</MudList> </MudList>
<MudText Class="mb-3" Typo="Typo.caption"> <MudText Class="mb-3" Typo="Typo.caption">
Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>. Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
By clicking "Accept GPL and download installer", you agree to the terms of the GPL license.<br/> By clicking "Accept GPL and download installer", you agree to the terms of the GPL license. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
</MudText> </MudText>
<MudButton OnClick="@this.GetInstaller" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading"> <MudButton OnClick="@this.GetInstaller" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading">
Accept GPL and download installer Accept GPL and download installer
@ -74,10 +74,10 @@
</ExpansionPanel> </ExpansionPanel>
<ExpansionPanel HeaderIcon="@Icons.Material.Outlined.Archive" HeaderText="Download with archive"> <ExpansionPanel HeaderIcon="@Icons.Material.Outlined.Archive" HeaderText="Download with archive">
<MudList T="string"> <MudList T="string">
<MudListItem T="string" Class="mb-4"> <MudListItem T="string" Class="mb-2">
Accept the terms of the GPL license and download the latest archive with the download button below. Accept the terms of the GPL license and download the latest archive with the download button below.
</MudListItem> </MudListItem>
<MudListItem T="string" Class="mb-4"> <MudListItem T="string" Class="mb-2">
Extract the archive to a folder of your choice. Extract the archive to a folder of your choice.
<CodeTabs> <CodeTabs>
<CodeBlock Title="Windows">C:\Users\%USERNAME%\pandoc</CodeBlock> <CodeBlock Title="Windows">C:\Users\%USERNAME%\pandoc</CodeBlock>
@ -85,7 +85,7 @@
<CodeBlock Title="Linux">/usr/local/bin/pandoc</CodeBlock> <CodeBlock Title="Linux">/usr/local/bin/pandoc</CodeBlock>
</CodeTabs> </CodeTabs>
</MudListItem> </MudListItem>
<MudListItem T="string" Class="mb-4"> <MudListItem T="string" Class="mb-2">
Open the folder and copy the full path to the <CodeBlock IsInline="@true">pandoc.exe</CodeBlock> file into your Open the folder and copy the full path to the <CodeBlock IsInline="@true">pandoc.exe</CodeBlock> file into your
clipboard. clipboard.
<CodeTabs> <CodeTabs>
@ -107,7 +107,7 @@
</MudList> </MudList>
<MudText Class="mb-3" Typo="Typo.caption"> <MudText Class="mb-3" Typo="Typo.caption">
Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>. Pandoc is distributed under the <MudLink Typo="Typo.caption" Href="https://github.com/jgm/pandoc/blob/main/COPYRIGHT" Target="_blank">GNU General Public License v2 (GPL)</MudLink>.
By clicking "Accept GPL and archive", you agree to the terms of the GPL license.<br/> By clicking "Accept GPL and archive", you agree to the terms of the GPL license. Software under GPL is <strong>free of charge</strong> and free to use.<br/>
</MudText> </MudText>
<MudButton OnClick="@this.GetArchive" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading"> <MudButton OnClick="@this.GetArchive" Color="Color.Secondary" Class="mt-4" Variant="Variant.Filled" Size="Size.Small" StartIcon="@Icons.Material.Filled.Downloading">
Accept GPL and download archive Accept GPL and download archive
@ -117,7 +117,7 @@
</ExpansionPanel> </ExpansionPanel>
</MudExpansionPanels> </MudExpansionPanels>
<div class="mt-2"> <div class="mt-2">
<MudButton Variant="Variant.Text" Color="Color.Default">Reject GPL licence</MudButton> <MudButton OnClick="@this.RejectLicense" Variant="Variant.Text" Color="Color.Default">Reject GPL licence</MudButton>
</div> </div>
} }
else else
@ -151,7 +151,4 @@
</MudItem> </MudItem>
} }
</DialogContent> </DialogContent>
<DialogActions>
<!-- Hier können Sie bei Bedarf Aktionen hinzufügen -->
</DialogActions>
</MudDialog> </MudDialog>

View File

@ -14,6 +14,9 @@ public partial class PandocDialog : ComponentBase
[Inject] [Inject]
protected IJSRuntime JsRuntime { get; init; } = null!; protected IJSRuntime JsRuntime { get; init; } = null!;
[Inject]
private IDialogService DialogService { get; init; } = null!;
[CascadingParameter] [CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!; private IMudDialogInstance MudDialog { get; set; } = null!;
@ -42,12 +45,17 @@ public partial class PandocDialog : ComponentBase
private async Task CheckPandocAvailabilityAsync() private async Task CheckPandocAvailabilityAsync()
{ {
this.isPandocAvailable = await Pandoc.CheckAvailabilityAsync(false); this.isPandocAvailable = await Pandoc.CheckAvailabilityAsync(this.RustService);
this.showSkeleton = false; this.showSkeleton = false;
await this.InvokeAsync(this.StateHasChanged); await this.InvokeAsync(this.StateHasChanged);
} }
private async Task InstallPandocAsync() => await Pandoc.InstallAsync(this.RustService); private async Task InstallPandocAsync()
{
await Pandoc.InstallAsync(this.RustService);
this.MudDialog.Close(DialogResult.Ok(true));
await this.DialogService.ShowAsync<PandocDialog>("pandoc dialog");
}
private void ProceedToInstallation() => this.showInstallPage = true; private void ProceedToInstallation() => this.showInstallPage = true;
@ -56,7 +64,6 @@ public partial class PandocDialog : ComponentBase
var uri = await Pandoc.GenerateInstallerUriAsync(); var uri = await Pandoc.GenerateInstallerUriAsync();
var filename = this.FilenameFromUri(uri); var filename = this.FilenameFromUri(uri);
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename); await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
} }
private async Task GetArchive() private async Task GetArchive()
@ -66,15 +73,33 @@ public partial class PandocDialog : ComponentBase
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename); await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
} }
private async Task RejectLicense()
{
var message = "Pandoc is open-source and free of charge, but if you reject Pandoc's license, it can not be installed and some of AIStudios data retrieval features will be disabled (e.g. using Office files like Word)." +
"This decision can be revoked at any time. Are you sure you want to reject the license?";
var dialogParameters = new DialogParameters
{
{ "Message", message },
};
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Reject Pandoc's licence", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult is null || dialogResult.Canceled)
dialogReference.Close();
else
this.Cancel();
}
private string FilenameFromUri(string uri) private string FilenameFromUri(string uri)
{ {
var index = uri.LastIndexOf('/'); var index = uri.LastIndexOf('/');
return uri[(index + 1)..]; return uri[(index + 1)..];
} }
private async Task OnExpandedChanged(bool newVal) private async Task OnExpandedChanged(bool isExpanded)
{ {
if (newVal) if (isExpanded)
{ {
this.isLoading = true; this.isLoading = true;
try try

View File

@ -20,8 +20,27 @@ public static partial class Pandoc
/// 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>
/// <returns>True, if pandoc is available and the minimum required version is met, else False.</returns> /// <returns>True, if pandoc is available and the minimum required version is met, else False.</returns>
public static async Task<bool> CheckAvailabilityAsync(bool showMessages = true) public static async Task<bool> CheckAvailabilityAsync(RustService rustService, bool showMessages = true)
{ {
var installDir = await GetPandocDataFolder(rustService);
var subdirectories = Directory.GetDirectories(installDir);
if (subdirectories.Length > 1)
{
await InstallAsync(rustService);
return true;
}
var hasPandoc = false;
foreach (var subdirectory in subdirectories)
{
if (subdirectory.Contains("pandoc"))
hasPandoc = true;
}
if (hasPandoc)
return true;
try try
{ {
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
@ -88,9 +107,8 @@ public static partial class Pandoc
public static async Task InstallAsync(RustService rustService) public static async Task InstallAsync(RustService rustService)
{ {
var dataDir = await rustService.GetDataDirectory(); var installDir = await GetPandocDataFolder(rustService);
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Help, $"{dataDir}")); ClearFolder(installDir);
var installDir = Path.Join(dataDir, "pandoc");
try try
{ {
@ -127,24 +145,8 @@ public static partial class Pandoc
return; return;
} }
var currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
var pandocDir = Path.Join(currentPath, "pandoc-3.6.4");
if (currentPath != null && !currentPath.Contains(pandocDir))
{
Environment.SetEnvironmentVariable(
"PATH",
$"{currentPath};{pandocDir}",
EnvironmentVariableTarget.Machine);
Console.WriteLine("Pandoc-Verzeichnis zum PATH hinzugefügt.");
}
else
{
Console.WriteLine("Pandoc-Verzeichnis ist bereits im PATH.");
}
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle,
$"Pandoc {MINIMUM_REQUIRED_VERSION.ToString()} was installed successfully.")); $"Pandoc {await FetchLatestVersionAsync()} was installed successfully."));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -152,9 +154,21 @@ public static partial class Pandoc
} }
} }
private static async Task ExtractZipAsync(string zipPath, string targetDir) private static void ClearFolder(string path)
{ {
if (!Directory.Exists(path)) return;
try
{
foreach (var dir in Directory.GetDirectories(path))
{
Directory.Delete(dir, true);
}
}
catch (Exception ex)
{
LOG.LogError(ex, "Error clearing pandoc folder.");
}
} }
public static async Task<string> FetchLatestVersionAsync() { public static async Task<string> FetchLatestVersionAsync() {
@ -222,6 +236,8 @@ 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";
private static async Task<string> GetPandocDataFolder(RustService rustService) => Path.Join(await rustService.GetDataDirectory(), "pandoc");
[GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+)")] [GeneratedRegex(@"pandoc(?:\.exe)?\s*([0-9]+\.[0-9]+)")]
private static partial Regex PandocRegex(); private static partial Regex PandocRegex();