This commit is contained in:
AMIAY
2026-01-24 12:22:15 +01:00
parent 679f065e24
commit 87b168dd4c
2 changed files with 44 additions and 27 deletions

View File

@@ -323,19 +323,19 @@ class ClientPatcher {
// FORCE PATCHING: Always patch, never skip
console.log(`Force patching server for ${newDomain}`);
if (progressCallback) {
progressCallback('Preparing to patch server...', 10);
}
console.log('Creating backup...');
this.backupClient(serverPath);
if (progressCallback) {
progressCallback('Extracting server JAR...', 20);
}
console.log('Opening server JAR...');
const zip = new AdmZip(serverPath);
let zip;
try {
zip = new AdmZip(serverPath);
} catch (zipError) {
console.error('Failed to read server JAR:', zipError.message);
return { success: false, error: `Failed to read JAR: ${zipError.message}` };
}
const entries = zip.getEntries();
console.log(`JAR contains ${entries.length} entries`);
@@ -375,7 +375,24 @@ class ClientPatcher {
}
console.log('Writing patched JAR...');
zip.writeZip(serverPath);
const tempPath = serverPath + '.patched.tmp';
// Write to temp file first to avoid corruption
try {
zip.writeZip(tempPath);
// Replace original with patched version
if (fs.existsSync(serverPath)) {
fs.unlinkSync(serverPath);
}
fs.renameSync(tempPath, serverPath);
} catch (writeError) {
// Cleanup temp file if it exists
if (fs.existsSync(tempPath)) {
fs.unlinkSync(tempPath);
}
throw writeError;
}
this.markAsPatched(serverPath);