Replace AdmZip with node-stream-zip.

This commit is contained in:
Daniel Scalzi
2020-06-02 23:07:59 -04:00
parent 0b063e4bfc
commit d627ce72a3
12 changed files with 283 additions and 215 deletions

View File

@@ -1,4 +1,3 @@
import AdmZip from 'adm-zip'
import { createHash } from 'crypto'
import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra'
import { Module, Type } from 'helios-distribution-types'
@@ -59,24 +58,14 @@ export class ForgeGradle2Adapter extends ForgeResolver {
}
ForgeGradle2Adapter.logger.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
const forgeUniversalBuffer = await readFile(targetLocalPath)
const zip = new AdmZip(forgeUniversalBuffer)
const zipEntries = zip.getEntries()
let versionManifest
for (const entry of zipEntries) {
if (entry.entryName === 'version.json') {
versionManifest = zip.readAsText(entry)
break
}
}
if (!versionManifest) {
let versionManifestBuf: Buffer
try {
versionManifestBuf = await this.getVersionManifestFromJar(targetLocalPath)
} catch(err) {
throw new Error('Failed to find version.json in forge universal jar.')
}
versionManifest = JSON.parse(versionManifest) as VersionManifestFG2
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifestFG2
const forgeModule: Module = {
id: MavenUtil.mavenComponentsToIdentifier(
@@ -87,7 +76,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
name: 'Minecraft Forge',
type: Type.ForgeHosted,
artifact: this.generateArtifact(
forgeUniversalBuffer,
await readFile(targetLocalPath),
await lstat(targetLocalPath),
libRepo.getArtifactUrlByComponents(
this.baseUrl,

View File

@@ -1,4 +1,3 @@
import AdmZip from 'adm-zip'
import { ForgeResolver } from '../forge.resolver'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
@@ -420,29 +419,19 @@ export class ForgeGradle3Adapter extends ForgeResolver {
}
return null
}
private async processWithoutInstaller(installerPath: string): Promise<Module> {
// Extract version.json from installer.
const forgeInstallerBuffer = await readFile(installerPath)
const zip = new AdmZip(forgeInstallerBuffer)
const zipEntries = zip.getEntries()
let versionManifest
for (const entry of zipEntries) {
if (entry.entryName === 'version.json') {
versionManifest = zip.readAsText(entry)
break
}
}
if (!versionManifest) {
let versionManifestBuf: Buffer
try {
versionManifestBuf = await this.getVersionManifestFromJar(installerPath)
} catch(err) {
throw new Error('Failed to find version.json in forge installer jar.')
}
versionManifest = JSON.parse(versionManifest) as VersionManifestFG3
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifestFG3
// Save Version Manifest
const versionManifestDest = this.repoStructure.getVersionRepoStruct().getVersionManifest(

View File

@@ -1,3 +1,4 @@
import StreamZip from 'node-stream-zip'
import { createHash } from 'crypto'
import { Stats } from 'fs-extra'
import { Artifact } from 'helios-distribution-types'
@@ -81,4 +82,24 @@ export abstract class ForgeResolver extends BaseResolver {
}
}
protected async getVersionManifestFromJar(jarPath: string): Promise<Buffer>{
return new Promise((resolve, reject) => {
const zip = new StreamZip({
file: jarPath,
storeEntries: true
})
zip.on('ready', () => {
try {
const data = zip.entryDataSync('version.json')
zip.close()
resolve(data)
} catch(err) {
reject(err)
}
})
zip.on('error', err => reject(err))
})
}
}