@@ -145,15 +145,15 @@ private void ProcessRepositories(
145
145
bool skipDependencyCheck )
146
146
{
147
147
var listOfRepositories = RepositorySettings . Read ( repository , out string [ ] _ ) ;
148
- List < string > pckgNamesToInstall = packageNames . ToList ( ) ;
148
+ List < string > pkgNamesToInstall = packageNames . ToList ( ) ;
149
149
var yesToAll = false ;
150
150
var noToAll = false ;
151
151
152
152
var findHelper = new FindHelper ( _cancellationToken , _cmdletPassedIn ) ;
153
153
foreach ( var repo in listOfRepositories )
154
154
{
155
155
// If no more packages to install, then return
156
- if ( ! pckgNamesToInstall . Any ( ) ) return ;
156
+ if ( ! pkgNamesToInstall . Any ( ) ) return ;
157
157
158
158
string repoName = repo . Name ;
159
159
_cmdletPassedIn . WriteVerbose ( string . Format ( "Attempting to search for packages in '{0}'" , repoName ) ) ;
@@ -185,7 +185,7 @@ private void ProcessRepositories(
185
185
186
186
// Finds parent packages and dependencies
187
187
IEnumerable < PSResourceInfo > pkgsFromRepoToInstall = findHelper . FindByResourceName (
188
- name : pckgNamesToInstall . ToArray ( ) ,
188
+ name : pkgNamesToInstall . ToArray ( ) ,
189
189
type : ResourceType . None ,
190
190
version : _versionRange != null ? _versionRange . OriginalString : null ,
191
191
prerelease : _prerelease ,
@@ -225,14 +225,14 @@ private void ProcessRepositories(
225
225
226
226
List < string > pkgsInstalled = InstallPackage (
227
227
pkgsFromRepoToInstall ,
228
- repoName ,
228
+ pkgNamesToInstall ,
229
229
repo . Url . AbsoluteUri ,
230
230
credential ,
231
231
isLocalRepo ) ;
232
232
233
233
foreach ( string name in pkgsInstalled )
234
234
{
235
- pckgNamesToInstall . Remove ( name ) ;
235
+ pkgNamesToInstall . Remove ( name ) ;
236
236
}
237
237
}
238
238
}
@@ -286,15 +286,26 @@ private IEnumerable<PSResourceInfo> FilterByInstalledPkgs(IEnumerable<PSResource
286
286
}
287
287
288
288
private List < string > InstallPackage (
289
- IEnumerable < PSResourceInfo > pkgsToInstall ,
290
- string repoName ,
289
+ IEnumerable < PSResourceInfo > pkgsToInstall , // those found to be required to be installed (includes Dependency packages as well)
290
+ List < string > pkgNamesToInstall , // those requested by the user to be installed
291
291
string repoUrl ,
292
292
PSCredential credential ,
293
293
bool isLocalRepo )
294
294
{
295
295
List < string > pkgsSuccessfullyInstalled = new List < string > ( ) ;
296
- foreach ( PSResourceInfo pkgInfo in pkgsToInstall )
296
+ int totalPkgs = pkgsToInstall . Count ( ) ;
297
+
298
+ // counters for tracking dependent package and current package out of total
299
+ int totalPkgsCount = 0 ;
300
+ int dependentPkgCount = 1 ;
301
+ // by default this is 1, because if a parent package was already installed and only the dependent package
302
+ // needs to be installed we don't want a default value of 0 which throws a division error.
303
+ // if parent package isn't already installed we'll set this value properly in the below if condition anyways
304
+ int currentPkgNumOfDependentPkgs = 1 ;
305
+
306
+ foreach ( PSResourceInfo pkg in pkgsToInstall )
297
307
{
308
+ totalPkgsCount ++ ;
298
309
var tempInstallPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
299
310
try
300
311
{
@@ -307,24 +318,47 @@ private List<string> InstallPackage(
307
318
// TODO: are there Linux accommodations we need to consider here?
308
319
dir . Attributes = dir . Attributes & ~ FileAttributes . ReadOnly ;
309
320
310
- _cmdletPassedIn . WriteVerbose ( string . Format ( "Begin installing package: '{0}'" , pkgInfo . Name ) ) ;
321
+ _cmdletPassedIn . WriteVerbose ( string . Format ( "Begin installing package: '{0}'" , pkg . Name ) ) ;
322
+
323
+ int activityId = 0 ;
324
+ string activity = "" ;
325
+ string statusDescription = "" ;
326
+
327
+ if ( pkgNamesToInstall . ToList ( ) . Contains ( pkg . Name , StringComparer . InvariantCultureIgnoreCase ) )
328
+ {
329
+ // Installing parent package (one whose name was passed in to install)
330
+ activityId = 0 ;
331
+ activity = string . Format ( "Installing {0}..." , pkg . Name ) ;
332
+ statusDescription = string . Format ( "{0}% Complete:" , Math . Round ( ( ( double ) totalPkgsCount / totalPkgs ) * 100 ) , 2 ) ;
333
+ currentPkgNumOfDependentPkgs = pkg . Dependencies . Count ( ) ;
334
+ dependentPkgCount = 1 ;
335
+ }
336
+ else
337
+ {
338
+ // Installing dependent package
339
+ activityId = 1 ;
340
+ activity = string . Format ( "Installing dependent package {0}..." , pkg . Name ) ;
341
+ statusDescription = string . Format ( "{0}% Complete:" , Math . Round ( ( ( double ) dependentPkgCount / currentPkgNumOfDependentPkgs ) * 100 ) , 2 ) ;
342
+ dependentPkgCount ++ ;
343
+ }
311
344
312
- // TODO: add progress bar here
313
-
345
+ var progressRecord = new ProgressRecord ( activityId , activity , statusDescription ) ;
346
+ _cmdletPassedIn . WriteProgress ( progressRecord ) ;
347
+
314
348
// Create PackageIdentity in order to download
315
- string createFullVersion = pkgInfo . Version . ToString ( ) ;
316
- if ( pkgInfo . IsPrerelease )
349
+ string createFullVersion = pkg . Version . ToString ( ) ;
350
+ if ( pkg . IsPrerelease )
317
351
{
318
- createFullVersion = pkgInfo . Version . ToString ( ) + "-" + pkgInfo . PrereleaseLabel ;
352
+ createFullVersion = pkg . Version . ToString ( ) + "-" + pkg . PrereleaseLabel ;
319
353
}
320
354
321
355
if ( ! NuGetVersion . TryParse ( createFullVersion , out NuGetVersion pkgVersion ) )
322
356
{
323
357
_cmdletPassedIn . WriteVerbose ( string . Format ( "Error parsing package '{0}' version '{1}' into a NuGetVersion" ,
324
- pkgInfo . Name , pkgInfo . Version . ToString ( ) ) ) ;
358
+ pkg . Name , pkg . Version . ToString ( ) ) ) ;
325
359
continue ;
326
360
}
327
- var pkgIdentity = new PackageIdentity ( pkgInfo . Name , pkgVersion ) ;
361
+ var pkgIdentity = new PackageIdentity ( pkg . Name , pkgVersion ) ;
328
362
var cacheContext = new SourceCacheContext ( ) ;
329
363
330
364
if ( isLocalRepo )
@@ -419,8 +453,8 @@ private List<string> InstallPackage(
419
453
string tempDirNameVersion = isLocalRepo ? tempInstallPath : Path . Combine ( tempInstallPath , pkgIdentity . Id . ToLower ( ) , newVersion ) ;
420
454
var version4digitNoPrerelease = pkgIdentity . Version . Version . ToString ( ) ;
421
455
string moduleManifestVersion = string . Empty ;
422
- var scriptPath = Path . Combine ( tempDirNameVersion , pkgInfo . Name + ".ps1" ) ;
423
- var modulePath = Path . Combine ( tempDirNameVersion , pkgInfo . Name + ".psd1" ) ;
456
+ var scriptPath = Path . Combine ( tempDirNameVersion , pkg . Name + ".ps1" ) ;
457
+ var modulePath = Path . Combine ( tempDirNameVersion , pkg . Name + ".psd1" ) ;
424
458
// Check if the package is a module or a script
425
459
var isModule = File . Exists ( modulePath ) ;
426
460
@@ -446,13 +480,13 @@ private List<string> InstallPackage(
446
480
moduleManifestVersion = parsedMetadataHashtable [ "ModuleVersion" ] as string ;
447
481
448
482
// Accept License verification
449
- if ( ! _savePkg && ! CallAcceptLicense ( pkgInfo , moduleManifest , tempInstallPath , newVersion ) )
483
+ if ( ! _savePkg && ! CallAcceptLicense ( pkg , moduleManifest , tempInstallPath , newVersion ) )
450
484
{
451
485
continue ;
452
486
}
453
487
454
488
// If NoClobber is specified, ensure command clobbering does not happen
455
- if ( _noClobber && ! DetectClobber ( pkgInfo . Name , parsedMetadataHashtable ) )
489
+ if ( _noClobber && ! DetectClobber ( pkg . Name , parsedMetadataHashtable ) )
456
490
{
457
491
continue ;
458
492
}
@@ -478,11 +512,11 @@ private List<string> InstallPackage(
478
512
479
513
if ( _includeXML )
480
514
{
481
- CreateMetadataXMLFile ( tempDirNameVersion , installPath , pkgInfo , isModule ) ;
515
+ CreateMetadataXMLFile ( tempDirNameVersion , installPath , pkg , isModule ) ;
482
516
}
483
517
484
518
MoveFilesIntoInstallPath (
485
- pkgInfo ,
519
+ pkg ,
486
520
isModule ,
487
521
isLocalRepo ,
488
522
tempDirNameVersion ,
@@ -492,15 +526,15 @@ private List<string> InstallPackage(
492
526
moduleManifestVersion ,
493
527
scriptPath ) ;
494
528
495
- _cmdletPassedIn . WriteVerbose ( String . Format ( "Successfully installed package '{0}' to location '{1}'" , pkgInfo . Name , installPath ) ) ;
496
- pkgsSuccessfullyInstalled . Add ( pkgInfo . Name ) ;
529
+ _cmdletPassedIn . WriteVerbose ( String . Format ( "Successfully installed package '{0}' to location '{1}'" , pkg . Name , installPath ) ) ;
530
+ pkgsSuccessfullyInstalled . Add ( pkg . Name ) ;
497
531
}
498
532
catch ( Exception e )
499
533
{
500
534
_cmdletPassedIn . WriteError (
501
535
new ErrorRecord (
502
536
new PSInvalidOperationException (
503
- message : $ "Unable to successfully install package '{ pkgInfo . Name } ': '{ e . Message } '",
537
+ message : $ "Unable to successfully install package '{ pkg . Name } ': '{ e . Message } '",
504
538
innerException : e ) ,
505
539
"InstallPackageFailed" ,
506
540
ErrorCategory . InvalidOperation ,
0 commit comments