mirror of
https://github.com/themitosan/fpPS4-Temmie-s-Launcher.git
synced 2025-04-02 10:31:50 -04:00
261 lines
No EOL
5.7 KiB
JavaScript
261 lines
No EOL
5.7 KiB
JavaScript
/*
|
|
******************************************************************************
|
|
fpPS4 Temmie's Launcher
|
|
settings.js
|
|
|
|
This file is contains all functions / variables related to settings menu
|
|
and Launcher's look, behavior and more.
|
|
******************************************************************************
|
|
*/
|
|
|
|
temp_SETTINGS = {
|
|
|
|
// Settings list
|
|
data: {
|
|
|
|
/*
|
|
General
|
|
*/
|
|
|
|
// Remove previous imported modules
|
|
removedLibModules: !1,
|
|
|
|
// Paths
|
|
nwPath: '',
|
|
emuPath: '',
|
|
gamePath: '',
|
|
|
|
// Enable / Disable PARAM.SFO support
|
|
enableParamSfo: !0,
|
|
|
|
// Log External window
|
|
logExternalWindowPrompt: !0,
|
|
logExternalWindowStartMode: 'normal',
|
|
|
|
/*
|
|
GUI
|
|
*/
|
|
|
|
// Game search mode (appName or titleId)
|
|
gameSearchMode: 'appName',
|
|
searchCaseSensitive: !1,
|
|
|
|
// Background Opacity
|
|
bgEmuOpacity: 0.6,
|
|
bgListOpacity: 0.7,
|
|
|
|
// Background Blur
|
|
bgEmuBlur: 6,
|
|
bgListBlur: 2,
|
|
|
|
// (Grid)
|
|
gridIconSize: 116,
|
|
gridBorderRadius: 8,
|
|
|
|
showBgOnEntry: !0,
|
|
showPathEntry: !0,
|
|
showPathRunning: !0,
|
|
gameListMode: 'normal'
|
|
|
|
},
|
|
|
|
// Load settings
|
|
load: function(){
|
|
|
|
// Get launcher main dir before settings load
|
|
var updateSettings = !1,
|
|
nwPath = APP.tools.fixPath(nw.__dirname);
|
|
|
|
// Create save
|
|
if (APP.fs.existsSync(nwPath + '/Settings.json') === !1){
|
|
APP.settings.save();
|
|
}
|
|
|
|
try {
|
|
|
|
// Read settings file
|
|
var loadSettings = JSON.parse(APP.fs.readFileSync(nwPath + '/Settings.json', 'utf8'));
|
|
|
|
// Check for obsolete settings
|
|
Object.keys(loadSettings).forEach(function(cSettings){
|
|
|
|
if (APP.settings.data[cSettings] === void 0){
|
|
delete loadSettings[cSettings];
|
|
updateSettings = !0;
|
|
}
|
|
|
|
});
|
|
|
|
// Fix new settings data
|
|
Object.keys(this.data).forEach(function(cSettings){
|
|
|
|
if (loadSettings[cSettings] === void 0){
|
|
loadSettings[cSettings] = APP.settings.data[cSettings];
|
|
updateSettings = !0;
|
|
}
|
|
|
|
});
|
|
|
|
// Load settings
|
|
this.data = loadSettings;
|
|
|
|
// Check if need to update settings file
|
|
if (updateSettings === !0){
|
|
APP.log('INFO - Settings file was updated successfully!');
|
|
APP.settings.save();
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('ERROR - Unable to load settings!\n' + err);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Save settings
|
|
save: function(){
|
|
|
|
// Get launcher main dir before settings load
|
|
const nwPath = APP.tools.fixPath(nw.__dirname);
|
|
|
|
try {
|
|
APP.fs.writeFileSync(nwPath + '/Settings.json', JSON.stringify(this.data), 'utf8');
|
|
} catch (err) {
|
|
console.error('ERROR - Unable to save settings!\n' + err);
|
|
}
|
|
|
|
},
|
|
|
|
// Check paths
|
|
checkPaths: function(){
|
|
|
|
// Fix path
|
|
this.data.nwPath = APP.tools.fixPath(nw.__dirname);
|
|
|
|
var logMessage = '',
|
|
mainPath = this.data.nwPath,
|
|
pathList = ['/Emu', '/Games'];
|
|
|
|
// Try create required paths
|
|
pathList.forEach(function(cPath){
|
|
|
|
if (APP.fs.existsSync(mainPath + cPath) !== !0){
|
|
|
|
try {
|
|
APP.fs.mkdirSync(mainPath + cPath);
|
|
} catch (err) {
|
|
APP.log('ERROR - Unable to create path!\n(' + mainPath + cPath + ')\n' + err);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Set Games / Emu paths and check if both exists
|
|
if (this.data.gamePath === '' && APP.fs.existsSync(this.data.gamePath) === !1){
|
|
APP.settings.data.gamePath = mainPath + '/Games';
|
|
}
|
|
|
|
// fpPS4 path
|
|
if (this.data.emuPath === '' || APP.fs.existsSync(this.data.emuPath) === !1){
|
|
APP.settings.data.emuPath = mainPath + '/Emu/fpPS4.exe';
|
|
}
|
|
if (APP.fs.existsSync(this.data.emuPath) === !0){
|
|
|
|
logMessage = 'INFO - Main fpPS4 was found!\nPath: ' + APP.settings.data.emuPath + '\n ';
|
|
|
|
} else {
|
|
|
|
logMessage = 'ERROR - Unable to locate main fpPS4 executable!\nMake sure to select it on settings or insert it on \"Emu\" folder and click on ok.';
|
|
window.alert(logMessage);
|
|
|
|
}
|
|
|
|
// Log message
|
|
APP.log(logMessage);
|
|
|
|
},
|
|
|
|
// Select path
|
|
selectPath: function(data){
|
|
|
|
APP.fileManager.selectPath(function(newGamePath){
|
|
document.getElementById(data.label).innerHTML = newGamePath;
|
|
APP.settings.data[data.settings] = newGamePath;
|
|
APP.settings.save();
|
|
APP.gameList.load();
|
|
});
|
|
|
|
},
|
|
|
|
// Select file
|
|
selectFile: function(data){
|
|
|
|
APP.fileManager.selectFile(data.extension, function(newEmuPath){
|
|
document.getElementById(data.label).innerHTML = newEmuPath;
|
|
APP.settings.data[data.settings] = newEmuPath;
|
|
APP.settings.save();
|
|
APP.gameList.load();
|
|
});
|
|
|
|
},
|
|
|
|
// Reset all game settings
|
|
resetAllGameSettings: function(){
|
|
|
|
// Confirm action
|
|
const conf = window.confirm('WARN - This option will remove ALL saved settings from your game list.\nDo you want to continue?');
|
|
if (conf === !0){
|
|
|
|
// Reset search form
|
|
document.getElementById('INPUT_gameListSearch').value = '';
|
|
|
|
// Get game list
|
|
var cMessage = '',
|
|
gList = Object.keys(APP.gameList.list);
|
|
|
|
// Check if user has games and apps
|
|
if (gList.length !== 0){
|
|
|
|
// Process game list
|
|
gList.forEach(function(cGame){
|
|
|
|
// Check if settings file exists
|
|
if (APP.fs.existsSync(APP.path.parse(APP.gameList.list[cGame].exe).dir + '/launcherSettings.json') === !0){
|
|
|
|
try {
|
|
|
|
APP.fs.unlinkSync(APP.path.parse(APP.gameList.list[cGame].exe).dir + '/launcherSettings.json');
|
|
cMessage = 'INFO - ( ' + APP.gameList.list[cGame].name + ' ) Settings file was removed sucessfully!';
|
|
|
|
} catch (err) {
|
|
|
|
cMessage = 'ERROR - ( ' + APP.gameList.list[cGame].name + ' ) Unable to delete settings file!\nReason: ' + err;
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unable to find settings file
|
|
cMessage = 'WARN - ( ' + APP.gameList.list[cGame].name + ' ) Unable to find settings for this App / Game!';
|
|
|
|
}
|
|
|
|
// Log status
|
|
APP.log(cMessage);
|
|
|
|
});
|
|
|
|
// Process complete
|
|
window.alert('INFO - Process Complete!\nCheck log for more details.');
|
|
APP.log('INFO - Reset Game Settings: Process Complete!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |