mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-12 08:47:47 -04:00
Don't hardcode CLI path when updating dotnet build
This commit is contained in:
parent
dee6bee1f3
commit
dd8ff425df
10
.github/workflows/build.yml
vendored
10
.github/workflows/build.yml
vendored
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
@ -263,7 +263,7 @@ namespace MCGalaxy
|
||||
/// <summary> Returns the full path to the server core DLL </summary>
|
||||
public static string GetServerDLLPath() {
|
||||
#if MCG_STANDALONE
|
||||
return GetRuntimeProcessExePath();
|
||||
return GetRuntimeExePath();
|
||||
#else
|
||||
return Assembly.GetExecutingAssembly().Location;
|
||||
#endif
|
||||
@ -272,14 +272,14 @@ namespace MCGalaxy
|
||||
/// <summary> Returns the full path to the server executable </summary>
|
||||
public static string GetServerExePath() {
|
||||
#if MCG_STANDALONE
|
||||
return GetRuntimeProcessExePath();
|
||||
return GetRuntimeExePath();
|
||||
#else
|
||||
return DotNetBackend.GetExePath(RestartPath);
|
||||
return RestartPath;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary> Returns the full path to the runtime executable path </summary>
|
||||
public static string GetRuntimeProcessExePath() {
|
||||
/// <summary> Returns the full path to the runtime executable </summary>
|
||||
public static string GetRuntimeExePath() {
|
||||
return Process.GetCurrentProcess().MainModule.FileName;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -57,7 +57,10 @@ namespace MCGalaxy.Platform
|
||||
/// <remarks> Does not return if the restart is performed in-place
|
||||
/// (since the current process image is replaced) </remarks>
|
||||
public virtual void RestartProcess() {
|
||||
Process.Start(Server.GetServerExePath());
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user