Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
heipiao233 committed Aug 8, 2023
1 parent 4c4b03d commit b6d9ba1
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion locales/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
4.1.1
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dmclc",
"version": "4.1.0",
"version": "4.1.1",
"description": "Dolphin Minecraft Launcher Core",
"typings": "./lib/index.d.ts",
"module": "./lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Launcher {
specialNatives: Record<string, Library>;
};
private realRootPath = "";
static readonly version = "4.1.0";
static readonly version = "4.1.1";
/**
* Create a new Launcher object.
* @throws {@link FormattedError}
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/fabriclike/fabriclike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Launcher } from "../../launcher.js";
import { ModDisplayInfo, ModInfo } from "../../mods/mod.js";
import { MCVersion } from "../../schemas.js";
import { merge } from "../../utils/MergeVersionJSONs.js";
import { transformJSON } from "../../utils/transformJSON.js";
import { MinecraftVersion } from "../../version.js";
import { FabricModJson } from "../fabric_schemas.js";
import { Loader, ModLoadingIssue } from "../loader.js";
Expand Down Expand Up @@ -33,7 +34,7 @@ export abstract class FabricLikeLoader<T extends FabricLikeVersionInfo, M> imple
const entry = await zip.entry("fabric.mod.json");
if(entry === undefined)return [];
const result: ModInfo<FabricModJson | M>[] = [];
const json: FabricModJson = JSON.parse((await zip.entryData(entry)).toString());
const json: FabricModJson = JSON.parse(transformJSON((await zip.entryData(entry)).toString()));
if(json.jars !== undefined){
for (const jar of json.jars) {
const paths = jar.file.split("/");
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/forge/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { merge } from "../../utils/MergeVersionJSONs.js";
import { checkFile } from "../../utils/check_file.js";
import { download } from "../../utils/downloads.js";
import { expandMavenId } from "../../utils/maven.js";
import { transformJSON } from "../../utils/transformJSON.js";
import { MinecraftVersion } from "../../version.js";
import { Loader, ModLoadingIssue } from "../loader.js";
import { ForgeJarJarJson, ForgeMcmodInfo, ForgeMcmodInfoOne, ForgeModsToml, StoreData } from "./forge_schemas.js";
Expand Down Expand Up @@ -144,7 +145,7 @@ export class ForgeLoader implements Loader<StoreData | ForgeMcmodInfoOne> {
const ret: ModInfo<StoreData | ForgeMcmodInfoOne>[] = [];
const jarJarEntry = await zip.entry("META-INF/jarjar/metadata.json");
if(jarJarEntry) {
const data: ForgeJarJarJson = JSON.parse((await zip.entryData(jarJarEntry)).toString());
const data: ForgeJarJarJson = JSON.parse(transformJSON((await zip.entryData(jarJarEntry)).toString()));
for (const jarObj of data.jars) {
const jar = jarObj.path;
const paths = jar.split("/");
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/quilt/quilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import StreamZip from "node-stream-zip";
import { tmpdir } from "os";
import { ModDisplayInfo, ModInfo } from "../../mods/mod.js";
import { MCVersion } from "../../schemas.js";
import { transformJSON } from "../../utils/transformJSON.js";
import { checkFabricDeps } from "../fabric.js";
import { FabricModJson } from "../fabric_schemas.js";
import { FabricLikeLoader, checkMatch, formatDepVersion, normalizeVersion } from "../fabriclike/fabriclike.js";
Expand All @@ -27,7 +28,7 @@ export class QuiltLoader extends FabricLikeLoader<QuiltVersionInfo, QuiltModJson
const entry = await zip.entry("quilt.mod.json");
if(entry === undefined)return super.findModInfos(path);
const result: ModInfo<QuiltModJson | FabricModJson>[] = await super.findModInfos(path);
const json: QuiltModJson = JSON.parse((await zip.entryData(entry)).toString());
const json: QuiltModJson = JSON.parse(transformJSON((await zip.entryData(entry)).toString()));
if(json.quilt_loader.jars !== undefined){
for (const jar of json.quilt_loader.jars) {
const paths = jar.split("/");
Expand Down
24 changes: 24 additions & 0 deletions src/utils/transformJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export function transformJSON(source: string): string {
const result = [];
let isStr = false;
for(const i of source) {
switch (i) {
case '"':
case "'":
isStr = !isStr;
result.push(i);
break;

case '\n':
if (isStr) {
result.push("\\n");
break;
}

default:
result.push(i);
break;
}
}
return result.join("");
}
8 changes: 5 additions & 3 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cp, { ChildProcess } from "child_process";
import cp, { ChildProcess, exec } from "child_process";
import compressing from "compressing";
import fs, { PathLike } from "fs";
import { ensureDir, mkdirs } from "fs-extra";
Expand All @@ -7,6 +7,7 @@ import got from "got";
import StreamZip from "node-stream-zip";
import os from "os";
import path from "path";
import { promisify } from "util";
import { Account } from "./auth/account.js";
import { FormattedError } from "./errors/FormattedError.js";
import { ContentType, ContentVersion } from "./index.js";
Expand Down Expand Up @@ -136,8 +137,8 @@ export class MinecraftVersion {
async run(account: Account<never>): Promise<ChildProcess> {
const progress = this.launcher.createProgress(5, "version.progress.run", "version.progress.account_login");
try {
if (!account.check()) {
account.login();
if (!await account.check()) {
await account.login();
}
progress.update("version.progress.account_prepare");
await account.prepareLaunch(this.versionLaunchWorkDir);
Expand All @@ -153,6 +154,7 @@ export class MinecraftVersion {
.concat(args)
.concat(this.extras.moreGameArguments ?? []);
progress.update("version.progress.done");
if (this.extras.beforeCommand) await promisify(exec)(this.extras.beforeCommand);
return cp.execFile(this.extras.usingJava ?? this.launcher.usingJava, allArguments, {
cwd: this.versionLaunchWorkDir
});
Expand Down

0 comments on commit b6d9ba1

Please sign in to comment.