Attempt to fix a problem where a mod update might fail post-restart.

NOTE: Moves the jail folder where the mods folder used to be. The Jail folder is then recreated after the next restart.
This commit is contained in:
zontreck 2025-03-02 19:36:18 -07:00
parent 89d5439b8d
commit da7b56ad97
4 changed files with 33 additions and 2 deletions

View file

@ -252,10 +252,36 @@ class StateMachine {
if (settings.inst!.pterodactylMode) { if (settings.inst!.pterodactylMode) {
// Shut down the server processes now // Shut down the server processes now
PacketServer.socket!.close(); PacketServer.socket!.close();
// Check if the shutdown reason was for a Mod Update
if (SessionData.shutDownReason == ShutDownReason.MODS) {
// Delete the old Mods Folder
Directory mods = Directory(settings.getModPath());
await mods.delete(recursive: true);
Directory jail = Directory(settings.getModJailPath());
await jail.rename(settings.getModPath());
File modsTxt = settings.getModListFile();
await modsTxt.delete();
}
exit(0); exit(0);
} else { } else {
resetKillswitch(); resetKillswitch();
SessionData.timer = settings.inst!.timer.time.copy(); SessionData.timer = settings.inst!.timer.time.copy();
// Check if the shutdown reason was for a Mod Update
if (SessionData.shutDownReason == ShutDownReason.MODS) {
// Delete the old Mods Folder
Directory mods = Directory(settings.getModPath());
await mods.delete(recursive: true);
Directory jail = Directory(settings.getModJailPath());
await jail.rename(settings.getModPath());
File modsTxt = settings.getModListFile();
await modsTxt.delete();
}
await pollModUpdates(); await pollModUpdates();
changeState(States.PreStart); changeState(States.PreStart);
SessionData.enableRestartTimer = settings.inst!.timer.enabled; SessionData.enableRestartTimer = settings.inst!.timer.enabled;
@ -383,6 +409,7 @@ class StateMachine {
print( print(
"Scheduling restart for mod updates: ${updatedMods.join(', ')}"); "Scheduling restart for mod updates: ${updatedMods.join(', ')}");
SessionData.enableRestartTimer = true; SessionData.enableRestartTimer = true;
SessionData.shutDownReason = ShutDownReason.MODS;
// Send discord alert! // Send discord alert!
DiscordHookHelper.sendWebHook( DiscordHookHelper.sendWebHook(

View file

@ -47,4 +47,8 @@ class SessionData {
static List<String> IE_SNAPSHOTS = []; static List<String> IE_SNAPSHOTS = [];
static bool IS_FIRST_MOD_CHECK = true; static bool IS_FIRST_MOD_CHECK = true;
static ShutDownReason shutDownReason = ShutDownReason.NORMAL;
} }
enum ShutDownReason { MODS, NORMAL }

View file

@ -112,7 +112,7 @@ class Settings {
Future<void> Read() async { Future<void> Read() async {
if (!server) return; if (!server) return;
try { try {
var tag = await NbtIo.read(ABSOLUTE_PATH); var tag = await NbtIo.read(ABSOLUTE_PATH) as CompoundTag;
inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag); inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag);

View file

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.1.010425+1753 version: 1.1.030225+1906
environment: environment:
sdk: ">=3.1.4 <4.0.0" sdk: ">=3.1.4 <4.0.0"