mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 04:06:21 +03:00
Update handler.js
This commit is contained in:
parent
4a6c340180
commit
b856fb0f7f
1 changed files with 65 additions and 36 deletions
|
@ -697,49 +697,78 @@ class Handler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadToDirectory (directory, libraries, eventName) {
|
async downloadToDirectory(directory, libraries, eventName) {
|
||||||
const libs = []
|
const libs = [];
|
||||||
|
|
||||||
await Promise.all(libraries.map(async library => {
|
await Promise.all(
|
||||||
if (!library) return
|
libraries.map(async (library) => {
|
||||||
if (this.parseRule(library)) return
|
if (!library) return;
|
||||||
const lib = library.name.split(':')
|
if (this.parseRule(library)) return;
|
||||||
|
const lib = library.name.split(":");
|
||||||
|
|
||||||
let jarPath
|
let jarPath;
|
||||||
let name
|
let name;
|
||||||
if (library.downloads && library.downloads.artifact && library.downloads.artifact.path) {
|
if (
|
||||||
name = library.downloads.artifact.path.split('/')[library.downloads.artifact.path.split('/').length - 1]
|
library.downloads &&
|
||||||
jarPath = path.join(directory, this.popString(library.downloads.artifact.path))
|
library.downloads.artifact &&
|
||||||
} else {
|
library.downloads.artifact.path
|
||||||
name = `${lib[1]}-${lib[2]}${lib[3] ? '-' + lib[3] : ''}.jar`
|
) {
|
||||||
jarPath = path.join(directory, `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`)
|
name =
|
||||||
}
|
library.downloads.artifact.path.split("/")[
|
||||||
|
library.downloads.artifact.path.split("/").length - 1
|
||||||
const downloadLibrary = async library => {
|
];
|
||||||
if (library.url) {
|
jarPath = path.join(
|
||||||
const url = `${library.url}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${name}`
|
directory,
|
||||||
await this.downloadAsync(url, jarPath, name, true, eventName)
|
this.popString(library.downloads.artifact.path)
|
||||||
} else if (library.downloads && library.downloads.artifact) {
|
);
|
||||||
await this.downloadAsync(library.downloads.artifact.url, jarPath, name, true, eventName)
|
} else {
|
||||||
|
name = `${lib[1]}-${lib[2]}${lib[3] ? "-" + lib[3] : ""}.jar`;
|
||||||
|
jarPath = path.join(
|
||||||
|
directory,
|
||||||
|
`${lib[0].replace(/\./g, "/")}/${lib[1]}/${lib[2]}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(path.join(jarPath, name))) downloadLibrary(library)
|
const downloadLibrary = async (library) => {
|
||||||
else if (library.downloads && library.downloads.artifact) {
|
if (library.url) {
|
||||||
if (!this.checkSum(library.downloads.artifact.sha1, path.join(jarPath, name))) downloadLibrary(library)
|
const url = `${library.url}${lib[0].replace(/\./g, "/")}/${
|
||||||
}
|
lib[1]
|
||||||
|
}/${lib[2]}/${name}`;
|
||||||
|
await this.downloadAsync(url, jarPath, name, true, eventName);
|
||||||
|
} else if (library.downloads && library.downloads.artifact) {
|
||||||
|
await this.downloadAsync(
|
||||||
|
library.downloads.artifact.url,
|
||||||
|
jarPath,
|
||||||
|
name,
|
||||||
|
true,
|
||||||
|
eventName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
counter++
|
if (!fs.existsSync(path.join(jarPath, name))) downloadLibrary(library);
|
||||||
this.client.emit('progress', {
|
else if (library.downloads && library.downloads.artifact) {
|
||||||
type: eventName,
|
if (
|
||||||
task: counter,
|
!this.checkSum(
|
||||||
total: libraries.length
|
library.downloads.artifact.sha1,
|
||||||
|
path.join(jarPath, name)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
downloadLibrary(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
this.client.emit("progress", {
|
||||||
|
type: eventName,
|
||||||
|
task: counter,
|
||||||
|
total: libraries.length,
|
||||||
|
});
|
||||||
|
libs.push(`${jarPath}${path.sep}${name}`);
|
||||||
})
|
})
|
||||||
libs.push(`${jarPath}${path.sep}${name}`)
|
);
|
||||||
}))
|
counter = 0;
|
||||||
counter = 0
|
|
||||||
|
|
||||||
return libs
|
return libs;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getClasses(classJson) {
|
async getClasses(classJson) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue