Skip to content

Commit

Permalink
Fix game log selection, #69 and #65
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Feb 10, 2023
1 parent f7aaba2 commit dc08049
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
37 changes: 33 additions & 4 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const settingsSchema = {
cache_version : { type : 'string', default : '0.0.0' },
color_theme : { type : 'string', default : 'dark', enum : ['dark', 'light', 'system']},
force_lang : { type : 'string', default : '' },
game_log_auto : { type : 'boolean', default : true },
game_log_file : { type : ['string', 'null'], default : null },
game_version : { type : 'number', default : 22, enum : [22, 19, 17, 15, 13]},
led_active : { type : 'boolean', default : true },
Expand Down Expand Up @@ -1274,6 +1275,11 @@ ipcMain.on('toMain_openGameLog', () => {
})
ipcMain.on('toMain_openGameLogFolder', () => { shell.showItemInFolder(mcStore.get('game_log_file')) })
ipcMain.on('toMain_getGameLog', () => { readGameLog() })
ipcMain.on('toMain_guessGameLog', () => {
mcStore.set('game_log_auto', true)
loadGameLog()
readGameLog()
})
ipcMain.on('toMain_changeGameLog', () => {
dialog.showOpenDialog(windows.prefs, {
properties : ['openFile'],
Expand All @@ -1295,7 +1301,16 @@ ipcMain.on('toMain_changeGameLog', () => {
function readGameLog() {
if ( windows.gamelog === null ) { return }

const thisGameLog = mcStore.get('game_log_file', null)
let thisGameLog = null

if ( mcStore.get('game_log_auto') ) {
const currentVersion = mcStore.get('game_version')
const gameSettings = mcStore.get( currentVersion === 22 ? 'game_settings' : `game_settings_${currentVersion}`)
thisGameLog = path.join(path.dirname(gameSettings), 'log.txt')
// guess from gamesettings
} else {
thisGameLog = mcStore.get('game_log_file', null)
}

if ( thisGameLog === null ) { return }

Expand Down Expand Up @@ -1511,6 +1526,8 @@ ipcMain.on('toMain_setGamePath', (event, version) => {
ipcMain.on('toMain_setGameVersion', (event, newVersion) => {
mcStore.set('game_version', newVersion)
parseSettings()
loadGameLog()
readGameLog()
refreshClientModList()
})
/** END: Preferences window operation */
Expand Down Expand Up @@ -1830,16 +1847,28 @@ function refreshClientModList(closeLoader = true) {

/** END: Utility & Convenience Functions */


/** Business Functions */
function loadGameLog(newPath = false) {
if ( newPath ) { mcStore.set('game_log_file', newPath) }
if ( newPath ) {
mcStore.set('game_log_file', newPath)
mcStore.set('game_log_auto', false)
}

if ( newPath || gameLogFileWatch !== null ) {
if ( gameLogFileWatch !== null ) {
gameLogFileWatch.close()
gameLogFileWatch = null
}

const thisGameLog = mcStore.get('game_log_file', null)
let thisGameLog = null

if ( mcStore.get('game_log_auto') ) {
const currentVersion = mcStore.get('game_version')
const gameSettings = mcStore.get( currentVersion === 22 ? 'game_settings' : `game_settings_${currentVersion}`)
thisGameLog = path.join(path.dirname(gameSettings), 'log.txt')
} else {
thisGameLog = mcStore.get('game_log_file', null)
}

if ( thisGameLog !== null && gameLogFileWatch === null ) {
log.log.debug(`Trying to open game log: ${thisGameLog}`, 'game-log')
Expand Down
11 changes: 6 additions & 5 deletions renderer/gamelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ <h2 class="ps-2 mastHead mb-0"><l10n name="app_name"></l10n></h2>
<span class="ps-4 small fst-italic" id="gameLogPath"></span>
</div>
<div class="col-4 text-end pe-5">
<div class="btn-group w-100 ms-auto me-1">
<button data-bs-toggle="tooltip" title="Open new log" type="button" onclick="window.gamelog.changeGameLogFile()" class="btn btn-secondary btn-sm"><i class="bi bi-folder2-open"></i></button>
<button data-bs-toggle="tooltip" title="Open log in Explorer" type="button" onclick="window.gamelog.openGameLogFolder()" class="btn btn-secondary btn-sm"><i class="bi bi-save"></i></button>
<button data-bs-toggle="tooltip" title="Refresh Log" type="button" onclick="window.gamelog.getGameLogContents()" class="btn btn-secondary btn-sm"><i class="bi bi-arrow-clockwise"></i></button>
<div class="btn-group btn-group-sm ms-auto me-1 align-items-center w-100">
<button data-bs-placement="bottom" data-bs-toggle="tooltip" title="Auto-Detect Log File Based on Game Version" type="button" onclick="window.gamelog.guessGameLogFile()" class="btn btn-secondary">AUTO</button>
<button data-bs-placement="bottom" data-bs-toggle="tooltip" title="Open new log" type="button" onclick="window.gamelog.changeGameLogFile()" class="btn btn-secondary"><i class="bi bi-folder2-open"></i></button>
<button data-bs-placement="bottom" data-bs-toggle="tooltip" title="Open log in Explorer" type="button" onclick="window.gamelog.openGameLogFolder()" class="btn btn-secondary"><i class="bi bi-save"></i></button>
<button data-bs-placement="bottom" data-bs-toggle="tooltip" title="Refresh Log" type="button" onclick="window.gamelog.getGameLogContents()" class="btn btn-secondary"><i class="bi bi-arrow-clockwise"></i></button>
<input type="checkbox" class="btn-check" id="auto_scroll" autocomplete="off">
<label data-bs-toggle="tooltip" title="Auto-Scroll to Bottom on change" class="btn btn-outline-success btn-sm border" for="auto_scroll"><i class="bi bi-align-bottom"></i></label>
<label data-bs-placement="bottom" data-bs-toggle="tooltip" title="Auto-Scroll to Bottom on change" class="btn btn-outline-success border" for="auto_scroll"><i class="bi bi-align-bottom"></i></label>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions renderer/preload/preload-gamelogWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contextBridge.exposeInMainWorld(
{
changeGameLogFile : () => { ipcRenderer.send('toMain_changeGameLog') },
getGameLogContents : () => { ipcRenderer.send('toMain_getGameLog') },
guessGameLogFile : () => { ipcRenderer.send('toMain_guessGameLog') },
openCText : () => { ipcRenderer.send('toMain_logContextMenu') },
openGameLogFolder : () => { ipcRenderer.send('toMain_openGameLogFolder') },

Expand Down
1 change: 1 addition & 0 deletions renderer/renderJS/gamelog_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ window.gamelog.receive('fromMain_gameLog', (data, fileName) => {
},
info : {
regex : [
new RegExp(/Application: /),
new RegExp(/Info:/),
new RegExp(/Info \(.+?\):/),
],
Expand Down

0 comments on commit dc08049

Please sign in to comment.