From 5036e8dea04d3d8ed336a5a63ef2a80d44f3a59e Mon Sep 17 00:00:00 2001 From: "J.T. Sage" Date: Thu, 13 Oct 2022 12:10:48 -0400 Subject: [PATCH] Bump to 0.9.4 - re-work internal file counter / tester to be a bit easier to augment. --- lib/single-mod-checker.js | 204 +++++++++++++++++++------------------- modAssist_main.js | 2 +- package.json | 2 +- renderer/detail.html | 2 +- test/mod-reader-test.js | 1 + 5 files changed, 107 insertions(+), 104 deletions(-) diff --git a/lib/single-mod-checker.js b/lib/single-mod-checker.js index 5952ac0b..ddf4dea7 100644 --- a/lib/single-mod-checker.js +++ b/lib/single-mod-checker.js @@ -17,17 +17,14 @@ const parseDDS = require('parse-dds') const PNG = require('pngjs').PNG class modFileChecker { - #validFileTypes = [ - '.png', '.anim', '.ogg', '.dds', '.i3d', '.shapes', '.lua', - '.gdm', '.cache', '.xml', '.grle', '.gls', '/' - ] + #maxFilesType = { grle : 10, png : 128, txt : 2, pdf : 1 } #fileSizeMap = { - dds : [( 12 * 1024 * 1024 ), 'dds_too_big'], - xml : [( 0.25 * 1024 * 1024 ), 'xml_too_big'], - shapes : [( 256 * 1024 * 1024 ), 'shapes_too_big'], - cache : [( 10 * 1024 * 1024 ), 'i3d_too_big'], - gdm : [( 18 * 1024 * 1024 ), 'gdm_too_big'], + dds : ( 12 * 1024 * 1024 ), + xml : ( 0.25 * 1024 * 1024 ), + shapes : ( 256 * 1024 * 1024 ), + cache : ( 10 * 1024 * 1024 ), + gdm : ( 18 * 1024 * 1024 ), } #failFlags = { @@ -55,6 +52,8 @@ class modFileChecker { gdm_too_big : false, // 18MB grle_too_many : false, // 10 png_too_many : false, // 128 + pdf_too_many : false, + txt_too_many : false, space_in_file : false, // (internal files) l10n_not_set : false, // set on processL10n if either null } @@ -82,6 +81,8 @@ class modFileChecker { shapes_too_big : 'PERF_SHAPES_TOO_BIG', // 256MB gdm_too_big : 'PERF_GDM_TOO_BIG', // 18MB grle_too_many : 'PERF_GRLE_TOO_MANY', // 10 + pdf_too_many : 'PERF_PDF_TOO_MANY', // 1 + txt_too_many : 'PERF_TXT_TOO_MANY', // 2 png_too_many : 'PERF_PNG_TOO_MANY', // 128 space_in_file : 'PERF_SPACE_IN_FILE', // (internal files) l10n_not_set : 'PERF_L10N_NOT_SET', // set on processL10n if either null @@ -409,58 +410,18 @@ class modFileChecker { return } - const fileMax = { grle : 10, png : 128 } - zipEntries.forEach((entry) => { - let isExtraFile = true - - Object.keys(this.#fileSizeMap).forEach((fileType) => { - if ( entry.entryName.endsWith(`.${fileType}`) ) { - if ( entry.header.size > this.#fileSizeMap[fileType][0] ) { - this.#failFlags[this.#fileSizeMap[fileType][1]] = true - this.fileDetail.tooBigFiles.push(entry.entryName) - } - } - }) - if ( entry.entryName.includes(' ') ) { - this.fileDetail.spaceFiles.push(entry.entryName) - this.#failFlags.space_in_file = true - } - if ( entry.entryName.endsWith('.grle') ) { - fileMax.grle-- - } - if ( entry.entryName.endsWith('.png') ) { - this.fileDetail.imageNonDDS.push(entry.entryName) - if ( entry.entryName.includes('texture') ) { - this.fileDetail.pngTexture.push(entry.entryName) - this.#failFlags.png_texture = true - } - fileMax.png-- - } - if ( entry.entryName.endsWith('.dds') ) { - this.fileDetail.imageDDS.push(entry.entryName) - } - if ( entry.entryName.endsWith('.l64') || entry.entryName.endsWith('productID.dat')) { - this.#failFlags.might_be_crack = true - } - if ( entry.entryName.endsWith('.lua') ) { - this.modDesc.scriptFiles++ - } - if ( entry.entryName.endsWith('.i3d') ) { - this.fileDetail.i3dFiles.push(entry.entryName) - } - - for ( const suffix of this.#validFileTypes ) { - if ( isExtraFile && entry.entryName.endsWith(suffix) ) { isExtraFile = false } - } - if ( isExtraFile ) { - this.#failFlags.has_extra_files = true - this.fileDetail.extraFiles.push(entry.entryName) - } + this.#checkInternalFile( + path.extname(entry.entryName), + entry.entryName, + entry.header.size + ) }) - - if ( fileMax.grle < 1 ) { this.#failFlags.grle_too_many = true } - if ( fileMax.png < 1 ) { this.#failFlags.png_too_many = true } + + this.#failFlags.grle_too_many = ( this.#maxFilesType.grle < 1 ) + this.#failFlags.png_too_many = ( this.#maxFilesType.png < 1 ) + this.#failFlags.pdf_too_many = ( this.#maxFilesType.pdf < 1 ) + this.#failFlags.txt_too_many = ( this.#maxFilesType.txt < 1 ) try { this.modDesc.xmlDoc = zipFile.readAsText('modDesc.xml') @@ -494,53 +455,20 @@ class modFileChecker { const allFileList = glob.sync('**', { cwd : this.fileDetail.fullPath, mark : true }) - const fileMax = { grle : 10, png : 128 } - for ( const checkFile of allFileList ) { const fileStats = fs.statSync(path.join(this.fileDetail.fullPath, checkFile)) - let extraFile = true - - Object.keys(this.#fileSizeMap).forEach((fileType) => { - if ( checkFile.endsWith(`.${fileType}`) ) { - if ( fileStats.size > this.#fileSizeMap[fileType][0] ) { - this.#failFlags[this.#fileSizeMap[fileType][1]] = true - this.fileDetail.tooBigFiles.push(checkFile) - } - } - }) - - for ( const suffix of this.#validFileTypes ) { - if ( extraFile && checkFile.endsWith(suffix) ) { - extraFile = false - } - } - - if ( checkFile.includes(' ') ) { - this.fileDetail.spaceFiles.push(checkFile) - this.#failFlags.space_in_file = true - } - if ( extraFile ) { this.#failFlags.has_extra_files = true; this.fileDetail.extraFiles.push(checkFile) } - if ( checkFile.endsWith('.i3d') ) { this.fileDetail.i3dFiles.push(checkFile) } - if ( checkFile.endsWith('.dds') ) { this.fileDetail.imageDDS.push(checkFile) } - if ( checkFile.endsWith('.png') ) { - fileMax.png-- - this.fileDetail.imageNonDDS.push(checkFile) - if ( checkFile.includes('texture') ) { - this.fileDetail.pngTexture.push(checkFile) - this.#failFlags.png_texture = true - } - } - if ( checkFile.endsWith('.grle') ) { fileMax.grle-- } - if ( checkFile.endsWith('.lua') ) { this.modDesc.scriptFiles++ } - - if ( checkFile.endsWith('.l64') ) { this.#failFlags.might_be_crack = true } - if ( checkFile.endsWith('productID.dat') ) { this.#failFlags.might_be_crack = true } + this.#checkInternalFile( + path.extname(checkFile), + checkFile, + fileStats.size + ) } - if ( fileMax.grle < 1 ) { this.#failFlags.grle_too_many = true } - if ( fileMax.png < 1 ) { this.#failFlags.png_too_many = true } - + this.#failFlags.grle_too_many = ( this.#maxFilesType.grle < 1 ) + this.#failFlags.png_too_many = ( this.#maxFilesType.png < 1 ) + this.#failFlags.pdf_too_many = ( this.#maxFilesType.pdf < 1 ) + this.#failFlags.txt_too_many = ( this.#maxFilesType.txt < 1 ) if ( ! this.#failFlags.no_modDesc ) { this.#processModDesc() @@ -567,6 +495,80 @@ class modFileChecker { return true } + #checkInternalFile(suffix, fileName, size) { + if ( fileName.includes(' ') ) { + this.fileDetail.spaceFiles.push(fileName) + this.#failFlags.space_in_file = true + } + + if ( !fileName.endsWith('/') && !fileName.endsWith('\\') ) { + switch (suffix) { + case '.png' : + this.#maxFilesType.png-- + this.fileDetail.imageNonDDS.push(fileName) + break + case '.dds' : + this.fileDetail.imageDDS.push(fileName) + if ( size > this.#fileSizeMap.dds ) { + this.fileDetail.tooBigFiles.push(fileName) + this.#failFlags.dds_too_big = true + } + break + case '.i3d' : + this.fileDetail.i3dFiles.push(fileName) + break + case '.shapes' : + if ( size > this.#fileSizeMap.shapes ) { + this.fileDetail.tooBigFiles.push(fileName) + this.#failFlags.i3d_too_big = true + } + break + case '.lua' : + this.modDesc.scriptFiles++ + break + case '.gdm' : + if ( size > this.#fileSizeMap.gdm ) { + this.fileDetail.tooBigFiles.push(fileName) + this.#failFlags.gdm_too_big = true + } + break + case '.cache' : + if ( size > this.#fileSizeMap.cache ) { + this.fileDetail.tooBigFiles.push(fileName) + this.#failFlags.i3d_too_big = true + } + break + case '.xml' : + if ( size > this.#fileSizeMap.xml ) { + this.fileDetail.tooBigFiles.push(fileName) + this.#failFlags.xml_too_big = true + } + break + case '.grle' : + this.#maxFilesType.grle-- + break + case '.pdf' : + this.#maxFilesType.pdf-- + break + case '.txt' : + this.#maxFilesType.txt-- + break + case '.l64' : + case '.dat' : + this.fileDetail.extraFiles.push(fileName) + this.#failFlags.might_be_crack = true + break + case '.gls' : + case '.anim' : + case '.ogg' : + break + default : + this.fileDetail.extraFiles.push(fileName) + this.#failFlags.has_extra_files = true + } + } + } + #loadZipIcon() { if ( this.#failFlags.bad_zip || this.#failFlags.no_modIcon ) { return } diff --git a/modAssist_main.js b/modAssist_main.js index 20fb8d64..450b212e 100644 --- a/modAssist_main.js +++ b/modAssist_main.js @@ -11,7 +11,7 @@ const { app, BrowserWindow, ipcMain, globalShortcut, shell, dialog, screen } = r const { autoUpdater } = require('electron-updater') -const devDebug = true +const devDebug = false if (process.platform === 'win32') { autoUpdater.checkForUpdatesAndNotify() diff --git a/package.json b/package.json index 403c58c6..8d30ea16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fsg-mod-assistant", - "version": "0.9.3", + "version": "0.9.4", "description": "FSG Farm Sim Mod Assistant", "main": "modAssist_main.js", "homepage": "https://github.com/FSGModding/FSG_Mod_Assistant#readme", diff --git a/renderer/detail.html b/renderer/detail.html index 982e7ee3..eb4ed5f0 100644 --- a/renderer/detail.html +++ b/renderer/detail.html @@ -43,7 +43,7 @@

-
+

diff --git a/test/mod-reader-test.js b/test/mod-reader-test.js index e0758dbd..876ad8e1 100644 --- a/test/mod-reader-test.js +++ b/test/mod-reader-test.js @@ -40,6 +40,7 @@ folderContents.forEach((thisFile) => { const badgeNames = Array.from(thisMod.badges.matchAll(/"mod_badge_(.+?)"/g), (m) => `${m[1]}`) console.log(` Issues: ${thisMod.issues.join(', ')}`) console.log(` Badges: ${badgeNames.join(', ')}`) + console.log(` Extra: ${thisMod.fileDetail.extraFiles.join(', ')}`) } catch (e) { console.log(` Unable to read ${thisFile} :: ${e}`) console.log(e.stack)