Skip to content

Commit

Permalink
4.4.0-beta.1: Fix downlad behaviors.
Browse files Browse the repository at this point in the history
Signed-off-by: 黑嫖233 <[email protected]>
  • Loading branch information
heipiao233 committed Feb 14, 2024
1 parent fd84358 commit 4d733fe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion locales/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.4.0-alpha.3
4.4.0-beta.1
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.4.0-alpha.3",
"version": "4.4.0-beta.1",
"description": "Dolphin Minecraft Launcher Core",
"typings": "./lib/index.d.ts",
"module": "./lib/index.js",
Expand Down
4 changes: 3 additions & 1 deletion src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Launcher {
};
envPaths = envPaths("DMCLC");
private realRootPath = "";
static readonly version = "4.4.0-alpha.3";
static readonly version = "4.4.0-beta.1";
/**
* Create a new Launcher object.
* @throws {@link FormattedError}
Expand Down Expand Up @@ -277,6 +277,7 @@ export class Launcher {
url = token.href;
let file = temp.createWriteStream();
await downloadIntoStream(url, file, self);
file.close();
token.href = pathToFileURL(file.path as string).toString();
} else if (token.type == "html") {
if (!token.raw.includes("<img"))
Expand All @@ -286,6 +287,7 @@ export class Launcher {
url = m[1];
let file = temp.createWriteStream();
await downloadIntoStream(url, file, self);
file.close();
token.raw = token.raw.replaceAll(url, pathToFileURL(file.path as string).toString());
token.text = token.text.replaceAll(url, pathToFileURL(file.path as string).toString());
}
Expand Down
3 changes: 0 additions & 3 deletions src/utils/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export async function download(url: string, filename: fs.PathLike, launcher: Lau
const dir = path.dirname(filename.toString());
await ensureDir(dir);
let realURL = transformURL(url, launcher.mirror);
realURL = realURL.replaceAll("http://", "https://");
if (launcher.downloader) await launcher.downloader(realURL, filename, url);
else await downloader(realURL, filename, url);
return true;
Expand All @@ -77,7 +76,6 @@ export async function download(url: string, filename: fs.PathLike, launcher: Lau
export async function downloadIntoStream(url: string, out: NodeJS.WritableStream, launcher: Launcher): Promise<boolean> {
if(url.length===0)return true;
let realURL = transformURL(url, launcher.mirror);
realURL = realURL.replaceAll("http://", "https://");
let failed = true;
for (let i=0;i<10;i++) {
try {
Expand All @@ -87,7 +85,6 @@ export async function downloadIntoStream(url: string, out: NodeJS.WritableStream
} catch (e) {
if(e instanceof HTTPError) {
if(e.response.statusCode === 404) {
realURL = url.replaceAll("http://", "https://");
i--;
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class MinecraftVersion {
progress.update("version.progress.account_prepare");
await account.prepareLaunch(this.versionLaunchWorkDir);
progress.update("version.progress.complete");
await this.completeVersionInstall();
await this.completeVersionInstall(false);
progress.update("version.progress.extract_native");
await this.extractNative(this.versionObject, this.name);
progress.update("version.progress.argument");
Expand All @@ -166,7 +166,7 @@ export class MinecraftVersion {
/**
* Complete this version installation. Fix wrong libraries, asset files and version.jar. Won't fix version.json.
*/
async completeVersionInstall(): Promise<boolean> {
async completeVersionInstall(alwaysDownloadNoDownloadsItems: boolean = true): Promise<boolean> {
const promises = [];
promises.push(checkAndDownload(this.versionObject.downloads.client.url, this.versionJarPath, this.versionObject.downloads.client.sha1, this.launcher));
promises.push(this.completeAssets(this.versionObject.assetIndex));
Expand Down Expand Up @@ -199,18 +199,20 @@ export class MinecraftVersion {
* @param liblist - All the libraries.
* @internal
*/
async completeLibraries (liblist: Library[]): Promise<boolean> {
async completeLibraries (liblist: Library[], alwaysDownloadNoDownloadsItems: boolean = true): Promise<boolean> {
const allDownloads: Map<string, Pair<string, PathLike>> = new Map();
const used = liblist.filter((i) => {
return i.rules === undefined || checkRules(i.rules);
});
for (const i of used) {
if (!("downloads" in i)) {
const filePath = expandMavenId(i.name);
let url: string;
if (!("url" in i)) url = "https://libraries.minecraft.net/";
else url = i.url;
allDownloads.set(`${url}${filePath}`, new Pair("no", `${this.launcher.rootPath}/libraries/${filePath}`));
if (alwaysDownloadNoDownloadsItems) {
const filePath = expandMavenId(i.name);
let url: string;
if (!("url" in i)) url = "https://libraries.minecraft.net/";
else url = i.url;
allDownloads.set(`${url}${filePath}`, new Pair("no", `${this.launcher.rootPath}/libraries/${filePath}`));
}
} else {
const artifacts: LibraryArtifact[]=[];
if ("artifact" in i.downloads) {
Expand Down

0 comments on commit 4d733fe

Please sign in to comment.