Add /update latest to allow updating to latest commit

This commit is contained in:
UnknownShadow200 2024-05-18 10:42:28 +10:00
parent 151b75a351
commit c6d0e03d81
2 changed files with 23 additions and 12 deletions

View File

@ -30,8 +30,10 @@ namespace MCGalaxy.Commands.Maintenance
p.Message("Checking for updates..");
bool needsUpdating = Updater.NeedsUpdating();
p.Message("Server {0}", needsUpdating ? "&cneeds updating" : "&ais up to date");
} else if (message.Length == 0) {
Updater.PerformUpdate();
} else if (message.CaselessEq("latest")) {
Updater.PerformUpdate(false);
} else if (message.Length == 0) {
Updater.PerformUpdate(true);
} else {
Help(p);
}
@ -40,8 +42,11 @@ namespace MCGalaxy.Commands.Maintenance
public override void Help(Player p) {
p.Message("&T/Update check");
p.Message("&HChecks whether the server needs updating");
p.Message("&T/Update latest");
p.Message("&HUpdates the server to the latest unstable build");
p.Message("&WNote unstable builds may have more bugs or issues");
p.Message("&T/Update");
p.Message("&HForce updates the server");
p.Message("&HUpdates the server to the latest release");
}
}
}

View File

@ -32,7 +32,7 @@ namespace MCGalaxy
const string CurrentVersionURL = BaseURL + "Uploads/current_version.txt";
const string changelogURL = BaseURL + "Changelog.txt";
const string CDN_URL = "https://cdn.classicube.net/client/mcg/release/";
const string CDN_URL = "https://cdn.classicube.net/client/mcg/{0}/";
#if NET_20
const string CDN_BASE = CDN_URL + "net20/";
#else
@ -76,21 +76,27 @@ namespace MCGalaxy
return new Version(latest) > new Version(Server.Version);
}
}
public static void PerformUpdate() {
// Backwards compatibility
public static void PerformUpdate() { PerformUpdate(true); }
public static void PerformUpdate(bool release) {
try {
try {
DeleteFiles("Changelog.txt", "MCGalaxy_.update", "MCGalaxy.update", "MCGalaxyCLI.update",
"prev_MCGalaxy_.dll", "prev_MCGalaxy.exe", "prev_MCGalaxyCLI.exe");
} catch {
}
Logger.Log(LogType.SystemActivity, "Downloading update files");
string mode = release ? "release" : "latest";
Logger.Log(LogType.SystemActivity, "Downloading {0} update files", mode);
WebClient client = HttpUtil.CreateWebClient();
client.DownloadFile(DLL_URL, "MCGalaxy_.update");
client.DownloadFile(DLL_URL.Replace("{0}", mode), "MCGalaxy_.update");
#if !MCG_STANDALONE
client.DownloadFile(GUI_URL, "MCGalaxy.update");
client.DownloadFile(CLI_URL, "MCGalaxyCLI.update");
client.DownloadFile(GUI_URL.Replace("{0}", mode), "MCGalaxy.update");
client.DownloadFile(CLI_URL.Replace("{0}", mode), "MCGalaxyCLI.update");
#endif
client.DownloadFile(changelogURL, "Changelog.txt");
@ -104,9 +110,9 @@ namespace MCGalaxy
// 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");
// Move update files to current files
AtomicIO.TryMove("MCGalaxyCLI.exe", "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");