Giter VIP home page Giter VIP logo

Comments (6)

Artentus avatar Artentus commented on June 12, 2024

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.

from modmyfactory2.

shelaf avatar shelaf commented on June 12, 2024

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)));

from modmyfactory2.

Rihoj avatar Rihoj commented on June 12, 2024

@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.

from modmyfactory2.

Artentus avatar Artentus commented on June 12, 2024

Everyone who had this issue, please try version 2.2.2

from modmyfactory2.

shelaf avatar shelaf commented on June 12, 2024

Seems to be working fine on my Windows. Thanks!

from modmyfactory2.

Rihoj avatar Rihoj commented on June 12, 2024

@Artentus This does seem to be working for my machine.

from modmyfactory2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.