Skip to content

Commit

Permalink
Possible correction for game log failing to open. At least provide ve…
Browse files Browse the repository at this point in the history
…rbose info.. Re: #62
  • Loading branch information
jtsage committed Feb 2, 2023
1 parent 6bcbc3d commit 1ff39c2
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function handleUnhandled(type, err, origin) {
message : `Caught ${type}: ${err}\n\nOrigin: ${origin}\n\n${err.stack}\n\n\nCan't Continue, exiting now!\n\nTo send file, please see ${crashLog}`,
type : 'error',
})
if ( gameLogFile ) { gameLogFile.close() }
if ( gameLogFile ) { gameLogFileWatch.close() }
app.quit()
} else {
log.log.debug(`Network error: ${err}`, `net-error-${type}`)
Expand Down Expand Up @@ -92,7 +92,7 @@ if ( process.platform === 'win32' && app.isPackaged && gotTheLock && !isPortable
dialog.showMessageBox(windows.main, dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
if ( tray ) { tray.destroy() }
if ( gameLogFile ) { gameLogFile.close() }
if ( gameLogFile ) { gameLogFileWatch.close() }
Object.keys(windows).forEach((thisWin) => {
if ( thisWin !== 'main' && windows[thisWin] !== null ) {
windows[thisWin].destroy()
Expand Down Expand Up @@ -126,6 +126,7 @@ let foundPath = false
let foundGame = ''

let gameLogFile = null
let gameLogFileWatch = null
let gameLogFileBounce = false

const gameExeName = 'FarmingSimulator2022.exe'
Expand Down Expand Up @@ -440,7 +441,7 @@ function createMainWindow () {
windows.main = null
if ( tray ) { tray.destroy() }
windows.load.destroy()
gameLogFile.close()
gameLogFileWatch.close()
app.quit()
})

Expand Down Expand Up @@ -1117,7 +1118,7 @@ ipcMain.on('toMain_getGameLog', () => { readGameLog() })
function readGameLog() {
if ( windows.gamelog === null ) { return }
try {
const gameLogContents = fs.readFileSync(path.join(path.dirname(gameSettings), 'log.txt'), {encoding : 'utf8', flag : 'r'})
const gameLogContents = fs.readFileSync(gameLogFile, {encoding : 'utf8', flag : 'r'})

windows.gamelog.webContents.send('fromMain_gameLog', gameLogContents)
} catch (e) {
Expand Down Expand Up @@ -1650,16 +1651,31 @@ function parseSettings({disable = null, newFolder = null, userName = null, serve
mcStore.set('game_settings', gameSettings)
}

if ( gameLogFile === null ) {
gameLogFile = fs.watch(path.join(path.dirname(gameSettings), 'log.txt'), (event, filename) => {
if ( filename ) {
if ( gameLogFileBounce ) return
gameLogFileBounce = setTimeout(() => {
gameLogFileBounce = false
readGameLog()
}, 1000)
}
})
if ( gameLogFileWatch !== null ) {
gameLogFileWatch.close()
gameLogFileWatch = null
}

if ( gameLogFileWatch === null ) {
gameLogFile = path.join(path.dirname(gameSettings), 'log.txt')
log.log.debug(`Log file probable path: ${gameLogFile}`, 'game-log')

if ( fs.existsSync(gameLogFile) ) {
gameLogFileWatch = fs.watch(gameLogFile, (event, filename) => {
if ( filename ) {
if ( gameLogFileBounce ) return
gameLogFileBounce = setTimeout(() => {
gameLogFileBounce = false
readGameLog()
}, 1000)
}
})
gameLogFileWatch.on('error', (err) => {
log.log.warning(`Error with game log: ${err}`, 'game-log')
})
} else {
log.log.warning(`Game Log not found at: ${gameLogFile}`, 'game-log')
}
}

let XMLString = ''
Expand Down

0 comments on commit 1ff39c2

Please sign in to comment.