Skip to content

Commit

Permalink
fix: Cannot identify zip with ext other than .zip
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 17, 2022
1 parent 77c0633 commit 6d356c8
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions xmcl-runtime/lib/entities/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,25 @@ export async function parseResource(path: string, context: ParseResourceContext,
const hint = typeHint || ''
const sha1 = context.sha1 ?? await checksum(path, 'sha1')
const fstat = context.stat ?? await stat(path)
let ext = extname(path)
if (ext !== '.jar' && ext !== '.zip' && fileType === 'zip') {
ext = '.zip'
}

const filterFunc: (r: ResourceParser<any>) => boolean = (hint === '*' || hint === '')
? (ext ? r => r.ext === ext : () => true)
: r => r.domain === hint || r.type === hint

const parsers: ResourceParser<any>[] = resourceParsers.filter(filterFunc)
if (ext === '.zip') {
parsers.push(forgeModParser)
const ext = extname(path)
const inspectExt = fileType === 'zip' ? '.zip' : undefined

let parsers: ResourceParser<any>[]
if (hint === '*' || hint === '') {
if (ext) {
parsers = resourceParsers.filter(r => r.ext === ext)
if (parsers.length === 0 && inspectExt) {
parsers.push(...resourceParsers.filter(r => r.ext === inspectExt), forgeModParser)
}
} else {
if (inspectExt) {
parsers = resourceParsers.filter(r => r.ext === inspectExt).concat(forgeModParser)
} else {
parsers = [...resourceParsers]
}
}
} else {
parsers = resourceParsers.filter(r => r.domain === hint || r.type === hint)
}
parsers.push(UNKNOWN_ENTRY)

Expand Down

0 comments on commit 6d356c8

Please sign in to comment.