572 views +0 -0

Download en Extract RDM Portable

$ErrorActionPreference = 'Stop'
$ProgressPreference    = 'SilentlyContinue'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$Destination   = Join-Path $env:USERPROFILE 'Downloads'
$ExtractFolder = Join-Path $Destination 'Devolutions.RemoteDesktopManager.Portable'
$7zip          = 'C:\Program Files\7-Zip\7z.exe'
$Arch          = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'x64' }
$PF            = if ($env:ProgramW6432) { $env:ProgramW6432 } else { $env:ProgramFiles }

New-Item -ItemType Directory -Path $Destination, $ExtractFolder -Force | Out-Null

# ---------- RDM portable ----------
$product = (Invoke-RestMethod 'https://devolutions.net/productinfo.json').RDMWindows.Current
$version = $product.Version
$file    = $product.Files | Where-Object { $_.Type -eq '7z' -and $_.Arch -eq $Arch } | Select-Object -First 1
if (-not $file) { throw "Geen 7z-build gevonden voor $Arch." }

$exe = Get-ChildItem $ExtractFolder -Filter 'RemoteDesktopManager*.exe' -ErrorAction SilentlyContinue |
       Select-Object -First 1
$current = if ($exe) { try { [version]$exe.VersionInfo.FileVersion } catch { $null } } else { $null }

if ($current -and $current -ge [version]$version) {
    Write-Host "RDM portable is al up-to-date ($current)."
} else {
    Get-Process -Name 'RemoteDesktopManager', 'RemoteDesktopManager_x64' -ErrorAction SilentlyContinue |
        ForEach-Object {
            Write-Host "RDM afsluiten (PID $($_.Id))..."
            $null = $_.CloseMainWindow()
            if (-not $_.WaitForExit(10000)) { $_.Kill(); $null = $_.WaitForExit(5000) }
        }

    if (-not (Test-Path $7zip)) { throw "7-Zip niet gevonden op $7zip" }

    $outFile = Join-Path $Destination ([IO.Path]::GetFileName($file.Url))
    Write-Host "Downloaden RDM $version ($Arch)..."
    Invoke-WebRequest -Uri $file.Url -OutFile $outFile -UseBasicParsing

    if ($file.Hash) {
        $hash = (Get-FileHash $outFile -Algorithm SHA256).Hash
        if ($hash -ne $file.Hash) { throw "SHA256 mismatch op $outFile (verwacht $($file.Hash), kreeg $hash)" }
        Write-Host "Hash geverifieerd."
    }

    Write-Host "Uitpakken naar: $ExtractFolder"
    & $7zip x $outFile "-o$ExtractFolder" -aoa -y | Out-Null
    if ($LASTEXITCODE -ne 0) { throw "7-Zip exitcode $LASTEXITCODE" }
    Remove-Item $outFile -Force
    Write-Host "Klaar. RDM $version portable staat in: $ExtractFolder"
}

# ---------- .NET Desktop Runtime 10 ----------
Write-Host ""
Write-Host "Controleren .NET Desktop Runtime 10..."
$index    = Invoke-RestMethod 'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json'
$channel  = $index.'releases-index' | Where-Object { $_.'channel-version' -eq '10.0' }
if (-not $channel) { throw "Kanaal 10.0 niet gevonden in releases-index.json" }
$latest   = $channel.'latest-runtime'
$latestV  = [version](($latest -split '-')[0])

$shared    = Join-Path $PF 'dotnet\shared\Microsoft.WindowsDesktop.App'
$installed = if (Test-Path $shared) {
    Get-ChildItem $shared -Directory |
        Where-Object { $_.Name -like '10.*' } |
        ForEach-Object { try { [version](($_.Name -split '-')[0]) } catch { } } |
        Sort-Object | Select-Object -Last 1
}

if ($installed -and $installed -ge $latestV) {
    Write-Host ".NET Desktop Runtime 10 is up-to-date ($installed)."
} else {
    if ($installed) { Write-Host "Geinstalleerd: $installed, nieuwer beschikbaar: $latest" }
    else            { Write-Host ".NET Desktop Runtime 10 niet gevonden. Installeren van $latest..." }

    $installerUrl  = "https://builds.dotnet.microsoft.com/dotnet/WindowsDesktop/$latest/windowsdesktop-runtime-$latest-win-$Arch.exe"
    $installerFile = Join-Path $Destination "windowsdesktop-runtime-$latest-win-$Arch.exe"

    Write-Host "Downloaden .NET Desktop Runtime $latest..."
    Invoke-WebRequest -Uri $installerUrl -OutFile $installerFile -UseBasicParsing

    Write-Host "Installeren..."
    $proc = Start-Process -FilePath $installerFile -ArgumentList '/install', '/quiet', '/norestart' -Wait -PassThru
    switch ($proc.ExitCode) {
        0       { Write-Host ".NET Desktop Runtime $latest geinstalleerd." }
        3010    { Write-Host ".NET Desktop Runtime $latest geinstalleerd. Reboot vereist." }
        default { Write-Warning "Installer exitcode $($proc.ExitCode)." }
    }
    Remove-Item $installerFile -Force -ErrorAction SilentlyContinue
}