pre-release & release game version [to check]

This commit is contained in:
AMIAY
2026-01-23 17:54:57 +01:00
parent 08c2218cf8
commit 3983fdb1bc
19 changed files with 888 additions and 302 deletions

View File

@@ -304,6 +304,30 @@ function loadGpuPreference() {
return config.gpuPreference || 'auto';
}
function saveVersionClient(versionClient) {
saveConfig({ version_client: versionClient });
}
function loadVersionClient() {
const config = loadConfig();
return config.version_client !== undefined ? config.version_client : null;
}
function saveVersionBranch(versionBranch) {
const branch = versionBranch || 'release';
if (branch !== 'release' && branch !== 'pre-release') {
console.warn(`Invalid branch "${branch}", defaulting to "release"`);
saveConfig({ version_branch: 'release' });
} else {
saveConfig({ version_branch: branch });
}
}
function loadVersionBranch() {
const config = loadConfig();
return config.version_branch || 'release';
}
module.exports = {
loadConfig,
saveConfig,
@@ -343,5 +367,10 @@ module.exports = {
loadGpuPreference,
// Close Launcher export
saveCloseLauncherOnStart,
loadCloseLauncherOnStart
loadCloseLauncherOnStart,
// Version Management exports
saveVersionClient,
loadVersionClient,
saveVersionBranch,
loadVersionBranch
};

View File

@@ -33,7 +33,12 @@ const {
resetCurrentUserUuid,
// GPU Preference
saveGpuPreference,
loadGpuPreference
loadGpuPreference,
// Version Management
saveVersionClient,
loadVersionClient,
saveVersionBranch,
loadVersionBranch
} = require('./core/config');
const { getResolvedAppDir, getModsPath } = require('./core/paths');
@@ -138,6 +143,10 @@ module.exports = {
// Version functions
getInstalledClientVersion,
getLatestClientVersion,
saveVersionClient,
loadVersionClient,
saveVersionBranch,
loadVersionBranch,
// News functions
getHytaleNews,

View File

@@ -7,7 +7,7 @@ const { spawn } = require('child_process');
const { v4: uuidv4 } = require('uuid');
const { getResolvedAppDir, findClientPath } = require('../core/paths');
const { setupWaylandEnvironment, setupGpuEnvironment } = require('../utils/platformUtils');
const { saveUsername, saveInstallPath, loadJavaPath, getUuidForUser, getAuthServerUrl, getAuthDomain } = require('../core/config');
const { saveUsername, saveInstallPath, loadJavaPath, getUuidForUser, getAuthServerUrl, getAuthDomain, loadVersionBranch, loadVersionClient, saveVersionClient } = require('../core/config');
const { resolveJavaPath, getJavaExec, getBundledJavaPath, detectSystemJava, JAVA_EXECUTABLE } = require('./javaManager');
const { getInstalledClientVersion, getLatestClientVersion } = require('../services/versionManager');
const { updateGameFiles } = require('./gameManager');
@@ -101,10 +101,11 @@ function generateLocalTokens(uuid, name) {
};
}
async function launchGame(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto') {
async function launchGame(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) {
const branch = branchOverride || loadVersionBranch();
const customAppDir = getResolvedAppDir(installPathOverride);
const customGameDir = path.join(customAppDir, 'release', 'package', 'game', 'latest');
const customJreDir = path.join(customAppDir, 'release', 'package', 'jre', 'latest');
const customGameDir = path.join(customAppDir, branch, 'package', 'game', 'latest');
const customJreDir = path.join(customAppDir, branch, 'package', 'jre', 'latest');
const userDataDir = path.join(customGameDir, 'Client', 'UserData');
const gameLatest = customGameDir;
@@ -151,13 +152,14 @@ async function launchGame(playerName = 'Player', progressCallback, javaPathOverr
const { identityToken, sessionToken } = await fetchAuthTokens(uuid, playerName);
// Patch client and server binaries to use custom auth server (BEFORE signing on macOS)
// FORCE patch on every launch to ensure consistency
const authDomain = getAuthDomain();
if (clientPatcher) {
try {
if (progressCallback) {
progressCallback('Patching game for custom server...', null, null, null, null);
}
console.log(`Patching game binaries for ${authDomain}...`);
console.log(`Force patching game binaries for ${authDomain}...`);
const patchResult = await clientPatcher.ensureClientPatched(gameLatest, (msg, percent) => {
console.log(`[Patcher] ${msg}`);
@@ -167,16 +169,12 @@ async function launchGame(playerName = 'Player', progressCallback, javaPathOverr
});
if (patchResult.success) {
if (patchResult.alreadyPatched) {
console.log(`Game already patched for ${authDomain}`);
} else {
console.log(`Game patched successfully (${patchResult.patchCount} total occurrences)`);
if (patchResult.client) {
console.log(` Client: ${patchResult.client.patchCount || 0} occurrences`);
}
if (patchResult.server) {
console.log(` Server: ${patchResult.server.patchCount || 0} occurrences`);
}
console.log(`Game patched successfully (${patchResult.patchCount} total occurrences)`);
if (patchResult.client) {
console.log(` Client: ${patchResult.client.patchCount || 0} occurrences`);
}
if (patchResult.server) {
console.log(` Server: ${patchResult.server.patchCount || 0} occurrences`);
}
} else {
console.warn('Game patching failed:', patchResult.error);
@@ -355,23 +353,23 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
}
}
async function launchGameWithVersionCheck(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto') {
async function launchGameWithVersionCheck(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) {
try {
const branch = branchOverride || loadVersionBranch();
if (progressCallback) {
progressCallback('Checking for updates...', 0, null, null, null);
}
const [installedVersion, latestVersion] = await Promise.all([
getInstalledClientVersion(),
getLatestClientVersion()
]);
const installedVersion = loadVersionClient();
const latestVersion = await getLatestClientVersion(branch);
console.log(`Installed version: ${installedVersion}, Latest version: ${latestVersion}`);
console.log(`Installed version: ${installedVersion}, Latest version: ${latestVersion} (branch: ${branch})`);
let needsUpdate = false;
if (installedVersion && latestVersion && installedVersion !== latestVersion) {
if (!installedVersion || installedVersion !== latestVersion) {
needsUpdate = true;
console.log('Version mismatch detected, update required');
console.log('Version mismatch or not installed, update required');
}
if (needsUpdate) {
@@ -380,13 +378,13 @@ async function launchGameWithVersionCheck(playerName = 'Player', progressCallbac
}
const customAppDir = getResolvedAppDir(installPathOverride);
const customGameDir = path.join(customAppDir, 'release', 'package', 'game', 'latest');
const customGameDir = path.join(customAppDir, branch, 'package', 'game', 'latest');
const customToolsDir = path.join(customAppDir, 'butler');
const customCacheDir = path.join(customAppDir, 'cache');
try {
await updateGameFiles(latestVersion, progressCallback, customGameDir, customToolsDir, customCacheDir);
console.log('Game updated successfully, waiting before launch...');
await updateGameFiles(latestVersion, progressCallback, customGameDir, customToolsDir, customCacheDir, branch);
console.log('Game updated successfully, patching will be forced on launch...');
if (progressCallback) {
progressCallback('Preparing game launch...', 90, null, null, null);
@@ -406,7 +404,7 @@ async function launchGameWithVersionCheck(playerName = 'Player', progressCallbac
progressCallback('Launching game...', 80, null, null, null);
}
return await launchGame(playerName, progressCallback, javaPathOverride, installPathOverride, gpuPreference);
return await launchGame(playerName, progressCallback, javaPathOverride, installPathOverride, gpuPreference, branch);
} catch (error) {
console.error('Error in version check and launch:', error);
if (progressCallback) {

View File

@@ -7,10 +7,11 @@ const { downloadFile } = require('../utils/fileManager');
const { getLatestClientVersion, getInstalledClientVersion } = require('../services/versionManager');
const { installButler } = require('./butlerManager');
const { downloadAndReplaceHomePageUI, downloadAndReplaceLogo } = require('./uiFileManager');
const { saveUsername, saveInstallPath, loadJavaPath, CONFIG_FILE, loadConfig } = require('../core/config');
const { saveUsername, saveInstallPath, loadJavaPath, CONFIG_FILE, loadConfig, loadVersionBranch, saveVersionClient, loadVersionClient } = require('../core/config');
const { resolveJavaPath, detectSystemJava, downloadJRE, getJavaExec, getBundledJavaPath } = require('./javaManager');
const userDataBackup = require('../utils/userDataBackup');
async function downloadPWR(version = 'release', fileName = '4.pwr', progressCallback, cacheDir = CACHE_DIR) {
async function downloadPWR(branch = 'release', fileName = '4.pwr', progressCallback, cacheDir = CACHE_DIR) {
const osName = getOS();
const arch = getArch();
@@ -18,9 +19,9 @@ async function downloadPWR(version = 'release', fileName = '4.pwr', progressCall
throw new Error('Hytale x86_64 Intel Mac Support has not been released yet. Please check back later.');
}
const url = `https://game-patches.hytale.com/patches/${osName}/${arch}/${version}/0/${fileName}`;
const url = `https://game-patches.hytale.com/patches/${osName}/${arch}/${branch}/0/${fileName}`;
const dest = path.join(cacheDir, fileName);
const dest = path.join(cacheDir, `${branch}_${fileName}`);
if (fs.existsSync(dest)) {
console.log('PWR file found in cache:', dest);
@@ -104,13 +105,22 @@ async function applyPWR(pwrFile, progressCallback, gameDir = GAME_DIR, toolsDir
console.log('Installation complete');
}
async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR, toolsDir = TOOLS_DIR, cacheDir = CACHE_DIR) {
async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR, toolsDir = TOOLS_DIR, cacheDir = CACHE_DIR, branchOverride = null) {
let tempUpdateDir;
let backupPath = null;
const branch = branchOverride || loadVersionBranch();
const installPath = path.dirname(path.dirname(path.dirname(path.dirname(gameDir))));
// Vérifier si on a version_client et version_branch dans config.json
const config = loadConfig();
const hasVersionConfig = !!(config.version_client && config.version_branch);
console.log(`[UpdateGameFiles] hasVersionConfig: ${hasVersionConfig}`);
try {
if (progressCallback) {
progressCallback('Updating game files...', 0, null, null, null);
}
console.log(`Updating game files to version: ${newVersion}`);
console.log(`Updating game files to version: ${newVersion} (branch: ${branch})`);
tempUpdateDir = path.join(gameDir, '..', 'temp_update');
@@ -123,7 +133,7 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
progressCallback('Downloading new game version...', 10, null, null, null);
}
const pwrFile = await downloadPWR('release', newVersion, progressCallback, cacheDir);
const pwrFile = await downloadPWR(branch, newVersion, progressCallback, cacheDir);
if (progressCallback) {
progressCallback('Extracting new files...', 50, null, null, null);
@@ -132,34 +142,18 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
await applyPWR(pwrFile, progressCallback, tempUpdateDir, toolsDir);
if (progressCallback) {
progressCallback('Replacing game files...', 80, null, null, null);
progressCallback('Backing up user data...', 70, null, null, null);
}
let userDataBackup = null;
const userDataPath = findUserDataRecursive(gameDir);
// Backup UserData using new system
try {
backupPath = await userDataBackup.backupUserData(installPath, branch, hasVersionConfig);
} catch (backupError) {
console.warn('UserData backup failed:', backupError.message);
}
if (userDataPath && fs.existsSync(userDataPath)) {
userDataBackup = path.join(gameDir, '..', 'UserData_backup_' + Date.now());
console.log(`Backing up UserData from ${userDataPath} to: ${userDataBackup}`);
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const files = fs.readdirSync(src);
for (const file of files) {
copyRecursive(path.join(src, file), path.join(dest, file));
}
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursive(userDataPath, userDataBackup);
} else {
console.log('No UserData folder found in game directory');
if (progressCallback) {
progressCallback('Replacing game files...', 80, null, null, null);
}
if (fs.existsSync(gameDir)) {
@@ -175,44 +169,26 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
const logoResult = await downloadAndReplaceLogo(gameDir, progressCallback);
console.log('Logo@2x.png update result after update:', logoResult);
if (userDataBackup && fs.existsSync(userDataBackup)) {
const newUserDataPath = findUserDataPath(gameDir);
const userDataParent = path.dirname(newUserDataPath);
if (progressCallback) {
progressCallback('Restoring user data...', 90, null, null, null);
}
if (!fs.existsSync(userDataParent)) {
fs.mkdirSync(userDataParent, { recursive: true });
// Restore UserData using new system
if (backupPath) {
try {
await userDataBackup.restoreUserData(backupPath, installPath, branch);
await userDataBackup.cleanupBackup(backupPath);
} catch (restoreError) {
console.warn('UserData restore failed:', restoreError.message);
}
console.log(`Restoring UserData to: ${newUserDataPath}`);
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const files = fs.readdirSync(src);
for (const file of files) {
copyRecursive(path.join(src, file), path.join(dest, file));
}
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursive(userDataBackup, newUserDataPath);
}
console.log(`Game files updated successfully to version: ${newVersion}`);
if (userDataBackup && fs.existsSync(userDataBackup)) {
try {
fs.rmSync(userDataBackup, { recursive: true, force: true });
console.log('UserData backup cleaned up');
} catch (cleanupError) {
console.warn('Could not clean up UserData backup:', cleanupError.message);
}
}
// Save the updated version and branch to config
saveVersionClient(newVersion);
const { saveVersionBranch } = require('../core/config');
saveVersionBranch(branch);
console.log('Waiting for file system sync...');
await new Promise(resolve => setTimeout(resolve, 2000));
@@ -225,9 +201,9 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
} catch (error) {
console.error('Error updating game files:', error);
if (userDataBackup && fs.existsSync(userDataBackup)) {
if (backupPath) {
try {
fs.rmSync(userDataBackup, { recursive: true, force: true });
await userDataBackup.cleanupBackup(backupPath);
console.log('UserData backup cleaned up after error');
} catch (cleanupError) {
console.warn('Could not clean up UserData backup:', cleanupError.message);
@@ -242,21 +218,45 @@ async function updateGameFiles(newVersion, progressCallback, gameDir = GAME_DIR,
}
}
function isGameInstalled() {
function isGameInstalled(branchOverride = null) {
const branch = branchOverride || loadVersionBranch();
const appDir = getResolvedAppDir();
const gameDir = path.join(appDir, 'release', 'package', 'game', 'latest');
const gameDir = path.join(appDir, branch, 'package', 'game', 'latest');
const clientPath = findClientPath(gameDir);
return clientPath !== null;
}
async function installGame(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride) {
async function installGame(playerName = 'Player', progressCallback, javaPathOverride, installPathOverride, branchOverride = null) {
const branch = branchOverride || loadVersionBranch();
const customAppDir = getResolvedAppDir(installPathOverride);
const customCacheDir = path.join(customAppDir, 'cache');
const customToolsDir = path.join(customAppDir, 'butler');
const customGameDir = path.join(customAppDir, 'release', 'package', 'game', 'latest');
const customJreDir = path.join(customAppDir, 'release', 'package', 'jre', 'latest');
const customGameDir = path.join(customAppDir, branch, 'package', 'game', 'latest');
const customJreDir = path.join(customAppDir, branch, 'package', 'jre', 'latest');
const userDataDir = path.join(customGameDir, 'Client', 'UserData');
// Vérifier si on a version_client et version_branch dans config.json
const config = loadConfig();
const hasVersionConfig = !!(config.version_client && config.version_branch);
console.log(`[InstallGame] Configuration détectée - version_client: ${config.version_client}, version_branch: ${config.version_branch}`);
console.log(`[InstallGame] hasVersionConfig: ${hasVersionConfig}`);
// Backup UserData AVANT l'installation si nécessaire
let backupPath = null;
if (progressCallback) {
progressCallback('Checking for existing UserData...', 5, null, null, null);
}
try {
console.log(`[InstallGame] Tentative de backup UserData (hasVersionConfig: ${hasVersionConfig})...`);
backupPath = await userDataBackup.backupUserData(customAppDir, branch, hasVersionConfig);
if (backupPath) {
console.log(`[InstallGame] ✓ UserData sauvegardé dans: ${backupPath}`);
}
} catch (backupError) {
console.warn('[InstallGame] ✗ Backup UserData échoué:', backupError.message);
}
[customAppDir, customCacheDir, customToolsDir].forEach(dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
@@ -313,18 +313,47 @@ async function installGame(playerName = 'Player', progressCallback, javaPathOver
if (progressCallback) {
progressCallback('Fetching game files...', null, null, null, null);
}
console.log('Installing game files...');
console.log(`Installing game files for branch: ${branch}...`);
const latestVersion = await getLatestClientVersion();
const pwrFile = await downloadPWR('release', latestVersion, progressCallback, customCacheDir);
const latestVersion = await getLatestClientVersion(branch);
const pwrFile = await downloadPWR(branch, latestVersion, progressCallback, customCacheDir);
await applyPWR(pwrFile, progressCallback, customGameDir, customToolsDir);
// Save the installed version and branch to config
saveVersionClient(latestVersion);
const { saveVersionBranch } = require('../core/config');
saveVersionBranch(branch);
const homeUIResult = await downloadAndReplaceHomePageUI(customGameDir, progressCallback);
console.log('HomePage.ui update result after installation:', homeUIResult);
const logoResult = await downloadAndReplaceLogo(customGameDir, progressCallback);
console.log('Logo@2x.png update result after installation:', logoResult);
// Ensure UserData directory exists
if (!fs.existsSync(userDataDir)) {
console.log(`[InstallGame] Création du dossier UserData dans: ${userDataDir}`);
fs.mkdirSync(userDataDir, { recursive: true });
}
// Restore UserData from backup if exists
if (backupPath) {
if (progressCallback) {
progressCallback('Restoring UserData...', 95, null, null, null);
}
try {
console.log(`[InstallGame] Restauration du UserData depuis: ${backupPath}`);
await userDataBackup.restoreUserData(backupPath, customAppDir, branch);
await userDataBackup.cleanupBackup(backupPath);
console.log('[InstallGame] ✓ UserData restauré avec succès');
} catch (restoreError) {
console.warn('[InstallGame] ✗ Erreur lors de la restauration UserData:', restoreError.message);
}
} else {
console.log('[InstallGame] Aucun backup à restaurer, dossier UserData vide créé');
}
if (progressCallback) {
progressCallback('Installation complete', 100, null, null, null);
}
@@ -357,8 +386,9 @@ async function uninstallGame() {
}
}
function checkExistingGameInstallation() {
function checkExistingGameInstallation(branchOverride = null) {
try {
const branch = branchOverride || loadVersionBranch();
const config = loadConfig();
if (!config.installPath || !config.installPath.trim()) {
@@ -366,7 +396,7 @@ function checkExistingGameInstallation() {
}
const installPath = config.installPath.trim();
const gameDir = path.join(installPath, 'HytaleF2P', 'release', 'package', 'game', 'latest');
const gameDir = path.join(installPath, 'HytaleF2P', branch, 'package', 'game', 'latest');
if (!fs.existsSync(gameDir)) {
return null;
@@ -384,7 +414,8 @@ function checkExistingGameInstallation() {
clientPath: clientPath,
userDataPath: userDataPath,
installPath: installPath,
hasUserData: userDataPath && fs.existsSync(userDataPath)
hasUserData: userDataPath && fs.existsSync(userDataPath),
branch: branch
};
} catch (error) {
console.error('Error checking existing game installation:', error);
@@ -392,40 +423,32 @@ function checkExistingGameInstallation() {
}
}
async function repairGame(progressCallback) {
async function repairGame(progressCallback, branchOverride = null) {
const branch = branchOverride || loadVersionBranch();
const appDir = getResolvedAppDir();
const gameDir = path.join(appDir, 'release', 'package', 'game', 'latest');
const gameDir = path.join(appDir, branch, 'package', 'game', 'latest');
const installPath = appDir;
let backupPath = null;
// Vérifier si on a version_client et version_branch dans config.json
const config = loadConfig();
const hasVersionConfig = !!(config.version_client && config.version_branch);
console.log(`[RepairGame] hasVersionConfig: ${hasVersionConfig}`);
// Check if game exists
if (!fs.existsSync(gameDir)) {
throw new Error('Game directory not found. Cannot repair.');
}
// Locate UserData
const userDataPath = findUserDataRecursive(gameDir);
let userDataBackup = null;
if (progressCallback) {
progressCallback('Backing up user data...', 10, null, null, null);
}
// Backup UserData
if (userDataPath && fs.existsSync(userDataPath)) {
userDataBackup = path.join(appDir, 'UserData_backup_repair_' + Date.now());
console.log(`Backing up UserData during repair from ${userDataPath} to ${userDataBackup}`);
// Copy function
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(child => copyRecursive(path.join(src, child), path.join(dest, child)));
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursive(userDataPath, userDataBackup);
// Backup UserData using new system
try {
backupPath = await userDataBackup.backupUserData(installPath, branch, hasVersionConfig);
} catch (backupError) {
console.warn('UserData backup failed during repair:', backupError.message);
}
if (progressCallback) {
@@ -446,39 +469,21 @@ async function repairGame(progressCallback) {
// Passing null/undefined for overrides to use defaults/saved configs
// installGame calls progressCallback internally
await installGame('Player', progressCallback);
await installGame('Player', progressCallback, null, null, branch);
// Restore UserData
if (userDataBackup && fs.existsSync(userDataBackup)) {
// Restore UserData using new system
if (backupPath) {
if (progressCallback) {
progressCallback('Restoring user data...', 90, null, null, null);
}
// installGame creates: path.join(customGameDir, 'Client', 'UserData')
const newGameDir = path.join(appDir, 'release', 'package', 'game', 'latest');
const newUserDataPath = path.join(newGameDir, 'Client', 'UserData');
if (!fs.existsSync(newUserDataPath)) {
fs.mkdirSync(newUserDataPath, { recursive: true });
try {
await userDataBackup.restoreUserData(backupPath, installPath, branch);
await userDataBackup.cleanupBackup(backupPath);
console.log('UserData restored successfully after repair');
} catch (restoreError) {
console.warn('UserData restore failed after repair:', restoreError.message);
}
console.log(`Restoring UserData to ${newUserDataPath}`);
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(child => copyRecursive(path.join(src, child), path.join(dest, child)));
} else {
fs.copyFileSync(src, dest);
}
}
copyRecursive(userDataBackup, newUserDataPath);
// Cleanup Backup
console.log('Cleaning up repair backup...');
fs.rmSync(userDataBackup, { recursive: true, force: true });
}
if (progressCallback) {

View File

@@ -1,6 +1,6 @@
const path = require('path');
const fs = require('fs');
const { markAsLaunched, loadConfig } = require('../core/config');
const { markAsLaunched, loadConfig, saveVersionBranch, saveVersionClient, loadVersionBranch, loadVersionClient } = require('../core/config');
const { checkExistingGameInstallation, updateGameFiles } = require('../managers/gameManager');
const { getInstalledClientVersion, getLatestClientVersion } = require('./versionManager');
@@ -56,6 +56,20 @@ async function handleFirstLaunchCheck(progressCallback) {
try {
const config = loadConfig();
// Initialize version_branch and version_client if not set
const currentBranch = loadVersionBranch();
const currentVersion = loadVersionClient();
if (!currentBranch) {
console.log('Initializing version_branch to "release"');
saveVersionBranch('release');
}
if (currentVersion === undefined || currentVersion === null) {
console.log('Initializing version_client to null (will trigger installation)');
saveVersionClient(null);
}
if (config.hasLaunchedBefore === true) {
return { isFirstLaunch: false, needsUpdate: false };
}

View File

@@ -1,9 +1,10 @@
const axios = require('axios');
async function getLatestClientVersion() {
async function getLatestClientVersion(branch = 'release') {
try {
console.log('Fetching latest client version from API...');
console.log(`Fetching latest client version from API (branch: ${branch})...`);
const response = await axios.get('https://files.hytalef2p.com/api/version_client', {
params: { branch },
timeout: 5000,
headers: {
'User-Agent': 'Hytale-F2P-Launcher'
@@ -12,7 +13,7 @@ async function getLatestClientVersion() {
if (response.data && response.data.client_version) {
const version = response.data.client_version;
console.log(`Latest client version: ${version}`);
console.log(`Latest client version for ${branch}: ${version}`);
return version;
} else {
console.log('Warning: Invalid API response, falling back to default version');

View File

@@ -11,6 +11,18 @@ class UpdateManager {
}
async checkForUpdates() {
// Disabled: Using electron-updater for automatic updates instead
console.log('Update check skipped - using electron-updater');
console.log(`Current version: ${CURRENT_VERSION}`);
return {
updateAvailable: false,
currentVersion: CURRENT_VERSION,
newVersion: CURRENT_VERSION,
message: 'Using electron-updater for automatic updates'
};
/* kept for reference
try {
console.log('Checking for updates...');
console.log(`Local version: ${CURRENT_VERSION}`);
@@ -54,6 +66,7 @@ class UpdateManager {
currentVersion: CURRENT_VERSION
};
}
*/
}
getDownloadUrl() {

View File

@@ -0,0 +1,129 @@
const fs = require('fs-extra');
const path = require('path');
/**
* Backup and restore UserData folder during game updates
*/
class UserDataBackup {
/**
* Backup UserData folder to a temporary location
* @param {string} installPath - Base installation path (e.g., C:\Users\...\HytaleF2P)
* @param {string} branch - Branch name (release or pre-release)
* @param {boolean} hasVersionConfig - True if config.json has version_client and version_branch
* @returns {Promise<string|null>} - Path to backup or null if no UserData found
*/
async backupUserData(installPath, branch, hasVersionConfig = true) {
let userDataPath;
// Si on n'a pas de version_client/version_branch dans config.json,
// c'est une ancienne installation, on cherche dans installPath/HytaleF2P/release
if (!hasVersionConfig) {
const oldPath = path.join(installPath, 'HytaleF2P', 'release', 'package', 'game', 'latest', 'Client', 'UserData');
console.log(`[UserDataBackup] Pas de version_client/version_branch détecté, recherche ancienne installation dans: ${oldPath}`);
if (fs.existsSync(oldPath)) {
userDataPath = oldPath;
console.log(`[UserDataBackup] ✓ Ancienne installation trouvée ! UserData existe dans l'ancien emplacement`);
} else {
console.log(`[UserDataBackup] ✗ Aucune ancienne installation trouvée dans ${oldPath}`);
userDataPath = path.join(installPath, branch, 'package', 'game', 'latest', 'Client', 'UserData');
}
} else {
// Si on a version_client/version_branch, on cherche dans installPath/HytaleF2P/<branch>
userDataPath = path.join(installPath, branch, 'package', 'game', 'latest', 'Client', 'UserData');
console.log(`[UserDataBackup] Version configurée, recherche dans: ${userDataPath}`);
}
if (!fs.existsSync(userDataPath)) {
console.log(`[UserDataBackup] ✗ Aucun UserData trouvé à ${userDataPath}, backup ignoré`);
return null;
}
console.log(`[UserDataBackup] ✓ UserData trouvé à ${userDataPath}`);
const backupPath = path.join(installPath, `UserData_backup_${branch}_${Date.now()}`);
try {
console.log(`[UserDataBackup] Copie de ${userDataPath} vers ${backupPath}...`);
await fs.copy(userDataPath, backupPath, {
overwrite: true,
errorOnExist: false
});
console.log('[UserDataBackup] ✓ Backup complété avec succès');
return backupPath;
} catch (error) {
console.error('[UserDataBackup] ✗ Erreur lors du backup:', error);
throw new Error(`Failed to backup UserData: ${error.message}`);
}
}
/**
* Restore UserData folder from backup
* @param {string} backupPath - Path to the backup folder
* @param {string} installPath - Base installation path
* @param {string} branch - Branch name (release or pre-release)
* @returns {Promise<boolean>} - True if restored, false otherwise
*/
async restoreUserData(backupPath, installPath, branch) {
if (!backupPath || !fs.existsSync(backupPath)) {
console.log('No backup to restore or backup path does not exist');
return false;
}
const userDataPath = path.join(installPath, branch, 'package', 'game', 'latest', 'Client', 'UserData');
try {
console.log(`Restoring UserData from ${backupPath} to ${userDataPath}`);
// Ensure parent directory exists
const parentDir = path.dirname(userDataPath);
if (!fs.existsSync(parentDir)) {
await fs.ensureDir(parentDir);
}
await fs.copy(backupPath, userDataPath, {
overwrite: true,
errorOnExist: false
});
console.log('UserData restore completed successfully');
return true;
} catch (error) {
console.error('Error restoring UserData:', error);
throw new Error(`Failed to restore UserData: ${error.message}`);
}
}
/**
* Clean up backup folder
* @param {string} backupPath - Path to the backup folder to delete
* @returns {Promise<boolean>} - True if deleted, false otherwise
*/
async cleanupBackup(backupPath) {
if (!backupPath || !fs.existsSync(backupPath)) {
return false;
}
try {
console.log(`Cleaning up backup at ${backupPath}`);
await fs.remove(backupPath);
console.log('Backup cleanup completed');
return true;
} catch (error) {
console.error('Error cleaning up backup:', error);
return false;
}
}
/**
* Check if UserData exists for a specific branch
* @param {string} installPath - Base installation path
* @param {string} branch - Branch name (release or pre-release)
* @returns {boolean} - True if UserData exists
*/
hasUserData(installPath, branch) {
const userDataPath = path.join(installPath, branch, 'package', 'game', 'latest', 'Client', 'UserData');
return fs.existsSync(userDataPath);
}
}
module.exports = new UserDataBackup();