Skip to content

Commit

Permalink
Fix all bugs found in testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Aug 18, 2024
1 parent 95faa90 commit 94e30d8
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/modAssist_func_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ const file = {
obj.dest_filename
)

promises.push(fsPromise.cp(obj.source_file, destFile, { recursive : true }).then(() => {
promises.push(fsPromise.cp(obj.source_file, destFile, { recursive : true, force : true }).then(() => {
file.log.info('Copy succeed', obj.source_file, destFile)
results.push(file._result_ok('copy', obj.source_file, destFile))
}).catch((err) => {
Expand Down
12 changes: 8 additions & 4 deletions lib/modCheckLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ class csvFileChecker {
* @class
*/
class saveFileChecker {
#silent = false
#fileName = null
#isFolder = false
#fileHandle = null
Expand All @@ -1400,12 +1401,13 @@ class saveFileChecker {
* @param {string} fileName full file and path of save
* @param {boolean} isFolder Expect a folder
*/
constructor( fileName, isFolder ) {
constructor( fileName, isFolder, silent = false ) {
this.#silent = silent
this.#fileName = fileName
this.#isFolder = isFolder
this.#log = serveIPC.log.group(`savegame-${path.basename(fileName)}`)

this.#log.info(`Adding Save: ${fileName}`)
if ( ! this.#silent ) { this.#log.info(`Adding Save: ${fileName}`) }
}

/**
Expand All @@ -1416,6 +1418,7 @@ class saveFileChecker {
return {
errorList : this.errorList,
farms : this.farms,
isValid : this.errorList.length === 0,
mapMod : this.mapMod,
mods : this.mods,
singleFarm : this.singleFarm,
Expand All @@ -1432,8 +1435,9 @@ class saveFileChecker {
const couldOpen = await this.#fileHandle.open()

if ( ! couldOpen ) {
this.#log.danger(`Save open fail: ${this.#fileName}`)
if ( ! this.#silent ) { this.#log.danger(`Save open fail: ${this.#fileName}`) }
this.errorList.push(['SAVEGAME_UNREADABLE', this.#fileName])
this.isValid = false
return this.dataReturn
}

Expand All @@ -1450,7 +1454,7 @@ class saveFileChecker {

#util_readError(type) {
this.errorList.push(['SAVEGAME_PARSE_ERROR', `${type}.xml`])
this.#log.warning(`Parsing ${type}.xml failed`)
if ( ! this.#silent ) { this.#log.warning(`Parsing ${type}.xml failed`) }
}

#util_iterateXML(data) {
Expand Down
4 changes: 2 additions & 2 deletions lib/workerThreadLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1828,8 +1828,8 @@ class fileHandlerAsync {
}

return thisParsedXML
} catch {
this.#log.warning(`Caught unrecoverable XML Parse error : ${fileName}`)
} catch (err) {
this.#log.warning(`Caught unrecoverable XML Parse error : ${fileName} :: ${err}`)
return false
}
}).catch((err) => {
Expand Down
20 changes: 16 additions & 4 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ ipcMain.handle('files:drop', async (_, files) => {
})
return
} else if ( files.length === 1 && files[0].endsWith('.json') ) {
// TODO: HANDLE JSON IMPORT
// HANDLE JSON IMPORT
funcLib.general.importJSON_process(files[0])
return
} else if ( files.length === 1 && files[0].endsWith('.zip') ) {
// Handles ZIP packs, ZIP save game, and finally single ZIP add
const saveResult = await new saveFileChecker(files[0], false, true).getInfo()

if ( saveResult.isValid ) {
serveIPC.windowLib.createNamedWindow('save', {
collectKey : null,
thisSaveGame : saveResult,
})
return
}
return getCopyMoveDelete('import', null, null, files, await new modPackChecker(files[0]).getInfo())
} else {
return getCopyMoveDelete('import', null, null, files, false)
}
return getCopyMoveDelete('import', null, null, files, false)
})

function sendCopyMoveDelete(operation, modIDS) {
Expand Down Expand Up @@ -613,7 +623,7 @@ ipcMain.handle('gamelog:auto', () => {
ipcMain.handle('gamelog:open', () => {
return dialog.showOpenDialog(serveIPC.windowLib.win.gamelog, {
properties : ['openFile'],
defaultPath : path.join(serveIPC.prefs.basePath(), 'log.txt'),
defaultPath : path.join(funcLib.prefs.basePath(), 'log.txt'),
filters : [{ name : 'Log Files', extensions : ['txt'] }],
}).then((result) => {
if ( ! result.canceled ) { funcLib.gameSet.setGameLog(result.filePaths[0]) }
Expand Down Expand Up @@ -698,6 +708,8 @@ ipcMain.on('cache:clean', () => {
}
}

serveIPC.log.info('cache-cleaner', `Removed ${md5Set.size} stale entries.`)

for ( const md5 of md5Set ) { delete serveIPC.storeCache.remMod(md5) }

serveIPC.storeCache.saveFile()
Expand Down
16 changes: 11 additions & 5 deletions renderer/a_changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
<div class="row">
<div class="col-auto ps-4"><img class="sticky-top" style="width: auto; height: 200px; top: calc(100vh - 240px);" src="img/sidebar.webp" alt=""></div>
<div class="col">
<h4>Version 4.0.0 Features</h4>
<h4>Version 5.0.0 Features</h4>
<div class="ms-3">
<ul class="list-group list-group-flush mb-3">
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-info bg-gradient text-white">ADDED</span> Malware Detector for Mods</li>
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-success bg-gradient text-white">CHANGED</span> New ZIP Library (no more 2Gb limit)</li>
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-info bg-gradient text-white">ADDED</span> game.xml / gameSettings.xml Backups</li>
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-info bg-gradient text-white">ADDED</span> Collection Import and Export</li>
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-info bg-gradient text-white">ADDED</span> FS2025 Initial Support</li>
<li class="list-group-item bg-body"><span class="w-25 me-2 badge text-bg-success bg-gradient text-white">CHANGED</span> Backend re-write</li>
</ul>
</div>

Expand All @@ -45,6 +43,14 @@ <h4>GitHub Known Issues &amp; Changes</h4>

<h4>Added Features by Major Version</h4>
<ul class="list-group list-group-flush mb-3">
<li class="list-group-item bg-body">
5.0.0
<ul style="list-style:square;" >
<li>Another massive refactor for stability</li>
<li>Add basic FS25 support</li>
<li>Remove multi-version option, always on now</li>
</ul>
</li>
<li class="list-group-item bg-body">
4.0.0
<ul style="list-style:square;" >
Expand Down
12 changes: 6 additions & 6 deletions renderer/renderJS/importjson_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class windowState {

node.classList.add('w-75', 'd-block', 'mx-auto', 'btn', 'btn-primary', 'btn-sm', 'disabled', 'btn-download', 'mb-2')
node.innerHTML = `<i18n-text data-key="import_json_step_2_download${isPack ? '_unpack' : ''}"></i18n-text> :: ${uri}`
node.firstElementChild.addEventListener('click', () => {
node.addEventListener('click', () => {
node.firstElementChild.classList.remove('btn-primary')
node.firstElementChild.classList.add('btn-success', 'disabled')
window.importjson_IPC.doDownload(this.importKey, uri, isPack)
Expand Down Expand Up @@ -131,8 +131,8 @@ class LoaderLib {
MA.byId('loadOverlay_downloadCancel').clsShow()
MA.byId('loadOverlay_speed').clsShow()
}
updateCount(count, inMB = false) {
const thisCount = inMB ? DATA.bytesToMB(count, false) : count
async updateCount(count, inMB = false) {
const thisCount = inMB ? await DATA.bytesToMB(count, false) : count
const thisElement = MA.byId('loadOverlay_statusCurrent')
const thisProg = MA.byId('loadOverlay_statusProgBarInner')
const thisPercent = `${Math.max(Math.ceil((count / this.lastTotal) * 100), 0)}%`
Expand All @@ -145,7 +145,7 @@ class LoaderLib {
const perDone = Math.max(1, Math.ceil((count / this.lastTotal) * 100))
const perRem = 100 - perDone
const elapsedSec = (Date.now() - this.startTime) / 1000
const estSpeed = DATA.bytesToMBCalc(count, false) / elapsedSec // MB/sec
const estSpeed = await DATA.bytesToMBCalc(count, false) / elapsedSec // MB/sec
const secRemain = elapsedSec / perDone * perRem

const prettyMinRemain = Math.floor(secRemain / 60)
Expand All @@ -170,9 +170,9 @@ class LoaderLib {

this.show()
}
updateTotal(count, inMB = false) {
async updateTotal(count, inMB = false) {
if ( inMB ) { this.startTime = Date.now() }
const thisCount = inMB ? DATA.bytesToMB(count) : count
const thisCount = inMB ? await DATA.bytesToMB(count) : count
MA.byIdText('loadOverlay_statusTotal', thisCount)
this.lastTotal = ( count < 1 ) ? 1 : count
}
Expand Down
30 changes: 16 additions & 14 deletions renderer/renderJS/main_ui_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,28 +1005,28 @@ class StateManager {
},
launchGame() {
const currentList = MA.byIdValue('collectionSelect')
if ( currentList === this.flag.activeCollect ) {
if ( currentList === window.state.flag.activeCollect ) {
// Selected is active, no confirm
LEDLib.spinLED()
window.main_IPC.dispatch('game')
} else {
// Different, ask confirmation
MA.byIdHTML('no_match_game_list', this.mapCollectionDropdown[this.flag.activeCollect])
MA.byIdHTML('no_match_game_list', this.mapCollectionDropdown[window.state.flag.activeCollect])
MA.byIdHTML('no_match_ma_list', this.mapCollectionDropdown[currentList])
LEDLib.fastBlinkLED()
this.modal.mismatch.show()
window.state.modal.mismatch.show()
}
},
launchGame_FIX : () => {
this.modal.mismatch.hide()
this.action.collectActive().then(() => {
window.state.modal.mismatch.hide()
window.state.action.collectActive().then(() => {
window.main_IPC.dispatch('game')
})
},
launchGame_IGNORE : () => {
this.modal.mismatch.hide()
window.state.modal.mismatch.hide()
LEDLib.spinLED()
MA.byIdValue('collectionSelect', this.flag.activeCollect)
MA.byIdValue('collectionSelect', window.state.flag.activeCollect)
window.main_IPC.dispatch('game')
},
openModInfo : (mod) => {
Expand Down Expand Up @@ -1637,7 +1637,9 @@ class DragDropLib {
const fileList = []
for ( const thisFile of files ) { fileList.push(thisFile.path) }
window.main_IPC.files.drop(fileList).then((result) => {
window.state.files.start_external('import', result)
if ( typeof result !== 'undefined' ) {
window.state.files.start_external('import', result)
}
})
}

Expand Down Expand Up @@ -1747,8 +1749,8 @@ class LoaderLib {
MA.byId('loadOverlay_downloadCancel').clsShow()
MA.byId('loadOverlay_speed').clsShow()
}
updateCount(count, inMB = false) {
const thisCount = inMB ? DATA.bytesToMB(count, false) : count
async updateCount(count, inMB = false) {
const thisCount = inMB ? await DATA.bytesToMB(count, false) : count
const thisElement = MA.byId('loadOverlay_statusCurrent')
const thisProg = MA.byId('loadOverlay_statusProgBarInner')
const thisPercent = `${Math.max(Math.ceil((count / this.lastTotal) * 100), 0)}%`
Expand All @@ -1761,7 +1763,7 @@ class LoaderLib {
const perDone = Math.max(1, Math.ceil((count / this.lastTotal) * 100))
const perRem = 100 - perDone
const elapsedSec = (Date.now() - this.startTime) / 1000
const estSpeed = DATA.bytesToMBCalc(count, false) / elapsedSec // MB/sec
const estSpeed = await DATA.bytesToMBCalc(count, false) / elapsedSec // MB/sec
const secRemain = elapsedSec / perDone * perRem

const prettyMinRemain = Math.floor(secRemain / 60)
Expand All @@ -1786,9 +1788,9 @@ class LoaderLib {

this.show()
}
updateTotal(count, inMB = false) {
async updateTotal(count, inMB = false) {
if ( inMB ) { this.startTime = Date.now() }
const thisCount = inMB ? DATA.bytesToMB(count) : count
const thisCount = inMB ? await DATA.bytesToMB(count) : count
MA.byIdText('loadOverlay_statusTotal', thisCount)
this.lastTotal = ( count < 1 ) ? 1 : count
}
Expand Down Expand Up @@ -2026,7 +2028,7 @@ class FileLib {
<path d="M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5z"/>
</svg>`,
shortname : shortName,
title : zipFiles === null ? path : [...zipFiles].join('<br>'),
title : zipFiles === null ? path.replaceAll('\\', '\\<wbr>') : [...zipFiles].join('<br>'),
})
}

Expand Down
4 changes: 2 additions & 2 deletions renderer/renderJS/mini_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ class StateManager {
},
launchGame : () => {
const currentList = MA.byIdValue('collectionSelect')
if ( currentList === this.track.activeCollect ) {
if ( currentList === this.flag.activeCollect ) {
// Selected is active, no confirm
LEDLib.spinLED()
window.mods.startFarmSim()
window.mini_IPC.startFarmSim()
} else if ( this.flasherInterval === null ) {
// Different, ask confirmation
LEDLib.fastBlinkLED()
Expand Down
2 changes: 1 addition & 1 deletion renderer/renderJS/resolve_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class windowState {

// MARK: copy button action
MA.byIdEventIfExists('copyButton', () => {
window.fileOpOverlay.show()
this.overlay.show()
MA.byId('fileOpWorking').clsShow()
MA.byId('fileOpSuccess').clsHide()
MA.byId('fileOpDanger').clsHide()
Expand Down
2 changes: 1 addition & 1 deletion renderer/renderJS/util/storeItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const ST = {

let nameString = thisProduction.name

if ( thisProduction.params !== null ) {
if ( typeof thisProduction.params !== 'undefined' && thisProduction.params !== null ) {
const paramArray = thisProduction.params.split('|')
let matchNum = -1
nameString = nameString.replace(/%s/g, () => {
Expand Down
2 changes: 1 addition & 1 deletion renderer/renderJS/version_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function displayData(data) {
class : ['badge-mod-notmod'],
skip : !isDiff || thisItem.modhub === null,
}),
I18N.buildBadgeBare({
I18N.buildBadge({
name : isDiff ? 'version_diff' : 'version_same',
class : [],
}),
Expand Down
2 changes: 1 addition & 1 deletion renderer/resolve.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<div class="ms-2 flex-grow-1">
<div class="fw-bold"><template-var>shortName</template-var> <span class="small"><template-var>version</template-var></span></div>
<div class="small text-body-tertiary"><template-var>title</template-var></div>
<div class="small text-body-emphasis ps-3"><i18n-text data-key="destination"></i18n-text> <template-var>collectName</template-var></div>
<div class="small text-body-emphasis ps-3"><i18n-text class="text-body" data-key="destination"></i18n-text> <template-var>collectName</template-var></div>
</div>
<div class="flex-grow-0 h-100 align-content-center">
<input class="form-check-input form-check modToCopy fileOpCheck" type="checkbox" name="modToCopy[]">
Expand Down
2 changes: 1 addition & 1 deletion renderer/version.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<div class="small ps-2 mt-2"><ul class="collection-list"><template-var>collections</template-var></ul></div>
</div>
<div class="col-4 text-end">
<div class="badgeContainer d-flex flex-wrap fs-4 justify-content-end gap-1 mb-2"></div>
<div class="badgeContainer d-flex flex-wrap fs-5 justify-content-end gap-1 mb-2"></div>
<div class="actionButton"></div>
</div>
</div>
Expand Down

0 comments on commit 94e30d8

Please sign in to comment.