Fix download of forge libraries for older versions.
Added function to determine extension type by checking the forge server.
This commit is contained in:
@@ -70,4 +70,28 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
|
||||
})
|
||||
}
|
||||
|
||||
public async headArtifactById(url: string, mavenIdentifier: string, extension?: string): Promise<boolean> {
|
||||
return this.headArtifactBase(url, MavenUtil.mavenIdentifierToString(mavenIdentifier, extension) as string)
|
||||
}
|
||||
|
||||
public async headArtifactByComponents(
|
||||
url: string, group: string, artifact: string, version: string, classifier?: string, extension?: string
|
||||
): Promise<boolean> {
|
||||
return this.headArtifactBase(url,
|
||||
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
|
||||
}
|
||||
|
||||
private async headArtifactBase(url: string, relative: string): Promise<boolean> {
|
||||
const resolvedURL = resolveURL(url, relative).toString()
|
||||
try {
|
||||
const response = await axios({
|
||||
method: 'head',
|
||||
url: resolvedURL
|
||||
})
|
||||
return response.status === 200
|
||||
} catch (ignored) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,12 +11,16 @@ import { VersionUtil } from '../../../util/versionutil'
|
||||
import { ForgeResolver } from '../forge.resolver'
|
||||
import { MinecraftVersion } from '../../../util/MinecraftVersion'
|
||||
|
||||
type ArrayElement<A> = A extends readonly (infer T)[] ? T : never
|
||||
|
||||
export class ForgeGradle2Adapter extends ForgeResolver {
|
||||
|
||||
public static isForVersion(version: MinecraftVersion): boolean {
|
||||
return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
|
||||
}
|
||||
|
||||
protected readonly MOJANG_REMOTE_REPOSITORY = 'https://libraries.minecraft.net/'
|
||||
|
||||
constructor(
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
@@ -100,8 +104,8 @@ export class ForgeGradle2Adapter extends ForgeResolver {
|
||||
}
|
||||
console.debug(`Processing ${lib.name}..`)
|
||||
|
||||
const extension = this.determineExtension(lib.checksums)
|
||||
const localPath = libRepo.getArtifactById(lib.name, extension) as string
|
||||
const extension = await this.determineExtension(lib, libRepo)
|
||||
const localPath = libRepo.getArtifactById(lib.name, extension)
|
||||
|
||||
const postProcess = extension === 'jar.pack.xz'
|
||||
|
||||
@@ -126,7 +130,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
|
||||
}
|
||||
|
||||
if (queueDownload) {
|
||||
await libRepo.downloadArtifactById(lib.url || 'https://libraries.minecraft.net/', lib.name, extension)
|
||||
await libRepo.downloadArtifactById(lib.url || this.MOJANG_REMOTE_REPOSITORY, lib.name, extension)
|
||||
libBuf = await readFile(localPath)
|
||||
} else {
|
||||
console.debug('Using local copy.')
|
||||
@@ -176,14 +180,42 @@ export class ForgeGradle2Adapter extends ForgeResolver {
|
||||
return forgeModule
|
||||
}
|
||||
|
||||
private determineExtension(checksums: string[] | undefined): string {
|
||||
return checksums != null && checksums.length > 1 ? 'jar.pack.xz' : 'jar'
|
||||
private async determineExtension(lib: ArrayElement<VersionManifestFG2['libraries']>, libRepo: LibRepoStructure): Promise<string> {
|
||||
if(lib.url == null) {
|
||||
return 'jar'
|
||||
}
|
||||
console.log('Determing extension..')
|
||||
const possibleExt = [
|
||||
'jar.pack.xz',
|
||||
'jar'
|
||||
]
|
||||
// Check locally.
|
||||
for(const ext of possibleExt) {
|
||||
const localPath = libRepo.getArtifactById(lib.name, ext)
|
||||
const exists = await libRepo.artifactExists(localPath)
|
||||
if(exists) {
|
||||
return ext
|
||||
}
|
||||
}
|
||||
// Check remote.
|
||||
for(const ext of possibleExt) {
|
||||
const exists = await libRepo.headArtifactById(this.REMOTE_REPOSITORY, lib.name, ext)
|
||||
if(exists) {
|
||||
return ext
|
||||
}
|
||||
}
|
||||
// Default to jar.
|
||||
return 'jar'
|
||||
}
|
||||
|
||||
private async processPackXZFiles(
|
||||
processingQueue: Array<{id: string, localPath: string}>
|
||||
): Promise<Array<{id: string, MD5: string}>> {
|
||||
|
||||
if(processingQueue.length == 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const accumulator = []
|
||||
|
||||
const tempDir = this.repoStructure.getTempDirectory()
|
||||
|
||||
Reference in New Issue
Block a user