Skip to content

Commit

Permalink
Add /update latest to allow updating to latest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 18, 2024
1 parent 151b75a commit c6d0e03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 8 additions & 3 deletions MCGalaxy/Commands/Maintenance/CmdUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public sealed class CmdUpdate : Command2
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);
}
Expand All @@ -40,8 +42,11 @@ public sealed class CmdUpdate : Command2
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");
}
}
}
24 changes: 15 additions & 9 deletions MCGalaxy/Server/Maintenance/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class Updater
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
Expand Down Expand Up @@ -76,21 +76,27 @@ public static class Updater
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");

Expand All @@ -104,9 +110,9 @@ public static class Updater
// 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");
Expand Down

0 comments on commit c6d0e03

Please sign in to comment.