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