mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 04:06:21 +03:00
Merge pull request #23 from Coding-Kiwi/master
Fixed wrong total value in downloadAsync
This commit is contained in:
commit
b1f59bf3ab
1 changed files with 51 additions and 5 deletions
|
@ -45,6 +45,13 @@ class Handler {
|
|||
|
||||
const _request = this.baseRequest(url);
|
||||
|
||||
let received_bytes = 0;
|
||||
let total_bytes = 0;
|
||||
|
||||
_request.on('response', (data) => {
|
||||
total_bytes = parseInt(data.headers['content-length']);
|
||||
});
|
||||
|
||||
_request.on('error', async (error) => {
|
||||
this.client.emit('debug', `[MCLC]: Failed to download asset to ${path.join(directory, name)} due to\n${error}.` +
|
||||
` Retrying... ${retry}`);
|
||||
|
@ -53,12 +60,11 @@ class Handler {
|
|||
});
|
||||
|
||||
_request.on('data', (data) => {
|
||||
let size = 0;
|
||||
if (fs.existsSync(path.join(directory, name))) size = fs.statSync(path.join(directory, name))["size"];
|
||||
received_bytes += data.length;
|
||||
this.client.emit('download-status', {
|
||||
"name": name,
|
||||
"current": Math.round(size / 10000),
|
||||
"total": data.length
|
||||
"current": received_bytes,
|
||||
"total": total_bytes
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -139,6 +145,12 @@ class Handler {
|
|||
|
||||
const index = require(path.join(this.options.root, 'assets', 'indexes',`${this.version.assetIndex.id}.json`));
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'assets',
|
||||
task: 0,
|
||||
total: Object.keys(index.objects).length
|
||||
});
|
||||
|
||||
await Promise.all(Object.keys(index.objects).map(async asset => {
|
||||
const hash = index.objects[asset].hash;
|
||||
const subhash = hash.substring(0,2);
|
||||
|
@ -161,6 +173,13 @@ class Handler {
|
|||
if(this.version.assets === "legacy" || this.version.assets === "pre-1.6") {
|
||||
const assetDirectory = this.options.overrides.assetRoot || path.join(this.options.root, 'assets');
|
||||
this.client.emit('debug', `[MCLC]: Copying assets over to ${path.join(assetDirectory, 'legacy')}`);
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'assets-copy',
|
||||
task: 0,
|
||||
total: Object.keys(index.objects).length
|
||||
});
|
||||
|
||||
await Promise.all(Object.keys(index.objects).map(async asset => {
|
||||
const hash = index.objects[asset].hash;
|
||||
const subhash = hash.substring(0,2);
|
||||
|
@ -233,6 +252,13 @@ class Handler {
|
|||
})
|
||||
};
|
||||
const stat = await natives();
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'natives',
|
||||
task: 0,
|
||||
total: stat.length
|
||||
});
|
||||
|
||||
await Promise.all(stat.map(async (native) => {
|
||||
const name = native.path.split('/').pop();
|
||||
await this.downloadAsync(native.url, nativeDirectory, name);
|
||||
|
@ -273,6 +299,12 @@ class Handler {
|
|||
const forge = require(path.join(this.options.root, 'forge', `${this.version.id}`, 'version.json'));
|
||||
const paths = [];
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'forge',
|
||||
task: 0,
|
||||
total: forge.libraries.length
|
||||
});
|
||||
|
||||
await Promise.all(forge.libraries.map(async library => {
|
||||
const lib = library.name.split(':');
|
||||
|
||||
|
@ -305,7 +337,7 @@ class Handler {
|
|||
paths.push(`${jarPath}${path.sep}${name}`);
|
||||
counter = counter + 1;
|
||||
this.client.emit('progress', {
|
||||
type: 'natives-forge',
|
||||
type: 'forge',
|
||||
task: counter,
|
||||
total: forge.libraries.length
|
||||
})
|
||||
|
@ -330,6 +362,13 @@ class Handler {
|
|||
|
||||
if(this.options.version.custom) {
|
||||
const customJarJson = require(path.join(this.options.root, 'versions', this.options.version.custom, `${this.options.version.custom}.json`));
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'classes-custom',
|
||||
task: 0,
|
||||
total: customJarJson.libraries.length
|
||||
});
|
||||
|
||||
await Promise.all(customJarJson.libraries.map(async library => {
|
||||
const lib = library.name.split(':');
|
||||
|
||||
|
@ -366,6 +405,13 @@ class Handler {
|
|||
})
|
||||
};
|
||||
const parsed = await parsedClasses();
|
||||
|
||||
this.client.emit('progress', {
|
||||
type: 'classes',
|
||||
task: 0,
|
||||
total: parsed.length
|
||||
});
|
||||
|
||||
await Promise.all(parsed.map(async (_lib) => {
|
||||
const libraryPath = _lib.downloads.artifact.path;
|
||||
const libraryUrl = _lib.downloads.artifact.url;
|
||||
|
|
Loading…
Add table
Reference in a new issue