@@ -67,24 +67,33 @@ export class PackageManager {
67
67
68
68
public constructor (
69
69
private platformInfo : PlatformInformation ,
70
- private outputChannel ?: Logger ,
71
- private statusItem ?: vscode . StatusBarItem ) {
70
+ private outputChannel ?: Logger ) {
72
71
// Ensure our temp files get cleaned up in case of error
73
72
tmp . setGracefulCleanup ( ) ;
74
73
}
75
74
76
- public DownloadPackages ( ) : Promise < void > {
75
+ public DownloadPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
77
76
return this . GetPackages ( )
78
77
. then ( ( packages ) => {
79
- return this . BuildPromiseChain ( packages , ( pkg ) => this . DownloadPackage ( pkg ) ) ;
78
+ let count : number = 1 ;
79
+ return this . BuildPromiseChain ( packages , ( pkg ) : Promise < void > => {
80
+ const p : Promise < void > = this . DownloadPackage ( pkg , `${ count } /${ packages . length } ` , progress ) ;
81
+ count += 1 ;
82
+ return p ;
83
+ } ) ;
80
84
} ) ;
81
85
}
82
86
83
- public InstallPackages ( ) : Promise < void > {
87
+ public InstallPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
84
88
return this . GetPackages ( )
85
- . then ( ( packages ) => {
86
- return this . BuildPromiseChain ( packages , ( pkg ) => this . InstallPackage ( pkg ) ) ;
89
+ . then ( ( packages ) => {
90
+ let count : number = 1 ;
91
+ return this . BuildPromiseChain ( packages , ( pkg ) : Promise < void > => {
92
+ const p : Promise < void > = this . InstallPackage ( pkg , `${ count } /${ packages . length } ` , progress ) ;
93
+ count += 1 ;
94
+ return p ;
87
95
} ) ;
96
+ } ) ;
88
97
}
89
98
90
99
/** Builds a chain of promises by calling the promiseBuilder function once per item in the list.
@@ -137,14 +146,13 @@ export class PackageManager {
137
146
} ) ;
138
147
}
139
148
140
- private async DownloadPackage ( pkg : IPackage ) : Promise < void > {
149
+ private async DownloadPackage ( pkg : IPackage , progressCount : string , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
141
150
this . AppendChannel ( `Downloading package '${ pkg . description } ' ` ) ;
142
151
143
- this . SetStatusText ( "$(cloud-download) Downloading packages..." ) ;
144
- this . SetStatusTooltip ( `Downloading package '${ pkg . description } '...` ) ;
152
+ progress . report ( { message : `Downloading ${ progressCount } : ${ pkg . description } ` } ) ;
145
153
146
154
const tmpResult : tmp . SyncResult = await this . CreateTempFile ( pkg ) ;
147
- await this . DownloadPackageWithRetries ( pkg , tmpResult ) ;
155
+ await this . DownloadPackageWithRetries ( pkg , tmpResult , progress ) ;
148
156
}
149
157
150
158
private async CreateTempFile ( pkg : IPackage ) : Promise < tmp . SyncResult > {
@@ -159,7 +167,7 @@ export class PackageManager {
159
167
} ) ;
160
168
}
161
169
162
- private async DownloadPackageWithRetries ( pkg : IPackage , tmpResult : tmp . SyncResult ) : Promise < void > {
170
+ private async DownloadPackageWithRetries ( pkg : IPackage , tmpResult : tmp . SyncResult , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
163
171
pkg . tmpFile = tmpResult ;
164
172
165
173
let success : boolean = false ;
@@ -170,7 +178,7 @@ export class PackageManager {
170
178
// Retry the download at most MAX_RETRIES times with 2-32 seconds delay.
171
179
do {
172
180
try {
173
- await this . DownloadFile ( pkg . url , pkg , retryCount ) ;
181
+ await this . DownloadFile ( pkg . url , pkg , retryCount , progress ) ;
174
182
success = true ;
175
183
} catch ( error ) {
176
184
retryCount += 1 ;
@@ -208,7 +216,7 @@ export class PackageManager {
208
216
}
209
217
210
218
// reloadCpptoolsJson in main.ts uses ~25% of this function.
211
- private DownloadFile ( urlString : any , pkg : IPackage , delay : number ) : Promise < void > {
219
+ private DownloadFile ( urlString : any , pkg : IPackage , delay : number , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
212
220
let parsedUrl : url . Url = url . parse ( urlString ) ;
213
221
let proxyStrictSSL : any = vscode . workspace . getConfiguration ( ) . get ( "http.proxyStrictSSL" , true ) ;
214
222
@@ -241,7 +249,7 @@ export class PackageManager {
241
249
} else {
242
250
redirectUrl = response . headers . location [ 0 ] ;
243
251
}
244
- return resolve ( this . DownloadFile ( redirectUrl , pkg , 0 ) ) ;
252
+ return resolve ( this . DownloadFile ( redirectUrl , pkg , 0 , progress ) ) ;
245
253
} else if ( response . statusCode !== 200 ) {
246
254
// Download failed - print error message
247
255
let errorMessage : string = `failed (error code '${ response . statusCode } ')` ;
@@ -255,23 +263,13 @@ export class PackageManager {
255
263
contentLength = response . headers [ 'content-length' ] [ 0 ] ;
256
264
}
257
265
let packageSize : number = parseInt ( contentLength , 10 ) ;
258
- let downloadedBytes : number = 0 ;
259
266
let downloadPercentage : number = 0 ;
260
267
let dots : number = 0 ;
261
268
let tmpFile : fs . WriteStream = fs . createWriteStream ( null , { fd : pkg . tmpFile . fd } ) ;
262
269
263
270
this . AppendChannel ( `(${ Math . ceil ( packageSize / 1024 ) } KB) ` ) ;
264
271
265
272
response . on ( 'data' , ( data ) => {
266
- downloadedBytes += data . length ;
267
-
268
- // Update status bar item with percentage
269
- let newPercentage : number = Math . ceil ( 100 * ( downloadedBytes / packageSize ) ) ;
270
- if ( newPercentage !== downloadPercentage ) {
271
- this . SetStatusTooltip ( `Downloading package '${ pkg . description } '... ${ downloadPercentage } %` ) ;
272
- downloadPercentage = newPercentage ;
273
- }
274
-
275
273
// Update dots after package name in output console
276
274
let newDots : number = Math . ceil ( downloadPercentage / 5 ) ;
277
275
if ( newDots > dots ) {
@@ -305,11 +303,10 @@ export class PackageManager {
305
303
} ) ;
306
304
}
307
305
308
- private InstallPackage ( pkg : IPackage ) : Promise < void > {
306
+ private InstallPackage ( pkg : IPackage , progressCount : string , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
309
307
this . AppendLineChannel ( `Installing package '${ pkg . description } '` ) ;
310
308
311
- this . SetStatusText ( "$(desktop-download) Installing packages..." ) ;
312
- this . SetStatusTooltip ( `Installing package '${ pkg . description } '` ) ;
309
+ progress . report ( { message : `Installing ${ progressCount } : ${ pkg . description } ` } ) ;
313
310
314
311
return new Promise < void > ( ( resolve , reject ) => {
315
312
if ( ! pkg . tmpFile || pkg . tmpFile . fd === 0 ) {
@@ -424,18 +421,4 @@ export class PackageManager {
424
421
this . outputChannel . appendLine ( text ) ;
425
422
}
426
423
}
427
-
428
- private SetStatusText ( text : string ) : void {
429
- if ( this . statusItem ) {
430
- this . statusItem . text = text ;
431
- this . statusItem . show ( ) ;
432
- }
433
- }
434
-
435
- private SetStatusTooltip ( text : string ) : void {
436
- if ( this . statusItem ) {
437
- this . statusItem . tooltip = text ;
438
- this . statusItem . show ( ) ;
439
- }
440
- }
441
424
}
0 commit comments