Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update processbuilder.js to write fullscreen to options.txt #347

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions app/assets/js/processbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class ProcessBuilder {
}

//args.push('-Dlog4j.configurationFile=D:\\WesterosCraft\\game\\common\\assets\\log_configs\\client-1.12.xml')

// Java Arguments
if(process.platform === 'darwin'){
args.push('-Xdock:name=HeliosLauncher')
Expand All @@ -432,6 +432,26 @@ class ProcessBuilder {
// Vanilla Arguments
args = args.concat(this.vanillaManifest.arguments.game)

async function WriteFullscreenToOptions(filePath, lineToReplace, newLine) {
try {
const exists = await fs.pathExists(filePath);

if (exists) {
let fileContent = await fs.readFile(filePath, 'utf8');
if (fileContent.includes(lineToReplace)) {
fileContent = fileContent.replace(lineToReplace, newLine);
await fs.outputFile(filePath, fileContent);
} else {
await fs.outputFile(filePath, newLine);
}
} else {
await fs.outputFile(filePath, newLine);
}
} catch (err) {
logger.info('Error while writing fullscreen to options.txt:', err);
}
}

for(let i=0; i<args.length; i++){
if(typeof args[i] === 'object' && args[i].rules != null){

Expand All @@ -453,11 +473,16 @@ class ProcessBuilder {
// This should be fine for a while.
if(rule.features.has_custom_resolution != null && rule.features.has_custom_resolution === true){
if(ConfigManager.getFullscreen()){
logger.info("gamedir: ", this.gameDir)
WriteFullscreenToOptions(path.join(this.gameDir, "options.txt"), 'fullscreen:false', 'fullscreen:true')
args[i].value = [
'--fullscreen',
'true'
]
} else {
WriteFullscreenToOptions(path.join(this.gameDir, "options.txt"), 'fullscreen:true', 'fullscreen:false');
}

checksum++
}
}
Expand Down Expand Up @@ -891,4 +916,4 @@ class ProcessBuilder {

}

module.exports = ProcessBuilder
module.exports = ProcessBuilder