Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion Knossos.NET/Classes/FsoBuild.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Knossos.NET.Classes;
using Avalonia.Threading;
using Knossos.NET.Classes;
using Knossos.NET.Views;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -91,6 +93,7 @@ public class FsoBuild
public bool isInstalled = true;
public bool devMode = false;
public Mod? modData;
private static bool _flagErrorOneWarn = false;

/// <summary>
/// This is a "DirectExec" FsoBuild
Expand Down Expand Up @@ -275,6 +278,7 @@ public async Task<FsoResult> RunFSO(FsoExecType executableType, string cmdline,
}

fso.StartInfo.UseShellExecute = false;
fso.StartInfo.RedirectStandardError = true;
if (workingFolder != null)
fso.StartInfo.WorkingDirectory = workingFolder;
if (Knossos.inPortableMode && Knossos.globalSettings.portableFsoPreferences ||
Expand All @@ -301,6 +305,31 @@ public async Task<FsoResult> RunFSO(FsoExecType executableType, string cmdline,
fso.Start();
if (waitForExit)
await fso.WaitForExitAsync();

var stderr = fso.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(stderr))
{
var errorMsg = $"FSO exited with code {fso.ExitCode}\n\n\nStderr:\n{stderr}";
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", errorMsg);

if (KnUtils.IsLinux && stderr.Contains("fuse", StringComparison.OrdinalIgnoreCase))
{
var libfuseError = $"libfuse is missing! FSO AppImages needs fuse to run. Install with:\n" +
"Ubuntu/Debian: sudo apt install libfuse2\n" +
"Fedora: sudo dnf install fuse\n" +
"Arch: sudo pacman -S fuse2";
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", libfuseError);
Dispatcher.UIThread.Invoke(new Action(() => { MessageBox.Show(MainWindow.instance, libfuseError, "Unable to run FSO", MessageBox.MessageBoxButtons.OK); }));
}
else
{
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", stderr);
Dispatcher.UIThread.Invoke(new Action(() => { MessageBox.Show(MainWindow.instance, stderr, "Unable to run FSO", MessageBox.MessageBoxButtons.OK); }));
}

return new FsoResult(false);
}

return new FsoResult(true);
}
}
Expand Down Expand Up @@ -344,6 +373,7 @@ public async Task<FsoResult> RunFSO(FsoExecType executableType, string cmdline,
}

string output = string.Empty;
string stderr = string.Empty;
try
{
using (var cmd = new Process())
Expand All @@ -354,6 +384,7 @@ public async Task<FsoResult> RunFSO(FsoExecType executableType, string cmdline,
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.StartInfo.StandardOutputEncoding = new UTF8Encoding(false);
cmd.StartInfo.WorkingDirectory = folderPath;
if (Knossos.inPortableMode && Knossos.globalSettings.portableFsoPreferences ||
Expand All @@ -369,8 +400,41 @@ public async Task<FsoResult> RunFSO(FsoExecType executableType, string cmdline,

cmd.Start();
string result = cmd.StandardOutput.ReadToEnd();
stderr = cmd.StandardError.ReadToEnd();
output = result;
cmd.WaitForExit();

if (!string.IsNullOrEmpty(stderr) )
{
var errorMsg = $"FSO exited with code {cmd.ExitCode}\n\nStdout:\n{output}\n\nStderr:\n{stderr}";
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", errorMsg);

if (KnUtils.IsLinux && (stderr.Contains("fuse", StringComparison.OrdinalIgnoreCase) || output.Contains("fuse", StringComparison.OrdinalIgnoreCase)))
{
var libfuseError = $"libfuse is missing! FSO AppImages needs fuse to run. Install with:\n" +
"Ubuntu/Debian: sudo apt install libfuse2\n" +
"Fedora: sudo dnf install fuse\n" +
"Arch: sudo pacman -S fuse2";
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", libfuseError);
if (!_flagErrorOneWarn)
{
_flagErrorOneWarn = true;
Dispatcher.UIThread.Invoke(new Action(() => { MessageBox.Show(MainWindow.instance, libfuseError, "Unable to run FSO", MessageBox.MessageBoxButtons.OK); }));
}
}
else
{
Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", stderr);
if (!_flagErrorOneWarn)
{
_flagErrorOneWarn = true;
Dispatcher.UIThread.Invoke(new Action(() => { MessageBox.Show(MainWindow.instance, stderr, "Unable to run FSO", MessageBox.MessageBoxButtons.OK); }));
}
}

return null;
}

cmd.Dispose();
//avoiding the "fso is running in legacy config mode..."
if (result.Contains("{"))
Expand Down