mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 08:01:46 -03:00
refactor: split main file into smaller modules for better maintainability
This commit is contained in:
116
backend/managers/uiFileManager.js
Normal file
116
backend/managers/uiFileManager.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { downloadFile, findHomePageUIPath, findLogoPath } = require('../utils/fileManager');
|
||||
|
||||
async function downloadAndReplaceHomePageUI(gameDir, progressCallback) {
|
||||
try {
|
||||
console.log('Downloading HomePage.ui from server...');
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Downloading HomePage.ui...', null, null, null, null);
|
||||
}
|
||||
|
||||
const homeUIUrl = 'http://3.10.208.30:3002/api/HomeUI';
|
||||
const tempHomePath = path.join(path.dirname(gameDir), 'HomePage_temp.ui');
|
||||
|
||||
await downloadFile(homeUIUrl, tempHomePath);
|
||||
|
||||
const existingHomePath = findHomePageUIPath(gameDir);
|
||||
|
||||
if (existingHomePath && fs.existsSync(existingHomePath)) {
|
||||
console.log('Found existing HomePage.ui at:', existingHomePath);
|
||||
|
||||
const backupPath = existingHomePath + '.backup';
|
||||
if (!fs.existsSync(backupPath)) {
|
||||
fs.copyFileSync(existingHomePath, backupPath);
|
||||
console.log('Original HomePage.ui backed up');
|
||||
}
|
||||
|
||||
fs.copyFileSync(tempHomePath, existingHomePath);
|
||||
console.log('HomePage.ui replaced successfully');
|
||||
} else {
|
||||
console.log('No existing HomePage.ui found, skipping replacement');
|
||||
}
|
||||
|
||||
if (fs.existsSync(tempHomePath)) {
|
||||
fs.unlinkSync(tempHomePath);
|
||||
}
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('HomePage.ui updated', null, null, null, null);
|
||||
}
|
||||
|
||||
return { success: true, updated: true };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error downloading/replacing HomePage.ui:', error);
|
||||
|
||||
const tempHomePath = path.join(path.dirname(gameDir), 'HomePage_temp.ui');
|
||||
if (fs.existsSync(tempHomePath)) {
|
||||
fs.unlinkSync(tempHomePath);
|
||||
}
|
||||
|
||||
console.log('HomePage.ui update failed, continuing...');
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadAndReplaceLogo(gameDir, progressCallback) {
|
||||
try {
|
||||
console.log('Downloading Logo@2x.png from server...');
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Downloading Logo@2x.png...', null, null, null, null);
|
||||
}
|
||||
|
||||
const logoUrl = 'http://3.10.208.30:3002/api/Logo';
|
||||
const tempLogoPath = path.join(path.dirname(gameDir), 'Logo@2x_temp.png');
|
||||
|
||||
await downloadFile(logoUrl, tempLogoPath);
|
||||
|
||||
const existingLogoPath = findLogoPath(gameDir);
|
||||
|
||||
if (existingLogoPath && fs.existsSync(existingLogoPath)) {
|
||||
console.log('Found existing Logo@2x.png at:', existingLogoPath);
|
||||
|
||||
const backupPath = existingLogoPath + '.backup';
|
||||
if (!fs.existsSync(backupPath)) {
|
||||
fs.copyFileSync(existingLogoPath, backupPath);
|
||||
console.log('Original Logo@2x.png backed up');
|
||||
}
|
||||
|
||||
fs.copyFileSync(tempLogoPath, existingLogoPath);
|
||||
console.log('Logo@2x.png replaced successfully');
|
||||
} else {
|
||||
console.log('No existing Logo@2x.png found, skipping replacement');
|
||||
}
|
||||
|
||||
if (fs.existsSync(tempLogoPath)) {
|
||||
fs.unlinkSync(tempLogoPath);
|
||||
}
|
||||
|
||||
if (progressCallback) {
|
||||
progressCallback('Logo@2x.png updated', null, null, null, null);
|
||||
}
|
||||
|
||||
return { success: true, updated: true };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error downloading/replacing Logo@2x.png:', error);
|
||||
|
||||
const tempLogoPath = path.join(path.dirname(gameDir), 'Logo@2x_temp.png');
|
||||
if (fs.existsSync(tempLogoPath)) {
|
||||
fs.unlinkSync(tempLogoPath);
|
||||
}
|
||||
|
||||
console.log('Logo@2x.png update failed, continuing...');
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
downloadAndReplaceHomePageUI,
|
||||
findHomePageUIPath,
|
||||
downloadAndReplaceLogo,
|
||||
findLogoPath
|
||||
};
|
||||
Reference in New Issue
Block a user