feat: only download java if not present
This commit is contained in:
parent
d46340c633
commit
76f3d7b588
1 changed files with 37 additions and 20 deletions
|
|
@ -14,6 +14,7 @@ import { installForge } from "../core/modloaders";
|
|||
import { getJavaExecutable } from "../core/java";
|
||||
import { readJson } from "../utils/fs";
|
||||
import { mergeManifests } from "../core/mergeManifests";
|
||||
import { exec } from "node:child_process";
|
||||
|
||||
function getJavaOs() {
|
||||
switch (os()) {
|
||||
|
|
@ -58,6 +59,20 @@ interface InstanceEvents {
|
|||
];
|
||||
}
|
||||
|
||||
function checkJava(javaLocation: string) {
|
||||
const javaExe = getJavaExecutable(javaLocation);
|
||||
|
||||
return new Promise<boolean>((res) => {
|
||||
exec(`${javaExe} -version`, (err) => {
|
||||
if (err) {
|
||||
res(false);
|
||||
} else {
|
||||
res(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export class Instance extends EventEmitter<InstanceEvents> {
|
||||
version: string;
|
||||
modloader?: Modloader;
|
||||
|
|
@ -117,7 +132,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
this.args.game = game || "";
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
private async initialize() {
|
||||
this.versionLocation = path.join(this.paths.versions, this.version);
|
||||
this.instanceLocation = path.join(this.paths.instances, this.version);
|
||||
|
||||
|
|
@ -209,6 +224,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
error.throw();
|
||||
}
|
||||
|
||||
if (!await checkJava(this.javaLocation)) {
|
||||
try {
|
||||
const javaDownloader = await core.java.JavaDownloader(
|
||||
getJavaOs(),
|
||||
|
|
@ -230,6 +246,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
const error = new InstallError("java", original);
|
||||
error.throw();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.modloader) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue