Skip to content

Commit

Permalink
Фикс скачивания нативок с указанием битности системы
Browse files Browse the repository at this point in the history
  • Loading branch information
JoCat committed Sep 12, 2023
1 parent 6cca69a commit 3b2b3e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/server/src/components/download/DownloadManagers/Mojang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { injectable } from "tsyringe";

import {
Action,
Artifact,
AssetIndex,
Assets,
Classifiers,
Expand Down Expand Up @@ -208,24 +209,40 @@ export class MojangManager extends AbstractDownloadManager {
#resolveOldNative(library: Library): ProfileLibrary[] {
const downloads = this.#resolveRulesForNatives(library);

return downloads.map(([os, nativeIndex]) => {
const artifact = library.downloads.classifiers[nativeIndex];

const { path, sha1 } = artifact;
let arch; // TODO resolveRulesForNatives "x-${arch}"

const resolveNative = (
{ path, sha1 }: Artifact,
os: Name,
arch?: string,
): ProfileLibrary => {
return {
path,
sha1,
type: "native",
rules: [
{
action: Action.Allow,
os: { name: <Name>os, arch },
os: { name: os, arch },
},
],
};
});
};

return downloads
.map(([os, nativeIndex]) => {
if ((<string>nativeIndex).includes("${arch}")) {
return ["32", "64"].map((arch) => {
const formattedNativeIndex = (<string>nativeIndex).replace("${arch}", arch);
return resolveNative(
library.downloads.classifiers[formattedNativeIndex],
<Name>os,
`x${arch}`,
);
});
} else {
return resolveNative(library.downloads.classifiers[nativeIndex], <Name>os);
}
})
.flat();
}

#resolveLibrary(library: Library): ProfileLibrary {
Expand All @@ -234,13 +251,11 @@ export class MojangManager extends AbstractDownloadManager {
}

#resolveRulesForNatives(library: Library) {
// TODO "natives": {"windows": "natives-windows-${arch}"}

if (!library.rules) {
return Object.entries(library.natives);
}

const res: [string, keyof Classifiers][] = [];
let res: [string, keyof Classifiers][] = [];
library.rules.forEach((rule) => {
if (rule.action === Action.Allow) {
if (rule.os) {
Expand All @@ -249,7 +264,7 @@ export class MojangManager extends AbstractDownloadManager {
res.push(...Object.entries(library.natives));
}
} else {
res.filter(([os]) => os !== rule.os.name);
res = res.filter(([os]) => os !== rule.os.name);
}
});
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface Classifiers {
"natives-osx"?: Artifact;
"natives-windows"?: Artifact;
"natives-macos"?: Artifact;
[x: string]: Artifact;
}

export interface Extract {
Expand Down

0 comments on commit 3b2b3e1

Please sign in to comment.