mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-07 10:35:09 +00:00
Possibly improved memory usage
This commit is contained in:
@@ -30,7 +30,6 @@ export class ChartDownload {
|
|||||||
private files: DriveFile[]
|
private files: DriveFile[]
|
||||||
private percent = 0 // Needs to be stored here because errors won't know the exact percent
|
private percent = 0 // Needs to be stored here because errors won't know the exact percent
|
||||||
private tempPath: string
|
private tempPath: string
|
||||||
private dropFastUpdate = false
|
|
||||||
private wasCanceled = false
|
private wasCanceled = false
|
||||||
|
|
||||||
private readonly individualFileProgressPortion: number
|
private readonly individualFileProgressPortion: number
|
||||||
@@ -100,14 +99,6 @@ export class ChartDownload {
|
|||||||
*/
|
*/
|
||||||
private updateGUI(header: string, description: string, type: ProgressType, isLink = false) {
|
private updateGUI(header: string, description: string, type: ProgressType, isLink = false) {
|
||||||
if (this.wasCanceled) { return }
|
if (this.wasCanceled) { return }
|
||||||
if (type == 'fastUpdate') {
|
|
||||||
if (this.dropFastUpdate) {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
this.dropFastUpdate = true
|
|
||||||
setTimeout(() => this.dropFastUpdate = false, 30)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emitIPCEvent('download-updated', {
|
emitIPCEvent('download-updated', {
|
||||||
versionID: this.versionID,
|
versionID: this.versionID,
|
||||||
@@ -222,7 +213,7 @@ export class ChartDownload {
|
|||||||
const size = Number(this.files[fileIndex].size)
|
const size = Number(this.files[fileIndex].size)
|
||||||
fileProgress = interpolate(bytesDownloaded, 0, size, downloadStartPoint, this.individualFileProgressPortion)
|
fileProgress = interpolate(bytesDownloaded, 0, size, downloadStartPoint, this.individualFileProgressPortion)
|
||||||
this.percent = this._allFilesProgress + fileProgress
|
this.percent = this._allFilesProgress + fileProgress
|
||||||
this.updateGUI(downloadHeader, `Downloading... (${Math.round(1000 * bytesDownloaded / size) / 10}%)`, 'fastUpdate')
|
this.updateGUI(downloadHeader, `Downloading... (${Math.round(1000 * bytesDownloaded / size) / 10}%)`, 'good')
|
||||||
})
|
})
|
||||||
|
|
||||||
downloader.on('error', this.handleError.bind(this))
|
downloader.on('error', this.handleError.bind(this))
|
||||||
@@ -249,7 +240,7 @@ export class ChartDownload {
|
|||||||
|
|
||||||
extractor.on('extractProgress', (percent, filecount) => {
|
extractor.on('extractProgress', (percent, filecount) => {
|
||||||
this.percent = interpolate(percent, 0, 100, 80, 95)
|
this.percent = interpolate(percent, 0, 100, 80, 95)
|
||||||
this.updateGUI(`[${archive}] (${filecount} file${filecount == 1 ? '' : 's'} extracted)`, `Extracting... (${percent}%)`, 'fastUpdate')
|
this.updateGUI(`[${archive}] (${filecount} file${filecount == 1 ? '' : 's'} extracted)`, `Extracting... (${percent}%)`, 'good')
|
||||||
})
|
})
|
||||||
|
|
||||||
extractor.on('error', this.handleError.bind(this))
|
extractor.on('error', this.handleError.bind(this))
|
||||||
|
|||||||
@@ -134,22 +134,33 @@ class APIFileDownloader {
|
|||||||
private handleDownloadResponse() {
|
private handleDownloadResponse() {
|
||||||
this.callbacks.downloadProgress(0)
|
this.callbacks.downloadProgress(0)
|
||||||
let downloadedSize = 0
|
let downloadedSize = 0
|
||||||
|
const writeStream = createWriteStream(this.fullPath)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.downloadStream.pipe(createWriteStream(this.fullPath))
|
this.downloadStream.pipe(writeStream)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.failDownload(downloadErrors.connectionError(err))
|
this.failDownload(downloadErrors.connectionError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.downloadStream.on('data', this.cancelable((chunk: Buffer) => {
|
this.downloadStream.on('data', this.cancelable((chunk: Buffer) => {
|
||||||
downloadedSize += chunk.length
|
downloadedSize += chunk.length
|
||||||
this.callbacks.downloadProgress(downloadedSize)
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const progressUpdater = setInterval(() => {
|
||||||
|
this.callbacks.downloadProgress(downloadedSize)
|
||||||
|
}, 100)
|
||||||
|
|
||||||
this.downloadStream.on('error', this.cancelable((err: Error) => {
|
this.downloadStream.on('error', this.cancelable((err: Error) => {
|
||||||
|
clearInterval(progressUpdater)
|
||||||
this.failDownload(downloadErrors.connectionError(err))
|
this.failDownload(downloadErrors.connectionError(err))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
this.downloadStream.on('end', this.cancelable(() => {
|
this.downloadStream.on('end', this.cancelable(() => {
|
||||||
|
clearInterval(progressUpdater)
|
||||||
|
writeStream.end()
|
||||||
|
this.downloadStream.destroy()
|
||||||
|
this.downloadStream = null
|
||||||
|
|
||||||
this.callbacks.complete()
|
this.callbacks.complete()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,4 +32,4 @@ export interface DownloadProgress {
|
|||||||
isLink: boolean
|
isLink: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProgressType = 'good' | 'error' | 'cancel' | 'done' | 'fastUpdate'
|
export type ProgressType = 'good' | 'error' | 'cancel' | 'done'
|
||||||
Reference in New Issue
Block a user