feat: separate instance data from shared folders
This commit is contained in:
parent
22d68bd378
commit
f958f3598a
3 changed files with 54 additions and 42 deletions
|
|
@ -9,20 +9,21 @@ import { getArgument } from "./log4j";
|
|||
function fillArguments(
|
||||
arg: string,
|
||||
versionManifest: Version,
|
||||
gameRoot: string,
|
||||
assetsPath: string,
|
||||
instancePath: string,
|
||||
classPaths: PoolFile[],
|
||||
auth: Auth,
|
||||
) {
|
||||
const argumentsToFill = {
|
||||
"${natives_directory}": path.join(gameRoot, "natives"),
|
||||
"${natives_directory}": path.join(instancePath, "natives"),
|
||||
"${launcher_name}": "nlk",
|
||||
"${launcher_version}": packageVersion,
|
||||
"${classpath}": classPaths,
|
||||
"${game_directory}": gameRoot,
|
||||
"${game_directory}": instancePath,
|
||||
"${version_name}": versionManifest.id,
|
||||
"${version_type}": versionManifest.type,
|
||||
"${assets_index_name}": versionManifest.assets,
|
||||
"${assets_root}": path.join(gameRoot, "assets"),
|
||||
"${assets_root}": assetsPath,
|
||||
"${auth_access_token}": auth.access_token,
|
||||
"${auth_session}": auth.access_token,
|
||||
"${auth_player_name}": auth.name,
|
||||
|
|
@ -48,23 +49,24 @@ function parseArg(
|
|||
this: string[],
|
||||
arg: Argument,
|
||||
versionManifest: Version,
|
||||
gameRoot: string,
|
||||
assetsPath: string,
|
||||
instancePath: string,
|
||||
classPaths: PoolFile[],
|
||||
auth: Auth,
|
||||
) {
|
||||
if (isNeeded(arg)) {
|
||||
if (typeof arg === "string") {
|
||||
this.push(
|
||||
fillArguments(arg, versionManifest, gameRoot, classPaths, auth),
|
||||
fillArguments(arg, versionManifest, assetsPath, instancePath, classPaths, auth),
|
||||
);
|
||||
} else if (typeof arg.value === "string") {
|
||||
this.push(
|
||||
fillArguments(arg.value, versionManifest, gameRoot, classPaths, auth),
|
||||
fillArguments(arg.value, versionManifest, assetsPath, instancePath, classPaths, auth),
|
||||
);
|
||||
} else if (arg.value.length > 1) {
|
||||
for (const e of arg.value) {
|
||||
this.push(
|
||||
fillArguments(e, versionManifest, gameRoot, classPaths, auth),
|
||||
fillArguments(e, versionManifest, assetsPath, instancePath, classPaths, auth),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +92,9 @@ function generateClassPaths(
|
|||
export async function generateLaunchArguments(
|
||||
versionManifest: Version,
|
||||
javaRoot: string,
|
||||
gameRoot: string,
|
||||
instancePath: string,
|
||||
librariesPath: string,
|
||||
assetsPath: string,
|
||||
versionRoot: string,
|
||||
auth: Auth,
|
||||
options: {
|
||||
|
|
@ -108,12 +112,12 @@ export async function generateLaunchArguments(
|
|||
|
||||
const classPaths = generateClassPaths(
|
||||
versionManifest,
|
||||
path.join(gameRoot, "libraries"),
|
||||
librariesPath,
|
||||
path.join(versionRoot, `${versionManifest.id}.jar`),
|
||||
);
|
||||
|
||||
function p(args: string[], arg: Argument) {
|
||||
parseArg.apply(args, [arg, versionManifest, gameRoot, classPaths, auth]);
|
||||
parseArg.apply(args, [arg, versionManifest, assetsPath, instancePath, classPaths, auth]);
|
||||
}
|
||||
|
||||
for (const arg of versionManifest.arguments.jvm) {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
paths: Paths;
|
||||
args: { java: string; game: string };
|
||||
versionManifest: Version;
|
||||
javaLocation?: string;
|
||||
javaLocation: string;
|
||||
versionLocation: string;
|
||||
instanceLocation: string;
|
||||
ready: boolean;
|
||||
|
||||
constructor() {
|
||||
|
|
@ -78,21 +80,20 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
if (typeof paths === "string") {
|
||||
this.paths = {
|
||||
root: paths,
|
||||
version: path.join(paths, "version", this.version),
|
||||
versions: path.join(paths, "versions"),
|
||||
assets: path.join(paths, "assets"),
|
||||
javaRoot: path.join(paths, "java"),
|
||||
libraries: path.join(paths, "libraries"),
|
||||
natives: path.join(paths, "natives"),
|
||||
instances: path.join(paths, "instances"),
|
||||
};
|
||||
} else {
|
||||
this.paths = {
|
||||
root: paths.root,
|
||||
version:
|
||||
paths.version || path.join(paths.root, "version", this.version),
|
||||
versions: paths.versions || path.join(paths.root, "versions"),
|
||||
assets: paths.assets || path.join(paths.root, "assets"),
|
||||
javaRoot: paths.javaRoot || path.join(paths.root, "java"),
|
||||
libraries: paths.libraries || path.join(paths.root, "libraries"),
|
||||
natives: paths.natives || path.join(paths.root, "natives"),
|
||||
instances: paths.instances || path.join(paths.root, "instances"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -107,9 +108,12 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
}
|
||||
|
||||
async initialize() {
|
||||
this.versionLocation = path.join(this.paths.versions, this.version);
|
||||
this.instanceLocation = path.join(this.paths.instances, this.version);
|
||||
|
||||
this.versionManifest = await core.version.getVersionManifest(
|
||||
this.version,
|
||||
this.paths.version,
|
||||
this.versionLocation,
|
||||
);
|
||||
|
||||
this.javaLocation = path.join(
|
||||
|
|
@ -122,7 +126,10 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
try {
|
||||
await this.initialize();
|
||||
this.ready = true;
|
||||
await core.version.downloadJar(this.versionManifest, this.paths.version);
|
||||
await core.version.downloadJar(
|
||||
this.versionManifest,
|
||||
this.versionLocation,
|
||||
);
|
||||
} catch (original) {
|
||||
const error = new InstallError("version", original);
|
||||
error.throw();
|
||||
|
|
@ -173,7 +180,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
|
||||
try {
|
||||
const nativesDownloader = await core.NativesDownloader(
|
||||
this.paths.natives,
|
||||
this.instanceLocation,
|
||||
this.versionManifest,
|
||||
);
|
||||
nativesDownloader.on("completed", () => {
|
||||
|
|
@ -227,25 +234,28 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
}
|
||||
|
||||
const args = await core.arguments.generateLaunchArguments(
|
||||
await core.version.getVersionManifest(this.version, this.paths.version),
|
||||
await core.version.getVersionManifest(
|
||||
this.version,
|
||||
this.versionLocation,
|
||||
),
|
||||
this.javaLocation,
|
||||
this.paths.root,
|
||||
this.paths.version,
|
||||
this.instanceLocation,
|
||||
this.paths.libraries,
|
||||
this.paths.assets,
|
||||
this.versionLocation,
|
||||
this.auth,
|
||||
{ customGameArgs: this.args.game, customJvmArgs: this.args.java },
|
||||
);
|
||||
|
||||
const process = core.launch(args, this.paths.root);
|
||||
const process = core.launch(args, this.instanceLocation);
|
||||
|
||||
return process;
|
||||
} catch (original) {
|
||||
const error = new LaunchError(
|
||||
{
|
||||
version: this.version,
|
||||
versionPath: this.paths.version,
|
||||
javaLocation: this.javaLocation,
|
||||
rootPath: this.paths.root,
|
||||
auth: this.auth,
|
||||
paths: this.paths,
|
||||
customGameArgs: this.args.game,
|
||||
customJvmArgs: this.args.java,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -179,20 +179,18 @@ export type Auth = {
|
|||
export type LaunchArguments = { command: string; args: string[] };
|
||||
|
||||
export type Paths = {
|
||||
root: string
|
||||
version?: string
|
||||
assets?: string
|
||||
libraries?: string
|
||||
natives?: string
|
||||
javaRoot?: string
|
||||
}
|
||||
root: string;
|
||||
versions?: string;
|
||||
assets?: string;
|
||||
libraries?: string;
|
||||
instances?: string;
|
||||
javaRoot?: string;
|
||||
};
|
||||
|
||||
export type LaunchErrorInfos = {
|
||||
version: string;
|
||||
versionPath: string;
|
||||
javaLocation: string;
|
||||
rootPath: string;
|
||||
auth: Auth;
|
||||
customGameArgs: string;
|
||||
customJvmArgs: string;
|
||||
}
|
||||
version: string;
|
||||
paths: Paths;
|
||||
auth: Auth;
|
||||
customGameArgs: string;
|
||||
customJvmArgs: string;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue