@@ -974,49 +974,56 @@ function Extract-PortablePython {
974974 New-Item - ItemType Directory - Path $pythonTargetDir - Force | Out-Null
975975
976976 # Extract zip file, excluding Doc directory
977- Add-Type - AssemblyName System.IO.Compression.FileSystem
978- Add-Type - AssemblyName System.IO.Compression
979- Write-LogInfo " extracting_archive" $archivePath
980- $zip = [System.IO.Compression.ZipFile ]::OpenRead($archivePath )
981977 try {
982- $totalEntries = ($zip.Entries | Where-Object { $_.FullName -notlike ' Doc/*' -and $_.FullName -ne ' Doc' }).Count
983- $current = 0
984- foreach ($entry in $zip.Entries ) {
985- if ($entry.FullName -like ' Doc/*' -or $entry.FullName -eq ' Doc' ) { continue }
986- $current ++
987- if ($current % 10 -eq 0 -or $current -eq $totalEntries ) {
988- Write-Progress - Activity " Extracting Python" - Status " File $current of $totalEntries " - PercentComplete (($current / $totalEntries ) * 100 ) - Id 1
989- }
990- $entryPath = Join-Path $pythonTargetDir $entry.FullName
991- if ($entry.Name -eq ' ' ) {
992- # Directory entry
993- New-Item - ItemType Directory - Path $entryPath - Force | Out-Null
994- }
995- else {
996- $entryDir = Split-Path $entryPath - Parent
997- if (-not (Test-Path $entryDir )) {
998- New-Item - ItemType Directory - Path $entryDir - Force | Out-Null
978+ Add-Type - AssemblyName System.IO.Compression.FileSystem
979+ Add-Type - AssemblyName System.IO.Compression
980+ Write-LogInfo " extracting_archive" $archivePath
981+ $zip = [System.IO.Compression.ZipFile ]::OpenRead($archivePath )
982+ try {
983+ $totalEntries = ($zip.Entries | Where-Object { $_.FullName -notlike ' Doc/*' -and $_.FullName -ne ' Doc' }).Count
984+ $current = 0
985+ foreach ($entry in $zip.Entries ) {
986+ if ($entry.FullName -like ' Doc/*' -or $entry.FullName -eq ' Doc' ) { continue }
987+ $current ++
988+ if ($current % 10 -eq 0 -or $current -eq $totalEntries ) {
989+ Write-Progress - Activity " Extracting Python" - Status " File $current of $totalEntries " - PercentComplete (($current / $totalEntries ) * 100 ) - Id 1
999990 }
1000- # Use .NET 4.5+ method to extract file
1001- $stream = [System.IO.File ]::Create($entryPath )
1002- try {
1003- $entryStream = $entry.Open ()
991+ $entryPath = Join-Path $pythonTargetDir $entry.FullName
992+ if ($entry.Name -eq ' ' ) {
993+ # Directory entry
994+ New-Item - ItemType Directory - Path $entryPath - Force | Out-Null
995+ }
996+ else {
997+ $entryDir = Split-Path $entryPath - Parent
998+ if (-not (Test-Path $entryDir )) {
999+ New-Item - ItemType Directory - Path $entryDir - Force | Out-Null
1000+ }
1001+ # Use .NET 4.5+ method to extract file
1002+ $stream = [System.IO.File ]::Create($entryPath )
10041003 try {
1005- $entryStream.CopyTo ($stream )
1004+ $entryStream = $entry.Open ()
1005+ try {
1006+ $entryStream.CopyTo ($stream )
1007+ }
1008+ finally {
1009+ $entryStream.Dispose ()
1010+ }
10061011 }
10071012 finally {
1008- $entryStream .Dispose ()
1013+ $stream .Dispose ()
10091014 }
10101015 }
1011- finally {
1012- $stream.Dispose ()
1013- }
10141016 }
1017+ Write-Progress - Activity " Extracting Python" - Completed - Id 1
1018+ }
1019+ finally {
1020+ $zip.Dispose ()
10151021 }
1016- Write-Progress - Activity " Extracting Python" - Completed - Id 1
10171022 }
1018- finally {
1019- $zip.Dispose ()
1023+ catch {
1024+ Write-Host " [错误详情] $_ " - ForegroundColor Red
1025+ Write-Host " [错误位置] $ ( $_.ScriptStackTrace ) " - ForegroundColor Red
1026+ exit 1
10201027 }
10211028
10221029 # Cleanup archive
0 commit comments