Skip to content

Commit

Permalink
Fail with a more useful error message if the forge installer was not …
Browse files Browse the repository at this point in the history
…run correctly.
  • Loading branch information
dscalzi committed Jan 17, 2023
1 parent 4aeb570 commit 530d475
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/resolver/forge/adapter/ForgeGradle3.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LoggerUtil } from '../../../util/LoggerUtil'
import { VersionUtil } from '../../../util/versionutil'
import { Module, Type } from 'helios-distribution-types'
import { LibRepoStructure } from '../../../structure/repo/LibRepo.struct'
import { pathExists, remove, mkdirs, copy, writeFile, readFile, lstat, writeJson } from 'fs-extra'
import { pathExists, remove, mkdirs, copy, writeFile, readFile, lstat, writeJson, exists } from 'fs-extra'
import { join, basename, dirname } from 'path'
import { spawn } from 'child_process'
import { JavaUtil } from '../../../util/java/javautil'
Expand Down Expand Up @@ -303,6 +303,8 @@ export class ForgeGradle3Adapter extends ForgeResolver {
ForgeGradle3Adapter.logger.debug('Installer finished, beginning processing..')
}

await this.verifyInstallerRan(installerOutputDir)

ForgeGradle3Adapter.logger.debug('Processing Version Manifest')
const versionManifestTuple = await this.processVersionManifest(installerOutputDir)
const versionManifest = versionManifestTuple[0] as VersionManifestFG3
Expand All @@ -328,10 +330,24 @@ export class ForgeGradle3Adapter extends ForgeResolver {

}

private async processVersionManifest(installerOutputDir: string): Promise<[VersionManifestFG3, Module]> {
private getVersionManifestPath(installerOutputDir: string): string {
const versionRepo = this.repoStructure.getVersionRepoStruct()
const versionName = versionRepo.getFileName(this.minecraftVersion, this.forgeVersion)
const versionManifestPath = join(installerOutputDir, 'versions', versionName, `${versionName}.json`)
return join(installerOutputDir, 'versions', versionName, `${versionName}.json`)
}

private async verifyInstallerRan(installerOutputDir: string): Promise<void> {
const versionManifestPath = this.getVersionManifestPath(installerOutputDir)

if(!await exists(versionManifestPath)) {
await remove(installerOutputDir)
throw new Error(`Forge was either not installed or installed to the wrong location. When the forge installer opens, you MUST set the installation directory to ${installerOutputDir}`)
}
}

private async processVersionManifest(installerOutputDir: string): Promise<[VersionManifestFG3, Module]> {
const versionRepo = this.repoStructure.getVersionRepoStruct()
const versionManifestPath = this.getVersionManifestPath(installerOutputDir)

const versionManifestBuf = await readFile(versionManifestPath)
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifestFG3
Expand Down

0 comments on commit 530d475

Please sign in to comment.