@@ -815,48 +815,43 @@ begin {
815
815
function Expand-FromArchiveType {
816
816
param (
817
817
[string ]$SourceFile ,
818
- [string ]$DestinationFolder
818
+ [string ]$DestinationFolder ,
819
+ [string ]$FileExtension ,
820
+ [string ]$Executable
819
821
)
820
822
821
823
# Define a mapping table for command templates
822
824
$commandTemplates = @ {
823
- ' tar.xz' = ' tar -xJf "{0 }" -C "{1 }"'
824
- ' tar.bz2' = ' tar -xjf "{0 }" -C "{1 }"'
825
- ' tar.gz' = ' tar -xzf "{0 }" -C "{1 }"'
826
- ' tar' = ' tar -xf "{0 }" -C "{1 }"'
827
- ' xz' = ' xz -d "{0 }" -C "{1 }"'
828
- ' 7z' = ' 7z x "{0 }" -o"{1 }"'
829
- ' bzip2' = ' bzip2 -d "{0 }" -C "{1 }"'
830
- ' gzip' = ' gzip -d "{0 }" -C "{1 }"'
825
+ ' tar.xz' = ' {0} -xJf "{1 }" -C "{2 }"'
826
+ ' tar.bz2' = ' {0} -xjf "{1 }" -C "{2 }"'
827
+ ' tar.gz' = ' {0} -xzf "{1 }" -C "{2 }"'
828
+ ' tar' = ' {0} -xf "{1 }" -C "{2 }"'
829
+ ' xz' = ' {0} -d "{1 }" -C "{2 }"'
830
+ ' 7z' = ' {0} x "{1 }" -o"{2 }"'
831
+ ' bzip2' = ' {0} -d "{1 }" -C "{2 }"'
832
+ ' gzip' = ' {0} -d "{1 }" -C "{2 }"'
831
833
}
832
834
833
- # Extract the full extension, including multi-part extensions
834
- $fileName = [System.IO.Path ]::GetFileName($SourceFile )
835
- $fileExtension = $commandTemplates.Keys | Where-Object { $fileName.EndsWith ($_ ) } | Select-Object - First 1
836
-
837
- if ($null -eq $fileExtension ) {
838
- if ($fileName.EndsWith (' .zip' )) {
839
- # Use .NET functions to extract zip files
840
- Add-Type - AssemblyName System.IO.Compression.FileSystem
841
- [System.IO.Compression.ZipFile ]::ExtractToDirectory($SourceFile , $DestinationFolder )
842
- Write-Verbose " Extracted zip file using .NET functions."
843
- }
844
- else {
845
- throw " Unsupported archive format: $fileName "
846
- }
835
+ if ($null -eq $Executable ) {
836
+ throw " Unsupported archive format: $FileExtension "
837
+ }
838
+ elseif ($Executable -eq ' powershell' ) {
839
+ # Use .NET functions to extract zip files
840
+ Add-Type - AssemblyName System.IO.Compression.FileSystem
841
+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($SourceFile , $DestinationFolder )
842
+ Write-Verbose " Extracted zip file using .NET functions."
847
843
}
848
844
else {
849
- $commandTemplate = $commandTemplates [$fileExtension ]
850
- $command = $commandTemplate -f $SourceFile , $DestinationFolder
845
+ $commandTemplate = $commandTemplates [$FileExtension ]
846
+ $command = $commandTemplate -f $Executable , $ SourceFile, $DestinationFolder
851
847
Write-Verbose " Running command: $command "
852
848
853
849
# Split the command into the executable and its arguments
854
850
$commandParts = $command -split ' ' , 2
855
- $executable = $commandParts [0 ]
856
851
$arguments = if ($commandParts.Length -gt 1 ) { $commandParts [1 ] } else { " " }
857
852
858
853
# Execute the external command
859
- Start-Process - FilePath $executable - ArgumentList $arguments - NoNewWindow - Wait
854
+ Start-Process - FilePath $Executable - ArgumentList $arguments - NoNewWindow - Wait
860
855
}
861
856
}
862
857
# endregion Functions -------------------------------------------------------
@@ -978,30 +973,30 @@ begin {
978
973
$archivePreferenceOrder = @ (' tar.xz' , ' 7z' , ' tar.bz2' , ' tar.gz' , ' zip' , ' tar' )
979
974
980
975
# ZIP is natively supported in PowerShell
981
- [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' zip' ; Command = ' powershell' })
976
+ [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' zip' ; Executable = ' powershell' })
982
977
983
978
if ($IsMacOS -or $IsLinux ) {
984
979
# Prefer tar if available
985
980
if (Get-Command tar - ErrorAction Ignore) {
986
- if (Test-TarSupportsFormat ' xz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Command = ' tar' }) }
987
- if (Test-TarSupportsFormat ' bzip2' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Command = ' tar' }) }
988
- if (Test-TarSupportsFormat ' gz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Command = ' tar' }) }
989
- [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar' ; Command = ' tar' })
981
+ if (Test-TarSupportsFormat ' xz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Executable = ' tar' }) }
982
+ if (Test-TarSupportsFormat ' bzip2' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Executable = ' tar' }) }
983
+ if (Test-TarSupportsFormat ' gz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Executable = ' tar' }) }
984
+ [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar' ; Executable = ' tar' })
990
985
}
991
986
# Check for individual tools
992
- if (Get-Command xz - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Command = ' xz' }) }
993
- if (Get-Command 7z - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' 7z' ; Command = ' 7z' }) }
994
- if (Get-Command bzip2 - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Command = ' bzip2' }) }
995
- if (Get-Command gzip - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Command = ' gzip' }) }
987
+ if (Get-Command xz - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Executable = ' xz' }) }
988
+ if (Get-Command 7z - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' 7z' ; Executable = ' 7z' }) }
989
+ if (Get-Command bzip2 - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Executable = ' bzip2' }) }
990
+ if (Get-Command gzip - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Executable = ' gzip' }) }
996
991
}
997
992
else {
998
993
if (Get-Command tar - ErrorAction Ignore) {
999
- if (Test-TarSupportsFormat ' xz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Command = ' tar' }) }
1000
- if (Test-TarSupportsFormat ' bzip2' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Command = ' tar' }) }
1001
- if (Test-TarSupportsFormat ' gz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Command = ' tar' }) }
1002
- [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar' ; Command = ' tar' })
994
+ if (Test-TarSupportsFormat ' xz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.xz' ; Executable = ' tar' }) }
995
+ if (Test-TarSupportsFormat ' bzip2' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.bz2' ; Executable = ' tar' }) }
996
+ if (Test-TarSupportsFormat ' gz' ) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar.gz' ; Executable = ' tar' }) }
997
+ [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' tar' ; Executable = ' tar' })
1003
998
}
1004
- if (Get-Command 7z - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' 7z' ; Command = ' 7z' }) }
999
+ if (Get-Command 7z - ErrorAction Ignore) { [void ]$supportedArchiveFormats.Add ([pscustomobject ]@ {FileExtension = ' 7z' ; Executable = ' 7z' }) }
1005
1000
}
1006
1001
1007
1002
# Sort the supportedArchiveFormats based on the preference order and remove duplicates
@@ -1057,7 +1052,7 @@ process {
1057
1052
1058
1053
Write-Verbose " Font archive URL: $assetUrl "
1059
1054
Write-Verbose " Font archive format: $ ( $archiveFormat.FileExtension ) "
1060
- Write-Verbose " Font archive extract command : $ ( $archiveFormat.Command ) "
1055
+ Write-Verbose " Font archive extract executable : $ ( $archiveFormat.Executable ) "
1061
1056
1062
1057
if (
1063
1058
$PSCmdlet.ShouldProcess (
@@ -1102,7 +1097,7 @@ process {
1102
1097
else {
1103
1098
Write-Verbose " Extracting font files to $extractPath "
1104
1099
$null = [System.IO.Directory ]::CreateDirectory($extractPath )
1105
- Expand-FromArchiveType - SourceFile $archivePath - DestinationFolder $extractPath
1100
+ Expand-FromArchiveType - SourceFile $archivePath - DestinationFolder $extractPath - FileExtension $archiveFormat .FileExtension - Executable $archiveFormat .Executable
1106
1101
}
1107
1102
1108
1103
# Determine search paths for font files based in $Variant parameter
0 commit comments