Skip to content

Commit

Permalink
Bump to 0.9.4 - re-work internal file counter / tester to be a bit ea…
Browse files Browse the repository at this point in the history
…sier to augment.
  • Loading branch information
jtsage committed Oct 13, 2022
1 parent 75eb2ba commit 5036e8d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 104 deletions.
204 changes: 103 additions & 101 deletions lib/single-mod-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion renderer/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h6 class="text-center mt-1 mb-1 w-75 mx-auto" id="badges"></h6>
</div>
<div class="px-3 mt-4 mb-2" id="problem_div">
<h4><l10n name="detail_problems"></l10n></h4>
<div id="problems" class="w-100 mx-auto"></div>
<div id="problems" class="w-100 mx-auto px-5"></div>
</div>
<div class="px-3 mt-4 mb-2" id="problem_div">
<h4><l10n name="detail_description"></l10n></h4>
Expand Down
1 change: 1 addition & 0 deletions test/mod-reader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5036e8d

Please sign in to comment.