@@ -104,30 +104,40 @@ export class PackageManager {
104104 tmp . setGracefulCleanup ( ) ;
105105 }
106106
107- public DownloadPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void | null > {
107+ public DownloadPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void | null > {
108108 return this . GetPackages ( )
109109 . then ( ( packages ) => {
110110 let count : number = 1 ;
111111 return this . BuildPromiseChain ( packages , ( pkg ) : Promise < void > => {
112- const p : Promise < void > = this . DownloadPackage ( pkg , `${ count } /${ packages . length } ` , progress ) ;
112+ const p : Promise < void > = this . DownloadPackage ( pkg ) ;
113+ progress . report ( { message : localize ( "downloading.progress.description" , "Downloading {0}" , pkg . description ) , increment : this . GetIncrement ( count , packages . length ) } ) ;
113114 count += 1 ;
114115 return p ;
115116 } ) ;
116117 } ) ;
117118 }
118119
119- public InstallPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void | null > {
120+ public InstallPackages ( progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void | null > {
120121 return this . GetPackages ( )
121122 . then ( ( packages ) => {
122123 let count : number = 1 ;
123124 return this . BuildPromiseChain ( packages , ( pkg ) : Promise < void > => {
124- const p : Promise < void > = this . InstallPackage ( pkg , `${ count } /${ packages . length } ` , progress ) ;
125+ const p : Promise < void > = this . InstallPackage ( pkg ) ;
126+ progress . report ( { message : localize ( "installing.progress.description" , "Installing {0}" , pkg . description ) , increment : this . GetIncrement ( count , packages . length ) } ) ;
125127 count += 1 ;
126128 return p ;
127129 } ) ;
128130 } ) ;
129131 }
130132
133+ private GetIncrement ( curStep : number , totalSteps : number ) : number {
134+ // The first half of the progress bar is assigned to download progress,
135+ // and the second half of the progress bar is assigned to install progress.
136+ const maxIncrement : number = 100 / 2 ;
137+ const increment : number = Math . floor ( maxIncrement / totalSteps ) ;
138+ return ( curStep !== totalSteps ) ? increment : maxIncrement - ( totalSteps - 1 ) * increment ;
139+ }
140+
131141 public GetPackages ( ) : Promise < IPackage [ ] > {
132142 return this . GetPackageList ( )
133143 . then ( ( list ) =>
@@ -175,13 +185,11 @@ export class PackageManager {
175185 } ) ;
176186 }
177187
178- private async DownloadPackage ( pkg : IPackage , progressCount : string , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
188+ private async DownloadPackage ( pkg : IPackage ) : Promise < void > {
179189 this . AppendChannel ( localize ( "downloading.package" , "Downloading package '{0}' " , pkg . description ) ) ;
180190
181- progress . report ( { message : localize ( "downloading.progress.description" , "Downloading {0}: {1}" , progressCount , pkg . description ) } ) ;
182-
183191 const tmpResult : tmp . FileResult = await this . CreateTempFile ( pkg ) ;
184- await this . DownloadPackageWithRetries ( pkg , tmpResult , progress ) ;
192+ await this . DownloadPackageWithRetries ( pkg , tmpResult ) ;
185193 }
186194
187195 private async CreateTempFile ( pkg : IPackage ) : Promise < tmp . FileResult > {
@@ -196,7 +204,7 @@ export class PackageManager {
196204 } ) ;
197205 }
198206
199- private async DownloadPackageWithRetries ( pkg : IPackage , tmpResult : tmp . FileResult , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
207+ private async DownloadPackageWithRetries ( pkg : IPackage , tmpResult : tmp . FileResult ) : Promise < void > {
200208 pkg . tmpFile = tmpResult ;
201209
202210 let success : boolean = false ;
@@ -207,7 +215,7 @@ export class PackageManager {
207215 // Retry the download at most MAX_RETRIES times with 2-32 seconds delay.
208216 do {
209217 try {
210- await this . DownloadFile ( pkg . url , pkg , retryCount , progress ) ;
218+ await this . DownloadFile ( pkg . url , pkg , retryCount ) ;
211219 success = true ;
212220 } catch ( error ) {
213221 retryCount += 1 ;
@@ -244,7 +252,7 @@ export class PackageManager {
244252 }
245253
246254 // reloadCpptoolsJson in main.ts uses ~25% of this function.
247- private DownloadFile ( urlString : any , pkg : IPackage , delay : number , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
255+ private DownloadFile ( urlString : any , pkg : IPackage , delay : number ) : Promise < void > {
248256 const parsedUrl : url . Url = url . parse ( urlString ) ;
249257 const proxyStrictSSL : any = vscode . workspace . getConfiguration ( ) . get ( "http.proxyStrictSSL" , true ) ;
250258
@@ -281,7 +289,7 @@ export class PackageManager {
281289 }
282290 redirectUrl = response . headers . location [ 0 ] ;
283291 }
284- return resolve ( this . DownloadFile ( redirectUrl , pkg , 0 , progress ) ) ;
292+ return resolve ( this . DownloadFile ( redirectUrl , pkg , 0 ) ) ;
285293 } else if ( response . statusCode !== 200 ) {
286294 if ( response . statusCode === undefined || response . statusCode === null ) {
287295 return reject ( new PackageManagerError ( 'Invalid response code received' , localize ( "invalid.response.code.received" , 'Invalid response code received' ) , 'DownloadFile' , pkg ) ) ;
@@ -348,11 +356,9 @@ export class PackageManager {
348356 } ) ;
349357 }
350358
351- private InstallPackage ( pkg : IPackage , progressCount : string , progress : vscode . Progress < { message ?: string ; increment ?: number } > ) : Promise < void > {
359+ private InstallPackage ( pkg : IPackage ) : Promise < void > {
352360 this . AppendLineChannel ( localize ( "installing.package" , "Installing package '{0}'" , pkg . description ) ) ;
353361
354- progress . report ( { message : `Installing ${ progressCount } : ${ pkg . description } ` } ) ;
355-
356362 return new Promise < void > ( ( resolve , reject ) => {
357363 if ( ! pkg . tmpFile || pkg . tmpFile . fd === 0 ) {
358364 return reject ( new PackageManagerError ( 'Downloaded file unavailable' , localize ( "downloaded.unavailable" , 'Downloaded file unavailable' ) , 'InstallPackage' , pkg ) ) ;
0 commit comments