From 3d6457b5c1eb0799e83371c11e7e3b8eb2f662fa Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Mar 2017 15:13:28 -0700 Subject: [PATCH 1/4] Minor fixes from PS/PS repo --- .../Microsoft.PowerShell.Archive.psd1 | 2 +- .../Microsoft.PowerShell.Archive.psm1 | 292 +++++++++--------- .../en-US/ArchiveResources.psd1 | Bin 5124 -> 5124 bytes 3 files changed, 147 insertions(+), 147 deletions(-) diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psd1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psd1 index 8e3b890..5d543d6 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psd1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psd1 @@ -10,5 +10,5 @@ DotNetFrameworkVersion = 4.5 CmdletsToExport = @() AliasesToExport = @() NestedModules="Microsoft.PowerShell.Archive.psm1" -HelpInfoURI = 'http://go.microsoft.com/fwlink/?LinkId=393254' +HelpInfoURI = 'https://go.microsoft.com/fwlink/?LinkId=393254' } diff --git a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 index 06b05fe..7b79ee4 100644 --- a/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 +++ b/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1 @@ -11,7 +11,7 @@ ArchiveFileIsEmpty=The archive file {0} is empty. CompressProgressBarText=The archive file '{0}' creation is in progress... ExpandProgressBarText=The archive file '{0}' expansion is in progress... - AppendArchiveFileExtensionMessage=The archive file path '{0}' supplied to the DestinationPath patameter does not include .zip extension. Hence .zip is appended to the supplied DestinationPath path and the archive file would be created at '{1}'. + AppendArchiveFileExtensionMessage=The archive file path '{0}' supplied to the DestinationPath parameter does not include .zip extension. Hence .zip is appended to the supplied DestinationPath path and the archive file would be created at '{1}'. AddItemtoArchiveFile=Adding '{0}'. CreateFileAtExpandedPath=Created '{0}'. InvalidArchiveFilePathError=The archive file path '{0}' specified as input to the {1} parameter is resolving to multiple file system paths. Provide a unique path to the {2} parameter where the archive file has to be created. @@ -29,17 +29,17 @@ Import-LocalizedData LocalizedData -filename ArchiveResources $zipFileExtension = ".zip" -<############################################################################################ +<############################################################################################ # The Compress-Archive cmdlet can be used to zip/compress one or more files/directories. ############################################################################################> function Compress-Archive { [CmdletBinding( - DefaultParameterSetName="Path", + DefaultParameterSetName="Path", SupportsShouldProcess=$true, HelpUri="https://go.microsoft.com/fwlink/?LinkID=393252")] [OutputType([System.IO.File])] - param + param ( [parameter (mandatory=$true, Position=0, ParameterSetName="Path", ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [parameter (mandatory=$true, Position=0, ParameterSetName="PathWithForce", ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] @@ -55,15 +55,15 @@ function Compress-Archive [string[]] $LiteralPath, [parameter (mandatory=$true, - Position=1, - ValueFromPipeline=$false, + Position=1, + ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false)] [ValidateNotNullOrEmpty()] [string] $DestinationPath, [parameter ( - mandatory=$false, - ValueFromPipeline=$false, + mandatory=$false, + ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false)] [ValidateSet("Optimal","NoCompression","Fastest")] [string] @@ -83,7 +83,7 @@ function Compress-Archive $PassThru = $false ) - BEGIN + BEGIN { # Ensure the destination path is in a non-PS-specific format $DestinationPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($DestinationPath) @@ -103,7 +103,7 @@ function Compress-Archive $archiveFileName = [system.IO.Path]::GetFileName($DestinationPath) $destinationParentDir = GetResolvedPathHelper $destinationParentDir $false $PSCmdlet - + if($destinationParentDir.Count -gt 1) { $errorMessage = ($LocalizedData.InvalidArchiveFilePathError -f $DestinationPath, "DestinationPath", "DestinationPath") @@ -113,14 +113,14 @@ function Compress-Archive IsValidFileSystemPath $destinationParentDir | Out-Null $DestinationPath = Join-Path -Path $destinationParentDir -ChildPath $archiveFileName - # GetExtension API does not validate for the actual existance of the path. + # GetExtension API does not validate for the actual existence of the path. $extension = [system.IO.Path]::GetExtension($DestinationPath) # If user does not specify an extension, we append the .zip extension automatically. If($extension -eq [string]::Empty) { $DestinationPathWithOutExtension = $DestinationPath - $DestinationPath = $DestinationPathWithOutExtension + $zipFileExtension + $DestinationPath = $DestinationPathWithOutExtension + $zipFileExtension $appendArchiveFileExtensionMessage = ($LocalizedData.AppendArchiveFileExtensionMessage -f $DestinationPathWithOutExtension, $DestinationPath) Write-Verbose $appendArchiveFileExtensionMessage } @@ -133,7 +133,7 @@ function Compress-Archive ThrowTerminatingErrorHelper "ArchiveFileExists" $errorMessage ([System.Management.Automation.ErrorCategory]::InvalidArgument) $DestinationPath } - # If archive file already exists and if -Update is specified, then we check to see + # If archive file already exists and if -Update is specified, then we check to see # if we have write access permission to update the existing archive file. if($archiveFileExist -and $Update -eq $true) { @@ -155,38 +155,38 @@ function Compress-Archive ProgressBarHelper "Compress-Archive" $progressBarStatus 0 100 100 1 } } - PROCESS + PROCESS { - if($PsCmdlet.ParameterSetName -eq "Path" -or - $PsCmdlet.ParameterSetName -eq "PathWithForce" -or + if($PsCmdlet.ParameterSetName -eq "Path" -or + $PsCmdlet.ParameterSetName -eq "PathWithForce" -or $PsCmdlet.ParameterSetName -eq "PathWithUpdate") { $inputPaths += $Path } - if($PsCmdlet.ParameterSetName -eq "LiteralPath" -or - $PsCmdlet.ParameterSetName -eq "LiteralPathWithForce" -or + if($PsCmdlet.ParameterSetName -eq "LiteralPath" -or + $PsCmdlet.ParameterSetName -eq "LiteralPathWithForce" -or $PsCmdlet.ParameterSetName -eq "LiteralPathWithUpdate") { $inputPaths += $LiteralPath } } - END + END { - # If archive file already exists and if -Force is specified, we delete the - # existing artchive file and create a brand new one. - if(($PsCmdlet.ParameterSetName -eq "PathWithForce" -or + # If archive file already exists and if -Force is specified, we delete the + # existing archive file and create a brand new one. + if(($PsCmdlet.ParameterSetName -eq "PathWithForce" -or $PsCmdlet.ParameterSetName -eq "LiteralPathWithForce") -and $archiveFileExist) { Remove-Item -Path $DestinationPath -Force -ErrorAction Stop } - # Validate Source Path depeding on parameter set being used. - # The specified source path conatins one or more files or directories that needs + # Validate Source Path depending on parameter set being used. + # The specified source path contains one or more files or directories that needs # to be compressed. $isLiteralPathUsed = $false - if($PsCmdlet.ParameterSetName -eq "LiteralPath" -or - $PsCmdlet.ParameterSetName -eq "LiteralPathWithForce" -or + if($PsCmdlet.ParameterSetName -eq "LiteralPath" -or + $PsCmdlet.ParameterSetName -eq "LiteralPathWithForce" -or $PsCmdlet.ParameterSetName -eq "LiteralPathWithUpdate") { $isLiteralPathUsed = $true @@ -195,21 +195,21 @@ function Compress-Archive ValidateDuplicateFileSystemPath $PsCmdlet.ParameterSetName $inputPaths $resolvedPaths = GetResolvedPathHelper $inputPaths $isLiteralPathUsed $PSCmdlet IsValidFileSystemPath $resolvedPaths | Out-Null - + $sourcePath = $resolvedPaths; - # CSVHelper: This is a helper function used to append comma after each path specifid by - # the $sourcePath array. The comma saperated paths are displayed in the -WhatIf message. + # CSVHelper: This is a helper function used to append comma after each path specified by + # the $sourcePath array. The comma separated paths are displayed in the -WhatIf message. $sourcePathInCsvFormat = CSVHelper $sourcePath if($pscmdlet.ShouldProcess($sourcePathInCsvFormat)) { try { - # StopProcessing is not avaliable in Script cmdlets. However the pipleline execution + # StopProcessing is not available in Script cmdlets. However the pipeline execution # is terminated when ever 'CTRL + C' is entered by user to terminate the cmdlet execution. - # The finally block is executed whenever pipleline is terminated. + # The finally block is executed whenever pipeline is terminated. # $isArchiveFileProcessingComplete variable is used to track if 'CTRL + C' is entered by the - # user. + # user. $isArchiveFileProcessingComplete = $false $numberOfItemsArchived = CompressArchiveHelper $sourcePath $DestinationPath $CompressionLevel $Update @@ -218,11 +218,11 @@ function Compress-Archive } finally { - # The $isArchiveFileProcessingComplete would be set to $false if user has typed 'CTRL + C' to + # The $isArchiveFileProcessingComplete would be set to $false if user has typed 'CTRL + C' to # terminate the cmdlet execution or if an unhandled exception is thrown. # $numberOfItemsArchived contains the count of number of files or directories add to the archive file. - # If the newly created archive file is empty then we delete it as its not usable. - if(($isArchiveFileProcessingComplete -eq $false) -or + # If the newly created archive file is empty then we delete it as it's not usable. + if(($isArchiveFileProcessingComplete -eq $false) -or ($numberOfItemsArchived -eq 0)) { $DeleteArchiveFileMessage = ($LocalizedData.DeleteArchiveFile -f $DestinationPath) @@ -242,20 +242,20 @@ function Compress-Archive } } -<############################################################################################ +<############################################################################################ # The Expand-Archive cmdlet can be used to expand/extract an zip file. ############################################################################################> function Expand-Archive { [CmdletBinding( - DefaultParameterSetName="Path", + DefaultParameterSetName="Path", SupportsShouldProcess=$true, - HelpUri="https://go.microsoft.com/fwlink/?LinkID=393253")] + HelpUri="https://go.microsoft.com/fwlink/?LinkID=393253")] [OutputType([System.IO.FileSystemInfo])] - param + param ( [parameter ( - mandatory=$true, + mandatory=$true, Position=0, ParameterSetName="Path", ValueFromPipeline=$true, @@ -264,22 +264,22 @@ function Expand-Archive [string] $Path, [parameter ( - mandatory=$true, - ParameterSetName="LiteralPath", + mandatory=$true, + ParameterSetName="LiteralPath", ValueFromPipelineByPropertyName=$true)] [ValidateNotNullOrEmpty()] [Alias("PSPath")] [string] $LiteralPath, [parameter (mandatory=$false, - Position=1, - ValueFromPipeline=$false, + Position=1, + ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false)] [ValidateNotNullOrEmpty()] [string] $DestinationPath, [parameter (mandatory=$false, - ValueFromPipeline=$false, + ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$false)] [switch] $Force, @@ -287,8 +287,8 @@ function Expand-Archive $PassThru = $false ) - BEGIN - { + BEGIN + { $isVerbose = $psboundparameters.ContainsKey("Verbose") $isConfirm = $psboundparameters.ContainsKey("Confirm") @@ -305,7 +305,7 @@ function Expand-Archive { $resolvedDestinationPath = GetResolvedPathHelper $DestinationPath $false $PSCmdlet if($resolvedDestinationPath.Count -gt 1) - { + { $errorMessage = ($LocalizedData.InvalidExpandedDirPathError -f $DestinationPath) ThrowTerminatingErrorHelper "InvalidDestinationPath" $errorMessage ([System.Management.Automation.ErrorCategory]::InvalidArgument) $DestinationPath } @@ -329,10 +329,10 @@ function Expand-Archive ThrowTerminatingErrorHelper "InvalidDirectoryPath" $errorMessage ([System.Management.Automation.ErrorCategory]::InvalidArgument) $DestinationPath } - $resolvedDestinationPath = GetResolvedPathHelper $DestinationPath $true $PSCmdlet - } + $resolvedDestinationPath = GetResolvedPathHelper $DestinationPath $true $PSCmdlet + } } - + $isWhatIf = $psboundparameters.ContainsKey("WhatIf") if(!$isWhatIf) { @@ -343,7 +343,7 @@ function Expand-Archive ProgressBarHelper "Expand-Archive" $progressBarStatus 0 100 100 1 } } - PROCESS + PROCESS { switch($PsCmdlet.ParameterSetName) { @@ -352,36 +352,36 @@ function Expand-Archive $resolvedSourcePaths = GetResolvedPathHelper $Path $false $PSCmdlet if($resolvedSourcePaths.Count -gt 1) - { + { $errorMessage = ($LocalizedData.InvalidArchiveFilePathError -f $Path, $PsCmdlet.ParameterSetName, $PsCmdlet.ParameterSetName) ThrowTerminatingErrorHelper "InvalidArchiveFilePath" $errorMessage ([System.Management.Automation.ErrorCategory]::InvalidArgument) $Path } } - "LiteralPath" - { + "LiteralPath" + { $resolvedSourcePaths = GetResolvedPathHelper $LiteralPath $true $PSCmdlet if($resolvedSourcePaths.Count -gt 1) - { + { $errorMessage = ($LocalizedData.InvalidArchiveFilePathError -f $LiteralPath, $PsCmdlet.ParameterSetName, $PsCmdlet.ParameterSetName) ThrowTerminatingErrorHelper "InvalidArchiveFilePath" $errorMessage ([System.Management.Automation.ErrorCategory]::InvalidArgument) $LiteralPath } } } - + ValidateArchivePathHelper $resolvedSourcePaths - + if($pscmdlet.ShouldProcess($resolvedSourcePaths)) { $expandedItems = @() try { - # StopProcessing is not avaliable in Script cmdlets. However the pipleline execution + # StopProcessing is not available in Script cmdlets. However the pipeline execution # is terminated when ever 'CTRL + C' is entered by user to terminate the cmdlet execution. - # The finally block is executed whenever pipleline is terminated. + # The finally block is executed whenever pipeline is terminated. # $isArchiveFileProcessingComplete variable is used to track if 'CTRL + C' is entered by the - # user. + # user. $isArchiveFileProcessingComplete = $false # The User has not provided a destination path, hence we use '$pwd\ArchiveFileName' as the directory where the @@ -406,14 +406,14 @@ function Expand-Archive } finally { - # The $isArchiveFileProcessingComplete would be set to $false if user has typed 'CTRL + C' to + # The $isArchiveFileProcessingComplete would be set to $false if user has typed 'CTRL + C' to # terminate the cmdlet execution or if an unhandled exception is thrown. if($isArchiveFileProcessingComplete -eq $false) { if($expandedItems.Count -gt 0) { - # delete the expanded file/directory as the archive - # file was not completly expanded. + # delete the expanded file/directory as the archive + # file was not completely expanded. $expandedItems | % { Remove-Item "$_" -Force -Recurse } } } @@ -427,22 +427,22 @@ function Expand-Archive } } } -} +} -<############################################################################################ +<############################################################################################ # GetResolvedPathHelper: This is a helper function used to resolve the user specified Path. # The path can either be absolute or relative path. ############################################################################################> -function GetResolvedPathHelper +function GetResolvedPathHelper { - param + param ( [string[]] $path, [boolean] $isLiteralPath, [System.Management.Automation.PSCmdlet] $callerPSCmdlet ) - + $resolvedPaths =@() # null and empty check are are already done on Path parameter at the cmdlet layer. @@ -482,19 +482,19 @@ function Add-CompressionAssemblies { { Add-Type -AssemblyName System.IO.Compression.ZipFile } - else + else { Add-Type -AssemblyName System.IO.Compression.FileSystem } } -function IsValidFileSystemPath +function IsValidFileSystemPath { - param + param ( [string[]] $path ) - + $result = $true; # null and empty check are are already done on Path parameter at the cmdlet layer. @@ -511,14 +511,14 @@ function IsValidFileSystemPath } -function ValidateDuplicateFileSystemPath +function ValidateDuplicateFileSystemPath { - param + param ( [string] $inputParameter, [string[]] $path ) - + $uniqueInputPaths = @() # null and empty check are are already done on Path parameter at the cmdlet layer. @@ -539,7 +539,7 @@ function ValidateDuplicateFileSystemPath function CompressionLevelMapper { - param + param ( [string] $compressionLevel ) @@ -553,8 +553,8 @@ function CompressionLevelMapper { $compressionLevelFormat = [System.IO.Compression.CompressionLevel]::Fastest } - "NoCompression" - { + "NoCompression" + { $compressionLevelFormat = [System.IO.Compression.CompressionLevel]::NoCompression } } @@ -562,9 +562,9 @@ function CompressionLevelMapper return $compressionLevelFormat } -function CompressArchiveHelper +function CompressArchiveHelper { - param + param ( [string[]] $sourcePath, [string] $destinationPath, @@ -589,7 +589,7 @@ function CompressArchiveHelper } } - # The Soure Path contains one or more directory (this directory can have files under it) and no files to be compressed. + # The Source Path contains one or more directory (this directory can have files under it) and no files to be compressed. if($sourceFilePaths.Count -eq 0 -and $sourceDirPaths.Count -gt 0) { $currentSegmentWeight = 100/[double]$sourceDirPaths.Count @@ -602,7 +602,7 @@ function CompressArchiveHelper } } - # The Soure Path contains only files to be compressed. + # The Source Path contains only files to be compressed. elseIf($sourceFilePaths.Count -gt 0 -and $sourceDirPaths.Count -eq 0) { # $previousSegmentWeight is equal to 0 as there are no prior segments. @@ -612,10 +612,10 @@ function CompressArchiveHelper $numberOfItemsArchived = CompressFilesHelper $sourceFilePaths $destinationPath $compressionLevel $isUpdateMode $previousSegmentWeight $currentSegmentWeight } - # The Soure Path contains one or more files and one or more directories (this directory can have files under it) to be compressed. + # The Source Path contains one or more files and one or more directories (this directory can have files under it) to be compressed. elseif($sourceFilePaths.Count -gt 0 -and $sourceDirPaths.Count -gt 0) { - # each directory is considered as an individual segments & all the individual files are clubed in to a separate sgemnet. + # each directory is considered as an individual segments & all the individual files are clubed in to a separate segment. $currentSegmentWeight = 100/[double]($sourceDirPaths.Count +1) $previousSegmentWeight = 0 @@ -633,9 +633,9 @@ function CompressArchiveHelper return $numberOfItemsArchived } -function CompressFilesHelper +function CompressFilesHelper { - param + param ( [string[]] $sourceFilePaths, [string] $destinationPath, @@ -644,15 +644,15 @@ function CompressFilesHelper [double] $previousSegmentWeight, [double] $currentSegmentWeight ) - + $numberOfItemsArchived = ZipArchiveHelper $sourceFilePaths $destinationPath $compressionLevel $isUpdateMode $null $previousSegmentWeight $currentSegmentWeight return $numberOfItemsArchived } -function CompressSingleDirHelper +function CompressSingleDirHelper { - param + param ( [string] $sourceDirPath, [string] $destinationPath, @@ -671,8 +671,8 @@ function CompressSingleDirHelper $sourceDirFullName = $sourceDirInfo.Parent.FullName # If the directory is present at the drive level the DirectoryInfo.Parent include directory separator. example: C:\ - # On the other hand if the directory exists at a deper level then DirectoryInfo.Parent - # has just the path (without an ending directory separator). example C:\source + # On the other hand if the directory exists at a deper level then DirectoryInfo.Parent + # has just the path (without an ending directory separator). example C:\source if($sourceDirFullName.Length -eq 3) { $modifiedSourceDirFullName = $sourceDirFullName @@ -691,7 +691,7 @@ function CompressSingleDirHelper $dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse foreach($currentContent in $dirContents) { - $isContainer = $currentContent -is [System.IO.DirectoryInfo] + $isContainer = $currentContent -is [System.IO.DirectoryInfo] if(!$isContainer) { $subDirFiles.Add($currentContent.FullName) @@ -700,7 +700,7 @@ function CompressSingleDirHelper { # The currentContent points to a directory. # We need to check if the directory is an empty directory, if so such a - # directory has to be explictly added to the archive file. + # directory has to be explicitly added to the archive file. # if there are no files in the directory the GetFiles() API returns an empty array. $files = $currentContent.GetFiles() if($files.Count -eq 0) @@ -715,9 +715,9 @@ function CompressSingleDirHelper return $numberOfItemsArchived } -function ZipArchiveHelper +function ZipArchiveHelper { - param + param ( [System.Collections.Generic.List[System.String]] $sourcePaths, [string] $destinationPath, @@ -737,7 +737,7 @@ function ZipArchiveHelper } Add-CompressionAssemblies - + try { # At this point we are sure that the archive file has write access. @@ -768,19 +768,19 @@ function ZipArchiveHelper # Update mode is selected. # Check to see if archive file already contains one or more zip files in it. if($isUpdateMode -eq $true -and $zipArchive.Entries.Count -gt 0) - { + { $entryToBeUpdated = $null - # Check if the file already exists in the archive file. + # Check if the file already exists in the archive file. # If so replace it with new file from the input source. - # If the file does not exist in the archive file then default to + # If the file does not exist in the archive file then default to # create mode and create the entry in the archive file. foreach($currentArchiveEntry in $zipArchive.Entries) { if($currentArchiveEntry.FullName -eq $relativeFilePath) { - $entryToBeUpdated = $currentArchiveEntry + $entryToBeUpdated = $currentArchiveEntry break } } @@ -794,8 +794,8 @@ function ZipArchiveHelper $compression = CompressionLevelMapper $compressionLevel - # If a directory needs to be added to an archive file, - # by convention the .Net API's expect the path of the diretcory + # If a directory needs to be added to an archive file, + # by convention the .Net API's expect the path of the directory # to end with directory separator to detect the path as an directory. if(!$relativeFilePath.EndsWith([System.IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) { @@ -807,10 +807,10 @@ function ZipArchiveHelper } catch { - # Failed to access the file. Write a non terminating error to the pipeline + # Failed to access the file. Write a non terminating error to the pipeline # and move on with the remaining files. $exception = $_.Exception - if($null -ne $_.Exception -and + if($null -ne $_.Exception -and $null -ne $_.Exception.InnerException) { $exception = $_.Exception.InnerException @@ -825,17 +825,17 @@ function ZipArchiveHelper $currentArchiveEntry = $zipArchive.CreateEntry($relativeFilePath, $compression) - # Updating the File Creation time so that the same timestamp would be retained after expanding the compressed file. + # Updating the File Creation time so that the same timestamp would be retained after expanding the compressed file. # At this point we are sure that Get-ChildItem would succeed. $currentArchiveEntry.LastWriteTime = (Get-Item -LiteralPath $currentFilePath).LastWriteTime $destStream = New-Object System.IO.BinaryWriter $currentArchiveEntry.Open() - + while($numberOfBytesRead = $srcStream.Read($buffer, 0, $bufferSize)) { $destStream.Write($buffer, 0, $numberOfBytesRead) $destStream.Flush() - } + } $numberOfItemsArchived += 1 $addItemtoArchiveFileMessage = ($LocalizedData.AddItemtoArchiveFile -f $currentFilePath) @@ -892,13 +892,13 @@ function ZipArchiveHelper return $numberOfItemsArchived } -<############################################################################################ +<############################################################################################ # ValidateArchivePathHelper: This is a helper function used to validate the archive file # path & its file format. The only supported archive file format is .zip ############################################################################################> -function ValidateArchivePathHelper +function ValidateArchivePathHelper { - param + param ( [string] $archiveFile ) @@ -910,13 +910,13 @@ function ValidateArchivePathHelper } } -<############################################################################################ +<############################################################################################ # ExpandArchiveHelper: This is a helper function used to expand the archive file contents # to the specified directory. ############################################################################################> function ExpandArchiveHelper { - param + param ( [string] $archiveFile, [string] $expandedDir, @@ -930,7 +930,7 @@ function ExpandArchiveHelper try { - # The existance of archive file has already been validated by ValidateArchivePathHelper + # The existence of archive file has already been validated by ValidateArchivePathHelper # before calling this helper function. $archiveFileStreamArgs = @($archiveFile, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read) $archiveFileStream = New-Object -TypeName System.IO.FileStream -ArgumentList $archiveFileStreamArgs @@ -945,7 +945,7 @@ function ExpandArchiveHelper # Failed to open the file for reading as a zip archive. Wrap the exception # and re-throw it indicating it does not appear to be a valid zip file. $exception = $_.Exception - if($null -ne $_.Exception -and + if($null -ne $_.Exception -and $null -ne $_.Exception.InnerException) { $exception = $_.Exception.InnerException @@ -972,18 +972,18 @@ function ExpandArchiveHelper # The archive entries can either be empty directories or files. foreach($currentArchiveEntry in $zipArchive.Entries) { - $currentArchiveEntryPath = Join-Path -Path $expandedDir -ChildPath $currentArchiveEntry.FullName + $currentArchiveEntryPath = Join-Path -Path $expandedDir -ChildPath $currentArchiveEntry.FullName $extension = [system.IO.Path]::GetExtension($currentArchiveEntryPath) # The current archive entry is an empty directory # The FullName of the Archive Entry representing a directory would end with a trailing directory separator. - if($extension -eq [string]::Empty -and + if($extension -eq [string]::Empty -and $currentArchiveEntryPath.EndsWith([System.IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) { $pathExists = Test-Path -LiteralPath $currentArchiveEntryPath # The current archive entry expects an empty directory. - # Check if the existing directory is empty. If its not empty + # Check if the existing directory is empty. If it's not empty # then it means that user has added this directory by other means. if($pathExists -eq $false) { @@ -1005,19 +1005,19 @@ function ExpandArchiveHelper $currentArchiveEntryFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $currentArchiveEntryPath $parentDirExists = Test-Path -LiteralPath $currentArchiveEntryFileInfo.DirectoryName -PathType Container - # If the Parent directory of the current entry in the archive file does not exist, then create it. + # If the Parent directory of the current entry in the archive file does not exist, then create it. if($parentDirExists -eq $false) { # note that if any ancestor of this directory doesn't exist, we don't recursively create each one as New-Item - # takes care of this already, so only one DirectoryInfo is returned instead of one for each parent directory + # takes care of this already, so only one DirectoryInfo is returned instead of one for each parent directory # that only contains directories New-Item $currentArchiveEntryFileInfo.DirectoryName -Type Directory -Confirm:$isConfirm | Out-Null if(!(Test-Path -LiteralPath $currentArchiveEntryFileInfo.DirectoryName -PathType Container)) { # The directory referred by $currentArchiveEntryFileInfo.DirectoryName was not successfully created. - # This could be because the user has specified -Confirm paramter when Expand-Archive was invoked - # and authorization was not provided when confirmation was prompted. In such a scenario, + # This could be because the user has specified -Confirm parameter when Expand-Archive was invoked + # and authorization was not provided when confirmation was prompted. In such a scenario, # we skip the current file in the archive and continue with the remaining archive file contents. Continue } @@ -1027,7 +1027,7 @@ function ExpandArchiveHelper $hasNonTerminatingError = $false - # Check if the file in to which the current archive entry contents + # Check if the file in to which the current archive entry contents # would be expanded already exists. if($currentArchiveEntryFileInfo.Exists) { @@ -1042,8 +1042,8 @@ function ExpandArchiveHelper if(Test-Path -LiteralPath $currentArchiveEntryFileInfo.FullName -PathType Leaf) { # The file referred by $currentArchiveEntryFileInfo.FullName was not successfully removed. - # This could be because the user has specified -Confirm paramter when Expand-Archive was invoked - # and authorization was not provided when confirmation was prompted. In such a scenario, + # This could be because the user has specified -Confirm parameter when Expand-Archive was invoked + # and authorization was not provided when confirmation was prompted. In such a scenario, # we skip the current file in the archive and continue with the remaining archive file contents. Continue } @@ -1067,9 +1067,9 @@ function ExpandArchiveHelper [System.IO.Compression.ZipFileExtensions]::ExtractToFile($currentArchiveEntry, $currentArchiveEntryPath, $false) - # Add the expanded file path to the $expandedItems array, + # Add the expanded file path to the $expandedItems array, # to keep track of all the expanded files created while expanding the archive file. - # If user enters CTRL + C then at that point of time, all these expanded files + # If user enters CTRL + C then at that point of time, all these expanded files # would be deleted as part of the clean up process. $expandedItems.Value += $currentArchiveEntryPath @@ -1090,7 +1090,7 @@ function ExpandArchiveHelper } } } - + $currentEntryCount += 1 # $currentSegmentWeight is Set to 100 giving equal weightage to each file that is getting expanded. # $previousSegmentWeight is set to 0 as there are no prior segments. @@ -1116,14 +1116,14 @@ function ExpandArchiveHelper } } -<############################################################################################ +<############################################################################################ # ProgressBarHelper: This is a helper function used to display progress message. # This function is used by both Compress-Archive & Expand-Archive to display archive file # creation/expansion progress. ############################################################################################> -function ProgressBarHelper +function ProgressBarHelper { - param + param ( [string] $cmdletName, [string] $status, @@ -1133,31 +1133,31 @@ function ProgressBarHelper [int] $currentEntryCount ) - if($currentEntryCount -gt 0 -and - $totalNumberofEntries -gt 0 -and - $previousSegmentWeight -ge 0 -and + if($currentEntryCount -gt 0 -and + $totalNumberofEntries -gt 0 -and + $previousSegmentWeight -ge 0 -and $currentSegmentWeight -gt 0) { $entryDefaultWeight = $currentSegmentWeight/[double]$totalNumberofEntries $percentComplete = $previousSegmentWeight + ($entryDefaultWeight * $currentEntryCount) - Write-Progress -Activity $cmdletName -Status $status -PercentComplete $percentComplete + Write-Progress -Activity $cmdletName -Status $status -PercentComplete $percentComplete } } -<############################################################################################ -# CSVHelper: This is a helper function used to append comma after each path specifid by +<############################################################################################ +# CSVHelper: This is a helper function used to append comma after each path specified by # the SourcePath array. This helper function is used to display all the user supplied paths # in the WhatIf message. ############################################################################################> -function CSVHelper +function CSVHelper { - param + param ( [string[]] $sourcePath ) - # SourcePath has already been validated by the calling funcation. + # SourcePath has already been validated by the calling function. if($sourcePath.Count -gt 1) { $sourcePathInCsvFormat = "`n" @@ -1181,12 +1181,12 @@ function CSVHelper return $sourcePathInCsvFormat } -<############################################################################################ +<############################################################################################ # ThrowTerminatingErrorHelper: This is a helper function used to throw terminating error. ############################################################################################> -function ThrowTerminatingErrorHelper +function ThrowTerminatingErrorHelper { - param + param ( [string] $errorId, [string] $errorMessage, @@ -1209,12 +1209,12 @@ function ThrowTerminatingErrorHelper $PSCmdlet.ThrowTerminatingError($errorRecord) } -<############################################################################################ +<############################################################################################ # CreateErrorRecordHelper: This is a helper function used to create an ErrorRecord ############################################################################################> -function CreateErrorRecordHelper +function CreateErrorRecordHelper { - param + param ( [string] $errorId, [string] $errorMessage, diff --git a/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 b/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 index 914f951df0fc7ca023e898d5f507f03564e11d25..780db382ae6dea97d916ac48d36a0e0b97ec4681 100644 GIT binary patch delta 19 acmZqCXwldp!ZkU8PhjFRq0MGo=QsgDRR)Uy delta 25 gcmZqCXwldp!o^v_kjRkBkjhXp@xJ6{Gp=)-0A3LXo&W#< From 2b5ecd2c929013e2e823569eef66575df989775a Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Mar 2017 15:48:27 -0700 Subject: [PATCH 2/4] Saved ArchiveResources.psd1 as UTF-8 --- .../en-US/ArchiveResources.psd1 | Bin 5124 -> 2564 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 b/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 index 780db382ae6dea97d916ac48d36a0e0b97ec4681..706891a0dba249db4cc461e36ebce5383ee4446c 100644 GIT binary patch literal 2564 zcmb_e%WfMt6x|EZKU}~IZR$bXt^>riEL1?+7>ScbcJ%PdA}}JSBuBDhw+)O8TDz5)78x;oS9T^ZwFQ*d_RD~RRpT!gk`i#1Q*5&6k z^|<(d%`0M*##4eb&F{QH%W~pH$k6$`sVh@rFp=faIv86wi83Lu2c~p3Dq{nn(1++G zPOQ$=_gO)A-fa_V)L8RpgZ%*W5QeN5q5?=gB>s7j7~PB{cDt!#tFNJaTQ#w~MaYfY z)Sg2?(MS3HRrz~JxW` zPAk9&Mf6gBB;%cHDlLne*8$cNTiU^%)=T(cbc4a);-PG6LSN`gTO=NG9W&mnlOyIA zx;xm~+#r=4JF{Fv@Ms1UmAQx9{r8@w6o$9sh zJP$QYJKP$1<3_Np(G1S_xB-fG!UGC(ZbZjE=4wcM+Tu47duW(OKs`HcpeTot?7D`Q!$8!9;s%X3xJMeODP+*jF0G+;gsQy$odCehc_$RE1l( z+pAOW0*^XHXKlyBP2U9dP;sxQ0ZpQ)R6zG1AjyYYIdulonmRl^f7guEYjGta{hep* t4+yw-2iN_={=o%4xLS8Y_%2&#PTtzRxp!IcuSI62Q(XVaHhVXn{0j{omYVT?>t315aU;`>bZ>$tlK>+o7T7hxWb!>_t(B&QD7;apnQdRO85a1>9y3cN_q3t)=Tia**1DlW-~9W|Fhq?5!m4DSRD1>bugNTb*P_qpPXT zU~?rYNaX&X+OdkikyphlzmJ6uCM0tg00QVsrDNZ`ggfrBi8Zq<116c>LJ09vj`~-?e|K*qh&Yw$|xd zy3N`=7Z&$Y3|GqBQZF=eo>-3c+mV&W_A2h1$2bhM^GWFXsBiPw@>#`L-9`I9M>?o& z=P3C)l#k$jENkD&V{|#*$dTdsy?nzbvat|CDqR^S`#o$&YNgYlk&J-fZLJ^~iM8Sd z_P}(d-ykd@`F*@Yl&3Ln#F*F(qeYLBd>>ENI*TMSVEXbiZo5~8RcwF0zLF#mHJ1)J z!ex{_=|;|S>F4_6Hd7XeRwZxj`#ACfNMe<$YxJJ$3O}i6^U`dCH>hOxT742ntj8)_ zrKV=#A?_$6)T+E&8O9`eMO^NU1USa*m_|%{{NdOt{I>BoVe42cp6gwne{O!s4slEo zcMD+T{UiUNy&#t;CmHVLODMCLpUaA+B6Sn2G$NPR7y$ z(}5Mb$F^?ged{`~)KSdVNWOwN#~Sggb^V9Fi9o7(V+^byCZ>zelEvRf7VKJVvFT^A z3)RC?^4t7X#x`tA_e^X{UE5jHLU(5ctgiGjPp_Y^e~>4Qx-ywvxA?M8U*5017OlG^ zD~JZsCaSJ$pjew#7g@*sZ!N+PBJLe;Uz<*KZmBqQr-0O9uo?`z?4LGK9m~tvUeQa) zY0o{WBT^~WZH)y}-R+({%52h|p2*5X)p);Q)Pbf(rUjd;+MdB-KSp1TseP|?^>G%h zlEqz*_VEFKo#~VJ{r%-Z__~)zbVuu`j>t5%z#(8ZRl7|PQ=J*cY|iz$=$R=_w9ZZ< zcfFBgvudg???nkEr;?ZB8#_iDzBtjO>?g3=tH~q|rOBtcGDjq7hjp$#wb^O!GYX!-)oir!r_y7g0IiCqls{Uy}6a$2_)sfCUu+Bz1!{b z9(_C|n)P&pnYfQ=Sp{4QLuY#Dv+g_XY2@`nHqXNLtk#v0aEFz-9G_deXV6QnV+)hx Ur|QfR==w_kvK{F^IA)lC0in;9F8}}l From 6fc5bd808d524734693b6ab29e09870909840ea4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Mar 2017 16:10:19 -0700 Subject: [PATCH 3/4] removed ArchiveResources.psd1 --- .../en-US/ArchiveResources.psd1 | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 diff --git a/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 b/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 deleted file mode 100644 index 706891a..0000000 --- a/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 +++ /dev/null @@ -1,25 +0,0 @@ -# Localized ArchiveResources.psd1 - -ConvertFrom-StringData @' -###PSLOC -PathNotFoundError=The path '{0}' either does not exist or is not a valid file system path. -ExpandArchiveInValidDestinationPath=The path '{0}' is not a valid file system directory path. -InvalidZipFileExtensionError={0} is not a supported archive file format. {1} is the only supported archive file format. -ArchiveFileIsReadOnly=The attributes of the archive file {0} is set to 'ReadOnly' hence it cannot be updated. If you intend to update the existing archive file, remove the 'ReadOnly' attribute on the archive file else use -Force parameter to override and create a new archive file. -ZipFileExistError=The archive file {0} already exists. Use the -Update parameter to update the existing archive file or use the -Force parameter to overwrite the existing archive file. -DuplicatePathFoundError=The input to {0} parameter contains a duplicate path '{1}'. Provide a unique set of paths as input to {2} parameter. -ArchiveFileIsEmpty=The archive file {0} is empty. -CompressProgressBarText=The archive file '{0}' creation is in progress... -ExpandProgressBarText=The archive file '{0}' expansion is in progress... -AppendArchiveFileExtensionMessage=The archive file path '{0}' supplied to the DestinationPath parameter does not include .zip extension. Hence .zip is appended to the supplied DestinationPath path and the archive file would be created at '{1}'. -AddItemtoArchiveFile=Adding '{0}'. -CreateFileAtExpandedPath=Created '{0}'. -InvalidArchiveFilePathError=The archive file path '{0}' specified as input to the {1} parameter is resolving to multiple file system paths. Provide a unique path to the {2} parameter where the archive file has to be created. -InvalidExpandedDirPathError=The directory path '{0}' specified as input to the DestinationPath parameter is resolving to multiple file system paths. Provide a unique path to the Destination parameter where the archive file contents have to be expanded. -FileExistsError=Failed to create file '{0}' while expanding the archive file '{1}' contents as the file '{2}' already exists. Use the -Force parameter if you want to overwrite the existing directory '{3}' contents when expanding the archive file. -DeleteArchiveFile=The partially created archive file '{0}' is deleted as it is not usable. -InvalidDestinationPath=The destination path '{0}' does not contain a valid archive file name. -PreparingToCompressVerboseMessage=Preparing to compress... -PreparingToExpandVerboseMessage=Preparing to expand... -###PSLOC -'@ From 6e28be44d2b8f1690ce3385503b97eca34c86e5e Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Mar 2017 16:11:33 -0700 Subject: [PATCH 4/4] UTF-8 ArchiveResources.psd1 --- .../en-US/ArchiveResources.psd1 | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 diff --git a/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 b/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 new file mode 100644 index 0000000..706891a --- /dev/null +++ b/Microsoft.PowerShell.Archive/en-US/ArchiveResources.psd1 @@ -0,0 +1,25 @@ +# Localized ArchiveResources.psd1 + +ConvertFrom-StringData @' +###PSLOC +PathNotFoundError=The path '{0}' either does not exist or is not a valid file system path. +ExpandArchiveInValidDestinationPath=The path '{0}' is not a valid file system directory path. +InvalidZipFileExtensionError={0} is not a supported archive file format. {1} is the only supported archive file format. +ArchiveFileIsReadOnly=The attributes of the archive file {0} is set to 'ReadOnly' hence it cannot be updated. If you intend to update the existing archive file, remove the 'ReadOnly' attribute on the archive file else use -Force parameter to override and create a new archive file. +ZipFileExistError=The archive file {0} already exists. Use the -Update parameter to update the existing archive file or use the -Force parameter to overwrite the existing archive file. +DuplicatePathFoundError=The input to {0} parameter contains a duplicate path '{1}'. Provide a unique set of paths as input to {2} parameter. +ArchiveFileIsEmpty=The archive file {0} is empty. +CompressProgressBarText=The archive file '{0}' creation is in progress... +ExpandProgressBarText=The archive file '{0}' expansion is in progress... +AppendArchiveFileExtensionMessage=The archive file path '{0}' supplied to the DestinationPath parameter does not include .zip extension. Hence .zip is appended to the supplied DestinationPath path and the archive file would be created at '{1}'. +AddItemtoArchiveFile=Adding '{0}'. +CreateFileAtExpandedPath=Created '{0}'. +InvalidArchiveFilePathError=The archive file path '{0}' specified as input to the {1} parameter is resolving to multiple file system paths. Provide a unique path to the {2} parameter where the archive file has to be created. +InvalidExpandedDirPathError=The directory path '{0}' specified as input to the DestinationPath parameter is resolving to multiple file system paths. Provide a unique path to the Destination parameter where the archive file contents have to be expanded. +FileExistsError=Failed to create file '{0}' while expanding the archive file '{1}' contents as the file '{2}' already exists. Use the -Force parameter if you want to overwrite the existing directory '{3}' contents when expanding the archive file. +DeleteArchiveFile=The partially created archive file '{0}' is deleted as it is not usable. +InvalidDestinationPath=The destination path '{0}' does not contain a valid archive file name. +PreparingToCompressVerboseMessage=Preparing to compress... +PreparingToExpandVerboseMessage=Preparing to expand... +###PSLOC +'@