mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 17:41:36 +00:00
Some checks failed
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
51 lines
2.4 KiB
C#
51 lines
2.4 KiB
C#
using AIStudio.Dialogs;
|
|
using AIStudio.Tools.PluginSystem;
|
|
using AIStudio.Tools.Services;
|
|
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
|
|
|
namespace AIStudio.Tools;
|
|
|
|
public static class UserFile
|
|
{
|
|
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(UserFile).Namespace, nameof(UserFile));
|
|
|
|
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(UserFile));
|
|
|
|
/// <summary>
|
|
/// Attempts to load the content of a file at the specified path, ensuring Pandoc is installed and available before proceeding.
|
|
/// </summary>
|
|
/// <param name="filePath">The full path to the file to be read. Must not be null or empty.</param>
|
|
/// <param name="rustService">Rust service used to read file content.</param>
|
|
/// <param name="dialogService">Dialogservice used to display the Pandoc installation dialog if needed.</param>
|
|
public static async Task<string> LoadFileData(string filePath, RustService rustService, IDialogService dialogService)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
{
|
|
LOGGER.LogError("Can't load from an empty or null file path.");
|
|
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, TB("The file path is null or empty and the file therefore can not be loaded.")));
|
|
}
|
|
|
|
// Ensure that Pandoc is installed and ready:
|
|
var pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: false);
|
|
if (!pandocState.IsAvailable)
|
|
{
|
|
var dialogParameters = new DialogParameters<PandocDialog>
|
|
{
|
|
{ x => x.ShowInitialResultInSnackbar, false },
|
|
};
|
|
|
|
var dialogReference = await dialogService.ShowAsync<PandocDialog>(TB("Pandoc Installation"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
await dialogReference.Result;
|
|
|
|
pandocState = await Pandoc.CheckAvailabilityAsync(rustService, showSuccessMessage: true);
|
|
if (!pandocState.IsAvailable)
|
|
{
|
|
LOGGER.LogError("Pandoc is not available after installation attempt.");
|
|
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Cancel, TB("Pandoc may be required for importing files.")));
|
|
}
|
|
}
|
|
|
|
var fileContent = await rustService.ReadArbitraryFileData(filePath, int.MaxValue);
|
|
return fileContent;
|
|
}
|
|
} |