[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$ArchivePath, [Parameter(Mandatory = $true)] [string]$DestinationPath, [ValidateRange(0, 100)] [int]$SafetyPercent = 10 ) $ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.IO.Compression.FileSystem if (-not (Test-Path -LiteralPath $ArchivePath -PathType Leaf)) { throw "Архив не найден: $ArchivePath" } $archiveFull = (Resolve-Path -LiteralPath $ArchivePath).Path $destFull = [IO.Path]::GetFullPath($DestinationPath) $zip = [IO.Compression.ZipFile]::OpenRead($archiveFull) try { $required = [long]0 $files = 0 foreach ($entry in $zip.Entries) { if ($entry.Name -eq '') { continue } $required += $entry.Length $files++ } } finally { $zip.Dispose() } $probe = $destFull while (-not (Test-Path -LiteralPath $probe)) { $parent = Split-Path -Parent $probe if ([string]::IsNullOrEmpty($parent)) { break } $probe = $parent } $root = [IO.Path]::GetPathRoot($probe) if ([string]::IsNullOrEmpty($root)) { throw "Не удалось определить диск для $destFull" } $drive = [System.IO.DriveInfo]::new($root) $free = [long]$drive.AvailableFreeSpace $needed = [long][math]::Ceiling($required * (1 + $SafetyPercent / 100.0)) "Файлов в архиве: $files" "Нужно места: $([math]::Round($needed / 1GB, 2)) ГБ, свободно: $([math]::Round($free / 1GB, 2)) ГБ" if ($free -lt $needed) { $missing = $needed - $free "Не хватает: $([math]::Round($missing / 1GB, 2)) ГБ" exit 1 } "Места достаточно." exit 0