Closed Rihoj closed 4 years ago
The log doesn't show any errors, which leads me to believe this is a Linux specific issue with the GUI (when the log reaches "Application exited gracefully" the GUI is supposed to already be closed entirely).
I recently got a new computer and haven't set up my Linux VM yet to test this, but I will as soon as I find the time to.
If you want to help me debug this (which would be greatly appreciated) try using Visual Studio Code with the C# plugin, that's what I'm using and getting it to compile should be fairly straightforward.
I had the same problem on my Windows. The sync version of UnloadProgramAsync() worked fine on my Windows. Also, without buffering, modpacks.json got corrupted when the file size exceeded 32KB in debug build. But, release build still corrupted. This is my patch.
diff --git a/ModMyFactory.Export/Exporter.cs b/ModMyFactory.Export/Exporter.cs
index 720bf3f..f8a4db0 100644
--- a/ModMyFactory.Export/Exporter.cs
+++ b/ModMyFactory.Export/Exporter.cs
@@ -43,9 +43,9 @@ namespace ModMyFactory.Export
private async Task ExportPackageAsync(FileInfo file)
{
string json = JsonConvert.SerializeObject(Package, Formatting.Indented);
- using var stream = file.Open(FileMode.Create, FileAccess.Write);
- using var writer = new StreamWriter(stream);
- await writer.WriteAsync(json);
+ using var stream = new FileStream(file.FullName, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true);
+ var bytes = Encoding.UTF8.GetBytes(json);
+ await stream.WriteAsync(bytes, 0, bytes.Length);
}
private Task ExportArchiveAsync(FileInfo file)
diff --git a/ModMyFactoryGUI/Program.cs b/ModMyFactoryGUI/Program.cs
index 9cbcd68..47c5dcc 100644
--- a/ModMyFactoryGUI/Program.cs
+++ b/ModMyFactoryGUI/Program.cs
@@ -250,11 +250,11 @@ namespace ModMyFactoryGUI
_modpacks = await LoadModpacksAsync();
}
- private static async Task UnloadProgramAsync()
+ private static void UnloadProgram()
{
Log.Information("Saving settings...");
Settings.Save();
- await SaveModpacksAsync();
+ SaveModpacks();
Log.Information("Shutting down");
Log.CloseAndFlush();
}
@@ -357,7 +357,7 @@ namespace ModMyFactoryGUI
finally
{
SyncContext.EndListen();
- await UnloadProgramAsync();
+ UnloadProgram();
}
}
else
@@ -508,25 +508,10 @@ namespace ModMyFactoryGUI
code = ErrorCode.GameStart_General;
}
- await UnloadProgramAsync();
+ UnloadProgram();
return code;
}
- // This has not yet been implemented in the latest stable release of CommandLineParser so we have to paste it into here
- private static Task<TResult> MapResultAsync<T1, T2, TResult>(ParserResult<object> result,
- Func<T1, Task<TResult>> parsedFunc1,
- Func<T2, Task<TResult>> parsedFunc2,
- Func<IEnumerable<Error>, Task<TResult>> notParsedFunc)
- {
- if (result is Parsed<object> parsed)
- {
- if (parsed.Value is T1) return parsedFunc1((T1)parsed.Value);
- if (parsed.Value is T2) return parsedFunc2((T2)parsed.Value);
- throw new InvalidOperationException();
- }
- return notParsedFunc(((NotParsed<object>)result).Errors);
- }
-
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
@@ -541,7 +526,7 @@ namespace ModMyFactoryGUI
});
var parsedOptions = parser.ParseArguments<RunOptions, StartGameOptions>(args);
- var code = await MapResultAsync(parsedOptions,
+ var code = await parsedOptions.MapResult(
(RunOptions opts) => StartAppAsync(args, opts),
(StartGameOptions opts) => StartGameAsync(opts),
errors => Task.FromResult(ErrorCodeFactory.FromCommandLineErrors(errors)));
@shelaf Thank you for providing the code. Unfortunately, that did not work on my Linux machine. After playing with it for a little while I did find that this was all I had to change to get the window to close:
diff --git a/ModMyFactoryGUI/Program.cs b/ModMyFactoryGUI/Program.cs
index 9cbcd68..f09ee67 100644
--- a/ModMyFactoryGUI/Program.cs
+++ b/ModMyFactoryGUI/Program.cs
@@ -254,7 +254,7 @@ namespace ModMyFactoryGUI
{
Log.Information("Saving settings...");
Settings.Save();
- await SaveModpacksAsync();
+ SaveModpacksAsync();
Log.Information("Shutting down");
Log.CloseAndFlush();
}
I also had issue with the modpacks.json file, and your code changes there fixed that issue.
Everyone who had this issue, please try version 2.2.2
Seems to be working fine on my Windows. Thanks!
@Artentus This does seem to be working for my machine.
I am trying to make a modpack, but when I close the window the application freezes during the save. I tried to get my system setup to be able to help debug the issue, but I am running into too many errors dealing with the dotnet framework (and I am not a dotnet or C# dev) trying to get it to build.
System and application information
Description: Ubuntu 20.04.1 LTS Release: 20.04 Codename: focal
Application version: 2.2.0.11-alpha_standalone_linux64 Using only Steam Factorio 1.0 Mods preinstalledInstall steps:
sudo chmod +x ~/Downloads/2.2.0.11-alpha_standalone_linux64/ModMyFactoryGUI
Steps to reproduce
~/Downloads/2.2.0.11-alpha_standalone_linux64/ModMyFactoryGUI
Vanilla Ext
Log Output: