$Script:DIR_ROOT = 'c:\Development\PyCharm\Paths\JB' $Script:NeedModules = @( @{ Name = '7Zip4Powershell' version = '2.12.0' FindStr = '7Zip' }, @{ Name = 'Microsoft.WinGet.Client' version = '1.29.280' FindStr = 'winget' } ) $Script:NeedSoft = @( @{ Name = '7-zip' ExeName = '7z.exe' WingetId = "7zip.7zip" Paths = @("$Env:ProgramFiles\*","${Env:ProgramFiles(x86)}\*") ExePath = '' } @{ Name = 'Aria' ExeName = 'aria2c.exe' WingetId = "aria2.aria2" Paths = @("$Env:ProgramFiles\*","${Env:ProgramFiles(x86)}\*") ExePath = '' } ) function Find-InstalledSoft { param( [Parameter(Mandatory)] [PsCustomObject]$Soft ) [PsCustomObject]$Result = @{ Code = -1 Msg = "Не удалось найти/установить $($Soft.Name)" OutPut = @() } $WingetId = $($Soft.WingetId) if ($WingetId) { Write-Host "Запрашиваю $($Soft.Name) по WingetId: " -NoNewline -ForegroundColor Gray Write-Host "$WingetId ..." -ForegroundColor Cyan $IsInstalleg = Get-WinGetPackage -Id $WingetId if (!($IsInstalleg)) { Write-Host "По WingetId: " -NoNewline -ForegroundColor Gray Write-Host "$WingetId " -NoNewline -ForegroundColor Cyan Write-Host "нет установленного" -ForegroundColor Red Write-Host "Ищу в сети по WingetId: " -NoNewline -ForegroundColor Gray Write-Host "$WingetId ..." -ForegroundColor Cyan $IsFind = Find-WinGetPackage -Id aria2.aria2 | Select-Object -Property * -First 1 if ($IsFind) { Write-Host "По WingetId: " -NoNewline -ForegroundColor Gray Write-Host "$WingetId " -NoNewline -ForegroundColor Cyan Write-Host "найдено: "-ForegroundColor Cyan Write-Host "Имя: " -NoNewline -ForegroundColor Gray Write-Host "$($IsFind.Name)" -ForegroundColor Green Write-Host "Версия: " -NoNewline -ForegroundColor Gray Write-Host "$($IsFind.Version)" -ForegroundColor Green Write-Host "Источник: " -NoNewline -ForegroundColor Gray Write-Host "$($IsFind.Source)" -ForegroundColor Green Write-Host "Устанавливаю"-ForegroundColor Cyan Install-WinGetPackage -Id $WingetId -Force Start-Sleep -Seconds 4 $IsInstalleg = Get-WinGetPackage -Id $WingetId if (!($IsInstalleg)) { Write-Host "Почему-то $($Soft.Name) не установилось!" -ForegroundColor Red Start-Sleep -Seconds 10 } else { [PsCustomObject]$Result = @{ Code = 0 Msg = "Софт $($Soft.Name) установлен" OutPut = @() } } } } else { Write-Host "Софт: " -NoNewline -ForegroundColor Gray Write-Host " $($SOFT.Name)" -NoNewline -ForegroundColor Cyan Write-Host " установлен!" -ForegroundColor Green [PsCustomObject]$Result = @{ Code = 0 Msg = "Софт $($Soft.Name) установлен" OutPut = @() } } } else { foreach ($Path in $Soft.Paths) { Write-Host "Ищу $( $SOFT.Name ) в " -ForegroundColor Cyan $SOFT.ExePath = Get-ChildItem -Path "$( $Path )" -Recurse -Filter "$( $Soft.ExeName )" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName -First 1 if ($SOFT.ExePath -and (Test-Path $( $SOFT.ExePath ))) { Write-Host "Софт: " -ForegroundColor Gray -NoNewline Write-Host "$( $SOFT.Name ) " -ForegroundColor Cyan -NoNewline Write-Host "найден: " -ForegroundColor Green -NoNewline Write-Host "$( $SOFT.ExePath )" -ForegroundColor Cyan break } } } return $RESULT } function Find-InstalledModule { param( [Parameter(Mandatory)] [PsCustomObject]$Module ) Write-Host "Функция: " -ForegroundColor Gray -NoNewline Write-Host "Find-InstalledModule" -ForegroundColor Cyan Write-Host "Модуль: " -ForegroundColor Gray -NoNewline Write-Host "$($Module.Name)" -ForegroundColor Cyan [PsCustomObject]$Result = @{ Code = -1 Msg = "Не удалось установить модуль $($Module.Name)" OutPut = @() } try { Write-Host "Запрашиваю модуль $( $Module.Name ) версии $( $Module.Version ) ..." -ForegroundColor Cyan $IsInstalled = Get-Module -ListAvailable | Where-Object { $_ -match $( $Module.Name ) } | Select-Object -First 1 # $IsInstalled if (!($IsInstalled)) { Write-Host "Модуль $( $Module.Name ) версии $( $Module.Version ) не установлен, ищу..." -ForegroundColor Yellow $IsFind = Find-Module $( $Module.Name ) -MinimumVersion $( $Module.Version ) | Select-Object -First 1 # $IsInstalled if (!($IsFind)) { [PsCustomObject]$Result = @{ Code = -1 Msg = "Не удалось найти модуль $($Module.Name)" OutPut = @() } return $Result } else { Write-Host "Модуль $( $Module.Name ) версии $( $Module.Version ) найден, устанавливаю..." -ForegroundColor Yellow # Install-Module -Name $( $Module.Name ) -MinimumVersion $( $Module.Version ) -Force -AllowClobber -AcceptLicense -Verbose Install-Module -Name $( $Module.Name ) -MinimumVersion $( $Module.Version ) -Force -AllowClobber -Verbose Write-Host "Модуль $( $Module.Name ) версии $( $Module.Version ) найден, импортирую..." -ForegroundColor Yellow Import-Module -Name $( $Module.Name ) -Force -DisableNameChecking -Verbose $IsInstalled = Get-Module -ListAvailable | Where-Object { $_ -match $( $Module.Name ) } | Select-Object -First 1 if (!($IsInstalled)) { [PsCustomObject]$Result = @{ Code = -1 Msg = "Модуль $($Module.Name) почему-то не установился" OutPut = @() } return $Result } else { Write-Host "Модуль $( $Module.Name ) версии $( $Module.Version ) успешно установлен..." -ForegroundColor Green $Result = @{ code = 0 Msg = "Модуль $( $Module.Name ) версии $( $Module.Version ) успешно установлен..." } } } } else { #Write-Host "" -ForegroundColor Green [PsCustomObject]$Result = @{ Code = 0 Msg = "Модуль $( $Module.Name ) версии $( $Module.Version ) найден!" OutPut = @() } } return $Result } catch { [PsCustomObject]$Result = @{ Code = -1 Msg = "Ошибка: $_" OutPut = @() } return $Result } } function Initialize-Dependencies { [PsCustomObject]$Result = @{ Code = 0 Msg = 'Ok' OutPut = @() } try { foreach ($Module in $Script:NeedModules) { $Result = Find-InstalledModule $Module $Result Write-Host "$($Module.Name): " -ForegroundColor Cyan $FPROBEL = " " * 9 Write-Host "$FPROBEL `$Result.Code: " -NoNewline -ForegroundColor Gray Write-Host "$($Result.Code)" -ForegroundColor Cyan Write-Host "$FPROBEL `$Result.Msg: " -NoNewline -ForegroundColor Gray Write-Host "$($Result.Msg)" -ForegroundColor Cyan if ( $($Result.Code) -ne 0 ) { return $Result } } foreach ($SOFT in $Script:NeedSoft) { $Result = Find-InstalledSoft $SOFT if ( $($Result.Code) -ne 0 ) { return $Result } } return $Result } catch { [PsCustomObject]$Result = @{ Code = -1 Msg = "Ошибка: $_" OutPut = @() } return $Result } } function Invoke-DownFile { param( [string]$Url, [String]$Dst ) [PsCustomObject]$Result = @{ Code = 0 Msg = 'Ok' OutPut = @() } try { Write-Host "`$URL = '" -NoNewline -ForegroundColor Gray Write-Host "$Url" -NoNewline -ForegroundColor Cyan Write-Host "'" -ForegroundColor Gray Write-Host "`$DST = '" -NoNewline -ForegroundColor Gray Write-Host "$Dst" -NoNewline -ForegroundColor Cyan Write-Host "'" -ForegroundColor Gray #return if (!(Test-Path "$Dst")) { New-Item -Path "$Dst" -ItemType Directory -Force } $FDST_FILE_NAME = Split-Path -Path $Url -Leaf $FDST_FILE_PATH = Join-Path -Path "$Dst" -ChildPath "$FDST_FILE_NAME" if (Test-Path "$FDST_FILE_PATH") { Write-Host "Удаляю файл '" -NoNewline -ForegroundColor Yellow Write-Host "$FDST_FILE_PATH" -NoNewline -ForegroundColor Cyan Write-Host "'" -ForegroundColor Yellow Remove-Item -Path "$FDST_FILE_PATH" -Force } #$URL = "https://gper.ru/soft/Development/PyCharm/Paths/$FDST_FILE_NAME" Write-Host "Запрашиваю: " -NoNewline -ForegroundColor Gray Write-Host "$URL" -ForegroundColor Cyan $FCOLOR = 'Green' $response = Invoke-WebRequest -Uri "$URL" -Method Head Write-Host "StatusCode: " -NoNewline -ForegroundColor Gray Write-Host "$($response.StatusCode)" -ForegroundColor Cyan #Start-Sleep -Seconds 5 if ($($response.StatusCode) -ne 200) { Write-Host "Код не 200" -ForegroundColor Red Write-Host "$($response.StatusCode) - $($response.StatusDescription) : " -ForegroundColor $FCOLOR -NoNewline Write-Host "$URL" -ForegroundColor Gray $Result = @{ Code = $rr.StatusCode Msg = $rr.StatusDescription OutPut = @() } return $Result } #return $Result if ($response.Headers.ContainsKey('Content-Length')) { # Берем первый элемент массива [0] и преобразуем в число if ($($PSVersionTable.PSVersion.Major) -eq 7) { [long]$bytes = $response.Headers['Content-Length'][0] } else { [long]$bytes = $response.Headers['Content-Length'] } if ($bytes -ge 1GB) { $readableSize = "{0:N2} GB" -f ($bytes / 1GB) } elseif ($bytes -ge 1MB) { $readableSize = "{0:N2} MB" -f ($bytes / 1MB) } else { $readableSize = "{0:N2} KB" -f ($bytes / 1KB) } Write-Host "Размер файла: " -NoNewline -ForegroundColor Gray; ` Write-Host "$readableSize" -ForegroundColor Cyan } else { Write-Host "Заголовок Content-Length не найден." -ForegroundColor Yellow } Write-Host "Качаю: " -NoNewline -ForegroundColor Gray Write-Host "$URL" -ForegroundColor Cyan #Invoke-WebRequest -Uri "$URL" -OutFile "$FDST_FILE_PATH" #$FCMD = 'aria2c -d "C:\temp" -o "pycharm-2026.2.exe" -s 16 -x 16 --file-allocation=falloc "https://gper.ru/soft/Development/PyCharm/pycharm-2026.2.exe"' $FCMD = "aria2c -d `"$Dst`" -o `"$FDST_FILE_NAME`" -s 16 -x 16 --file-allocation=falloc `"$URL`"" Start-Process pwsh -ArgumentList "-command `"$FCMD; `` read-host `"Нажми Enter`" `"" -Wait -UseNewEnvironment if (!(Test-Path "$FDST_FILE_PATH")) { $Result = @{ Code = -1 Msg = "Не файла: $FDST_FILE_PATH" OutPut = @() } return $Result } Write-Host "Файл: " -NoNewline -ForegroundColor Gray Write-Host "$FDST_FILE_PATH " -NoNewline -ForegroundColor Cyan Write-Host "На месте" -ForegroundColor Green } catch { $Result = @{ Code = -1 Msg = "Ошибка: $_" OutPut = @() } Write-Host "Ошибка: $_" -ForegroundColor Red return $Result } } function Main { Clear-Host # Invoke-Pester -Path "C:\Development\0020-Powershell\Pycharm\pycharm-build.ps1" $RESULT = Initialize-Dependencies ## $RESULT if ( $($RESULT.Code) -ne 0 ) { $FMSG = "$($RESULT.Code) $($RESULT.Msg)" Write-Host "$FMSG" -ForegroundColor Red return } $URL = "https://gper.ru/soft/Development/PyCharm/pycharm-2026.2.exe" $DST = "C:\temp" $RESULT = Invoke-DownFile -Url "$URL" -Dst "$DST" if ( ($RESULT) -and ($($RESULT.Code) -ne 0) ) { $FMSG = "$($RESULT.Code) $($RESULT.Msg)" Write-Host "$FMSG" -ForegroundColor Red return } $URL = "https://gper.ru/soft/Development/PyCharm/Paths/PyCarm_path_2026.2.7z" $DST = "C:\temp" $RESULT = Invoke-DownFile -Url "$URL" -Dst "$DST" #$RESULT if ( $($RESULT.Code) -ne 0 ) { $FMSG = "$($RESULT.Code) $($RESULT.Msg)" Write-Host "$FMSG" -ForegroundColor Red return } Write-Host "Конец" -ForegroundColor Magenta $FRAVNO = "=" * 50 Write-Host $FRAVNO -ForegroundColor Magenta } Main