mirror of
https://gitea.shironeko-all.duckdns.org/shironeko/Hytale-F2P-2.git
synced 2026-02-26 10:41:46 -03:00
fix
This commit is contained in:
@@ -155,7 +155,22 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
|
||||
|
||||
try {
|
||||
if (progressCallback) {
|
||||
progressCallback('Updating game files...', 0, null, null, null);
|
||||
progressCallback('Backing up user data...', 5, null, null, null);
|
||||
}
|
||||
|
||||
// Backup UserData AVANT de télécharger/installer (critical for same-branch updates)
|
||||
try {
|
||||
console.log(`[UpdateGameFiles] Attempting to backup UserData from old branch: ${oldBranch}`);
|
||||
backupPath = await userDataBackup.backupUserData(installPath, oldBranch, hasVersionConfig);
|
||||
if (backupPath) {
|
||||
console.log(`[UpdateGameFiles] ✓ UserData backed up from ${oldBranch}: ${backupPath}`);
|
||||
}
|
||||
} catch (backupError) {
|
||||
console.warn('[UpdateGameFiles] ✗ UserData backup failed:', backupError.message);
|
||||
}
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Updating game files...', 10, null, null, null);
|
||||
}
|
||||
console.log(`Updating game files to version: ${newVersion} (branch: ${branch})`);
|
||||
|
||||
@@ -167,32 +182,17 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
|
||||
fs.mkdirSync(tempUpdateDir, { recursive: true });
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Downloading new game version...', 10, null, null, null);
|
||||
progressCallback('Downloading new game version...', 20, null, null, null);
|
||||
}
|
||||
|
||||
const pwrFile = await downloadPWR(branch, newVersion, progressCallback, cacheDir);
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Extracting new files...', 50, null, null, null);
|
||||
progressCallback('Extracting new files...', 60, null, null, null);
|
||||
}
|
||||
|
||||
await applyPWR(pwrFile, progressCallback, tempUpdateDir, toolsDir);
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Backing up user data...', 70, null, null, null);
|
||||
}
|
||||
|
||||
// Backup UserData from OLD branch (before switching)
|
||||
try {
|
||||
console.log(`[UpdateGameFiles] Attempting to backup UserData from old branch: ${oldBranch}`);
|
||||
backupPath = await userDataBackup.backupUserData(installPath, oldBranch, hasVersionConfig);
|
||||
if (backupPath) {
|
||||
console.log(`[UpdateGameFiles] ✓ UserData backed up from ${oldBranch}: ${backupPath}`);
|
||||
}
|
||||
} catch (backupError) {
|
||||
console.warn('[UpdateGameFiles] ✗ UserData backup failed:', backupError.message);
|
||||
}
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Replacing game files...', 80, null, null, null);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user