Skip to content

Commit

Permalink
4.3.0-beta.3
Browse files Browse the repository at this point in the history
Signed-off-by: 黑嫖233 <heipiao233@outlook.com>
  • Loading branch information
heipiao233 committed Feb 6, 2024
1 parent 0de24d6 commit df71b92
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
git push
continue-on-error: true
- name: publish
uses: JS-DevTools/npm-publish@v1
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
continue-on-error: true
2 changes: 1 addition & 1 deletion locales/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.0-beta.2
4.3.0-beta.3
4 changes: 2 additions & 2 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.3.0-beta.2",
"version": "4.3.0-beta.3",
"description": "Dolphin Minecraft Launcher Core",
"typings": "./lib/index.d.ts",
"module": "./lib/index.js",
Expand Down
7 changes: 2 additions & 5 deletions src/auth/ali_account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import got from "got";
import { checkFile } from "../utils/check_file.js";
import { download } from "../utils/downloads.js";
import { checkAndDownload, download } from "../utils/downloads.js";
import { MinecraftVersion } from "../version.js";
import { YggdrasilAccount } from "./yggdrasil/yggdrasil_account.js";
import { YggdrasilUserData } from "./yggdrasil/yggdrasil_data.js";
Expand All @@ -24,10 +24,7 @@ export class AuthlibInjectorAccount extends YggdrasilAccount<YggdrasilUserData>
const obj = await got("https://bmclapi2.bangbang93.com/mirrors/authlib-injector/artifact/latest.json").json<AuthlibInjectorArtifact>();
const sha256 = obj.checksums.sha256;
const path = `${versionDir}/authlib-injector-latest.jar`;
if (!fs.existsSync(path) || !await checkFile(path, sha256, "sha256")) {
return await download(obj.download_url, path, this.launcher);
}
return true;
return await checkAndDownload(obj.download_url, path, sha256, this.launcher, "sha256");
}

async getLaunchJVMArgs(mc: MinecraftVersion): Promise<string[]> {
Expand Down
12 changes: 11 additions & 1 deletion src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export function addExitDelete(file: string) {
});
}

export function addExitDeleteDir(dir: string) {
process.addListener("beforeExit", () => {
try {
fs.rmdirSync(dir);
} catch {

}
});
}

class LocalizedProgress implements Progress {
constructor(private dest: Progress, private t: i18next.TFunction) {

Expand Down Expand Up @@ -96,7 +106,7 @@ export class Launcher {
specialNatives: Record<string, Library>;
};
private realRootPath = "";
static readonly version = "4.3.0-beta.2";
static readonly version = "4.3.0-beta.3";
/**
* Create a new Launcher object.
* @throws {@link FormattedError}
Expand Down
4 changes: 3 additions & 1 deletion src/loaders/forgelike/forgelike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tmpdir } from "os";
import nodePath from "path";
import toml from "toml";
import { parseStringPromise } from "xml2js";
import { Launcher } from "../../launcher.js";
import { Launcher, addExitDelete, addExitDeleteDir } from "../../launcher.js";
import { ModDisplayInfo, ModInfo } from "../../mods/mod.js";
import { MCVersion } from "../../schemas.js";
import { merge } from "../../utils/MergeVersionJSONs.js";
Expand Down Expand Up @@ -61,8 +61,10 @@ export abstract class ForgeLikeLoader implements Loader<StoreData | ForgeMcmodIn
if (!await download(`${this.mavenArtifactURL}/${abn}/${version}/${abn}-${version}-installer.jar`, path, this.launcher)) {
return false;
}
addExitDelete(path);
const installer = `${tmpdir()}/${this.launcher.name}_forgelike_installer`;
await compressing.zip.uncompress(fs.createReadStream(path), installer);
addExitDeleteDir(installer);
const metadata: InstallerProfileNew | InstallerProfileOld = JSON.parse(fs.readFileSync(`${installer}/install_profile.json`).toString());

if("processors" in metadata){ // 1.13+
Expand Down
37 changes: 37 additions & 0 deletions src/utils/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ import * as streamPromises from "stream/promises";
import { FormattedError } from "../errors/FormattedError.js";
import { Launcher } from "../launcher.js";
import { transformURL } from "./TransformURL.js";
import { Pair } from "./pair.js";
import { checkFile } from "./check_file.js";
/**
* Download multi files after checking hash.
* @throws RequestError
* @param files A map from URL to path
* @param launcher Launcher
* @returns true if success
*/
export async function checkAndDownloadAll(files: Map<string, Pair<string, fs.PathLike>>, launcher: Launcher, algorithm = "sha1"): Promise<boolean> {
const promises: Promise<boolean>[] = [];
files.forEach((v, k) => {
if (v.a === "no") {
promises.push(download(k, v.b, launcher));
} else {
promises.push(checkAndDownload(k, v.b, v.a, launcher, algorithm));
}
});
return !(await Promise.all(promises)).includes(false);
}

/**
* Download multi files.
* @throws RequestError
Expand All @@ -20,7 +41,23 @@ export async function downloadAll(files: Map<string, fs.PathLike>, launcher: Lau
});
return !(await Promise.all(promises)).includes(false);
}

/**
* Download a file after checking hash.
* @throws {@link FormattedError}
* @param url - URL.
* @param filename - File name.
* @param mirror - BMCLAPI mirror.
*/
export async function checkAndDownload(url: string, filename: fs.PathLike, hash: string, launcher: Launcher, algorithm = "sha1"): Promise<boolean> {
if (!await checkFile(filename, hash, algorithm)) {
return await download(url, filename, launcher);
}
return true;
}

/**
* Download a file.
* @throws {@link FormattedError}
* @param url - URL.
* @param filename - File name.
Expand Down
28 changes: 10 additions & 18 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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";
import { ContentType, ContentVersion, Pair } from "./index.js";
import { Launcher } from "./launcher.js";
import { ModrinthContent } from "./mods/download/modrinth/ModrinthContentService.js";
import { ModManager } from "./mods/manage/ModManager.js";
import { Argument, Asset, AssetIndexInfo, AssetsIndex, Library, LibraryArtifact, MCVersion, checkRules } from "./schemas.js";
import { transformURL } from "./utils/TransformURL.js";
import { checkFile } from "./utils/check_file.js";
import { download, downloadAll } from "./utils/downloads.js";
import { checkAndDownload, checkAndDownloadAll, download, downloadAll } from "./utils/downloads.js";
import { expandInheritsFrom } from "./utils/expand_inherits_from.js";
import { expandMavenId } from "./utils/maven.js";

Expand Down Expand Up @@ -168,16 +168,13 @@ export class MinecraftVersion {
*/
async completeVersionInstall(): Promise<boolean> {
const promises = [];
if (!fs.existsSync(this.versionJarPath) ||
!await checkFile(this.versionJarPath, this.versionObject.downloads.client.sha1)) {
promises.push(download(this.versionObject.downloads.client.url, this.versionJarPath, this.launcher));
}
promises.push(checkAndDownload(this.versionObject.downloads.client.url, this.versionJarPath, this.versionObject.downloads.client.sha1, this.launcher));
promises.push(this.completeAssets(this.versionObject.assetIndex));
promises.push(this.completeLibraries(this.versionObject.libraries));
return !(await Promise.all(promises)).includes(false);
}
private async completeAssets (asset: AssetIndexInfo): Promise<boolean> {
const allDownloads: Map<string, PathLike> = new Map();
const allDownloads: Map<string, Pair<string, PathLike>> = new Map();
const indexPath = `${this.launcher.rootPath}/assets/indexes/${asset.id}.json`;
let assetJson;
if (!fs.existsSync(indexPath)) {
Expand All @@ -191,12 +188,9 @@ export class MinecraftVersion {
const assetobj: AssetsIndex = JSON.parse(assetJson);
for (const assid in assetobj.objects) {
const assitem: Asset = assetobj.objects[assid];
if (!fs.existsSync(`${assetsObjects}/${assitem.hash.slice(0, 2)}/${assitem.hash}`) ||
!await checkFile(`${assetsObjects}/${assitem.hash.slice(0, 2)}/${assitem.hash}`, assitem.hash)) {
allDownloads.set(`https://resources.download.minecraft.net/${assitem.hash.slice(0, 2)}/${assitem.hash}`, `${assetsObjects}/${assitem.hash.slice(0, 2)}/${assitem.hash}`);
}
allDownloads.set(`https://resources.download.minecraft.net/${assitem.hash.slice(0, 2)}/${assitem.hash}`, new Pair(assitem.hash, `${assetsObjects}/${assitem.hash.slice(0, 2)}/${assitem.hash}`));
}
return await downloadAll(allDownloads, this.launcher);
return await checkAndDownloadAll(allDownloads, this.launcher);
}

/**
Expand All @@ -206,7 +200,7 @@ export class MinecraftVersion {
* @internal
*/
async completeLibraries (liblist: Library[]): Promise<boolean> {
const allDownloads: Map<string, PathLike> = new Map();
const allDownloads: Map<string, Pair<string, PathLike>> = new Map();
const used = liblist.filter((i) => {
return i.rules === undefined || checkRules(i.rules);
});
Expand All @@ -216,7 +210,7 @@ export class MinecraftVersion {
let url: string;
if (!("url" in i)) url = "https://libraries.minecraft.net/";
else url = i.url;
allDownloads.set(`${url}${filePath}`, `${this.launcher.rootPath}/libraries/${filePath}`);
allDownloads.set(`${url}${filePath}`, new Pair("no", `${this.launcher.rootPath}/libraries/${filePath}`));
} else {
const artifacts: LibraryArtifact[]=[];
if ("artifact" in i.downloads) {
Expand All @@ -226,13 +220,11 @@ export class MinecraftVersion {
artifacts.push(i.downloads.classifiers[i.natives[this.launcher.natives].replaceAll("${arch}", os.arch().includes("64")?"64":"32")]);
}
for (const artifact of artifacts) {
if(!(fs.existsSync(`${this.launcher.rootPath}/libraries/${artifact.path}`) && await checkFile(`${this.launcher.rootPath}/libraries/${artifact.path}`, artifact.sha1))){
allDownloads.set(artifact.url, `${this.launcher.rootPath}/libraries/${artifact.path}`);
}
allDownloads.set(artifact.url, new Pair(artifact.sha1, `${this.launcher.rootPath}/libraries/${artifact.path}`));
}
}
}
return await downloadAll(allDownloads, this.launcher);
return await checkAndDownloadAll(allDownloads, this.launcher);
}

private getClassPath (versionObject: MCVersion): string[] {
Expand Down

0 comments on commit df71b92

Please sign in to comment.