diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef291adaa..9694f423d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: if: ${{ always() && steps.compile.outcome == 'success' }} with: SOURCE_FILE: 'bin/Release' - DEST_NAME: 'MCGalaxy_net2.0' + DEST_NAME: 'MCGalaxy-net2.0' - uses: ./.github/actions/notify_success if: ${{ always() && steps.compile.outcome == 'success' }} @@ -70,13 +70,13 @@ jobs: if: ${{ always() && steps.compile.outcome == 'success' }} with: SOURCE_FILE: 'bin/Release_normal' - DEST_NAME: 'MCGalaxy' + DEST_NAME: 'MCGalaxy-net40' - uses: ./.github/actions/upload_build if: ${{ always() && steps.compile.outcome == 'success' }} with: SOURCE_FILE: 'bin/Release' - DEST_NAME: 'MCGalaxy-infid' + DEST_NAME: 'MCGalaxy-net40-infid' - uses: ./.github/actions/notify_success if: ${{ always() && steps.compile.outcome == 'success' }} @@ -114,7 +114,7 @@ jobs: if: ${{ always() && steps.compile.outcome == 'success' }} with: SOURCE_FILE: 'CLI/bin/Debug/net6.0' - DEST_NAME: 'MCGalaxy-dotnet6.0' + DEST_NAME: 'MCGalaxy-net6.0' # publish standalone windows binaries - name: Publish-win64 @@ -183,7 +183,7 @@ jobs: if: ${{ always() && steps.compile.outcome == 'success' }} with: SOURCE_FILE: 'CLI/bin/Debug/net8.0' - DEST_NAME: 'MCGalaxy-dotnet8.0' + DEST_NAME: 'MCGalaxy-net8.0' - uses: ./.github/actions/notify_success diff --git a/MCGalaxy/Modules/Compiling/CompilerBackends.cs b/MCGalaxy/Modules/Compiling/CompilerBackends.cs index 122df4bdc..afeef7a2e 100644 --- a/MCGalaxy/Modules/Compiling/CompilerBackends.cs +++ b/MCGalaxy/Modules/Compiling/CompilerBackends.cs @@ -120,7 +120,7 @@ namespace MCGalaxy.Modules.Compiling static string Quote(string value) { return "\"" + value + "\""; } static string GetDotnetPath() { - string path = Server.GetRuntimeProcessExePath(); + string path = Server.GetRuntimeExePath(); if (path.EndsWith("dotnet")) return path; return GetBinaryFile("MCG_DOTNET_PATH", "'dotnet' executable - e.g. /home/test/.dotnet/dotnet"); diff --git a/MCGalaxy/Server/Maintenance/Updater.cs b/MCGalaxy/Server/Maintenance/Updater.cs index 02fd5c1c3..03ae79e4a 100644 --- a/MCGalaxy/Server/Maintenance/Updater.cs +++ b/MCGalaxy/Server/Maintenance/Updater.cs @@ -113,17 +113,23 @@ namespace MCGalaxy foreach (Player pl in players) pl.SaveStats(); string serverDLL = Server.GetServerDLLPath(); + string serverGUI = "MCGalaxy.exe"; +#if !MCG_DOTNET + string serverCLI = "MCGalaxyCLI.exe"; +#else + string serverCLI = Server.GetServerExePath(); +#endif // Move current files to previous files (by moving instead of copying, // can overwrite original the files without breaking the server) - AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll"); - AtomicIO.TryMove("MCGalaxy.exe", "prev_MCGalaxy.exe"); - AtomicIO.TryMove("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe"); + AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll"); + AtomicIO.TryMove(serverGUI, "prev_MCGalaxy.exe"); + AtomicIO.TryMove(serverCLI, "prev_MCGalaxyCLI.exe"); // Move update files to current files AtomicIO.TryMove("MCGalaxy_.update", serverDLL); - AtomicIO.TryMove("MCGalaxy.update", "MCGalaxy.exe"); - AtomicIO.TryMove("MCGalaxyCLI.update", "MCGalaxyCLI.exe"); + AtomicIO.TryMove("MCGalaxy.update", serverGUI); + AtomicIO.TryMove("MCGalaxyCLI.update", serverCLI); Server.Stop(true, "Updating server."); } catch (Exception ex) { diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index 8255bf302..981e2f0f3 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -263,7 +263,7 @@ namespace MCGalaxy /// Returns the full path to the server core DLL public static string GetServerDLLPath() { #if MCG_STANDALONE - return GetRuntimeProcessExePath(); + return GetRuntimeExePath(); #else return Assembly.GetExecutingAssembly().Location; #endif @@ -272,14 +272,14 @@ namespace MCGalaxy /// Returns the full path to the server executable public static string GetServerExePath() { #if MCG_STANDALONE - return GetRuntimeProcessExePath(); + return GetRuntimeExePath(); #else - return DotNetBackend.GetExePath(RestartPath); + return RestartPath; #endif } - /// Returns the full path to the runtime executable path - public static string GetRuntimeProcessExePath() { + /// Returns the full path to the runtime executable + public static string GetRuntimeExePath() { return Process.GetCurrentProcess().MainModule.FileName; } diff --git a/MCGalaxy/util/DotnetBackend.cs b/MCGalaxy/util/DotnetBackend.cs index 07abf46e1..6be9b0e2a 100644 --- a/MCGalaxy/util/DotnetBackend.cs +++ b/MCGalaxy/util/DotnetBackend.cs @@ -56,7 +56,7 @@ namespace MCGalaxy.Platform public static string GetExePath(string path) { // NET core/5/6 executables tend to use the following structure: - // MCGalaxyCLI_core --> MCGalaxyCLI_core.dll + // MCGalaxyCLI --> MCGalaxyCLI.dll // in this case, 'RestartPath' will include '.dll' since this file // is actually the managed assembly, but we need to remove '.dll' // as the actual executable which must be started is the non .dll file diff --git a/MCGalaxy/util/OperatingSystem.cs b/MCGalaxy/util/OperatingSystem.cs index 5940de02c..0b4d16135 100644 --- a/MCGalaxy/util/OperatingSystem.cs +++ b/MCGalaxy/util/OperatingSystem.cs @@ -56,8 +56,11 @@ namespace MCGalaxy.Platform /// Attempts to restart the current process /// Does not return if the restart is performed in-place /// (since the current process image is replaced) - public virtual void RestartProcess() { - Process.Start(Server.GetServerExePath()); + public virtual void RestartProcess() { + string path = Server.GetServerExePath(); + string exe = DotNetBackend.GetExePath(path); + + Process.Start(exe); } @@ -179,13 +182,15 @@ namespace MCGalaxy.Platform // try to exec using actual runtime path first // e.g. /usr/bin/mono-sgen, /home/test/.dotnet/dotnet - string exe = Server.GetRuntimeProcessExePath(); - execvp(exe, new string[] { exe, Server.RestartPath, null }); - Console.WriteLine("execvp {0} failed: {1}", exe, Marshal.GetLastWin32Error()); + string runtime = Server.GetRuntimeExePath(); + string exePath = Server.GetServerExePath(); + + execvp(runtime, new string[] { runtime, exePath, null }); + Console.WriteLine("execvp {0} failed: {1}", runtime, Marshal.GetLastWin32Error()); #if !MCG_DOTNET // .. and fallback to mono if that doesn't work for some reason - execvp("mono", new string[] { "mono", Server.RestartPath, null }); + execvp("mono", new string[] { "mono", exePath, null }); Console.WriteLine("execvp mono failed: {0}", Marshal.GetLastWin32Error()); #endif } @@ -265,7 +270,7 @@ namespace MCGalaxy.Platform try { // try to restart using process's original command line arguments so that they are preserved // e.g. for "mono --debug MCGalaxyCLI.exe" - string exe = Server.GetRuntimeProcessExePath(); + string exe = Server.GetRuntimeExePath(); string[] args = GetProcessCommandLineArgs(); execvp(exe, args); } catch (Exception ex) {