Update install-AdHoc-Backup-GUI.ps1

This commit is contained in:
Mattia Tadini 2025-11-11 15:05:20 +00:00
parent 59994b82a6
commit 5ca482aa46

View File

@ -1,16 +1,14 @@
#Requires -Version 5.1 #Requires -Version 5.1
<# <#
Installer AdHoc Backup (GUI) - v1.3.1 Installer AdHoc Backup (GUI) - v1.3.4
- Tab "Configurazione (backup.conf)" con UI dinamica - Tab "Configurazione (backup.conf)" con UI dinamica (checkbox per booleani, textbox per altri valori)
- Eseguibili: C:\polo\scripts\bin\RClone e C:\polo\scripts\bin\7Zip - Struttura: C:\polo\scripts\bin\RClone\ C:\polo\scripts\bin\7Zip\ C:\polo\scripts\bin\conf\
- Config: C:\polo\scripts\bin\conf\backup.conf e C:\polo\scripts\bin\conf\rclone.conf - Config: C:\polo\scripts\bin\conf\backup.conf e C:\polo\scripts\bin\conf\rclone.conf
- Dopo l'estrazione elimina gli ZIP - "Installa": scarica/installa Rclone e **solo 7zr.exe** (nessun alias 7z.exe) nelle cartelle bin\
- Estrattore ZIP robusto (entry-per-entry, overwrite=true) - Dopo estrazione elimina ZIP di Rclone
- Fix Point/Size (helper New-Point/New-Size) - Avvio "Configura rclone" con Start-Process diretto (no cmd.exe)
- Schedulazione via schtasks; -Config punta a bin\conf\backup.conf - Schedulazione giornaliera/settimanale via schtasks; AdHoc-Backup.ps1 avviato con -Config <bin\conf\backup.conf>
- Chiude console aperte (rclone, ecc.) alla chiusura - Chiusura di tutte le console aperte dallinstaller alla chiusura della finestra
- FIX: avvio "Configura rclone" senza cmd.exe (Start-Process diretto su rclone.exe) per evitare l'errore "La sintassi del nome del file..."
- Minor: corretto flag Quiet in attività pianificata (-Quiet)
#> #>
Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Windows.Forms
@ -20,12 +18,8 @@ Add-Type -AssemblyName System.IO.Compression.FileSystem
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
# ------------------------------ HELPERS GRAFICI ------------------------------- # ------------------------------ HELPERS GRAFICI -------------------------------
function New-Point([object]$x,[object]$y) { function New-Point([object]$x,[object]$y) { try { return New-Object System.Drawing.Point ([int]$x), ([int]$y) } catch { return [System.Drawing.Point]::new([int]$x, [int]$y) } }
try { return New-Object System.Drawing.Point ([int]$x), ([int]$y) } catch { return [System.Drawing.Point]::new([int]$x, [int]$y) } function New-Size([object]$w,[object]$h) { try { return New-Object System.Drawing.Size ([int]$w), ([int]$h) } catch { return [System.Drawing.Size]::new([int]$w, [int]$h) } }
}
function New-Size([object]$w,[object]$h) {
try { return New-Object System.Drawing.Size ([int]$w), ([int]$h) } catch { return [System.Drawing.Size]::new([int]$w, [int]$h) }
}
function Set-Loc($ctrl,[object]$x,[object]$y){ $ctrl.Location = New-Point $x $y } function Set-Loc($ctrl,[object]$x,[object]$y){ $ctrl.Location = New-Point $x $y }
function Set-Sz($ctrl,[object]$w,[object]$h){ $ctrl.Size = New-Size $w $h } function Set-Sz($ctrl,[object]$w,[object]$h){ $ctrl.Size = New-Size $w $h }
@ -123,10 +117,8 @@ function Ensure-RcloneExe {
$zip = Join-Path $RcloneDir 'rclone-current-windows-amd64.zip' $zip = Join-Path $RcloneDir 'rclone-current-windows-amd64.zip'
if (Start-Download -Url 'https://downloads.rclone.org/rclone-current-windows-amd64.zip' -Dest $zip) { if (Start-Download -Url 'https://downloads.rclone.org/rclone-current-windows-amd64.zip' -Dest $zip) {
Expand-Zip -ZipPath $zip -DestDir $RcloneDir Expand-Zip -ZipPath $zip -DestDir $RcloneDir
# Trova il vero rclone.exe estratto (cartella rclone-*-windows-amd64\)
$found = Get-ChildItem -LiteralPath $RcloneDir -Recurse -Filter 'rclone.exe' | Select-Object -First 1 $found = Get-ChildItem -LiteralPath $RcloneDir -Recurse -Filter 'rclone.exe' | Select-Object -First 1
if ($found) { Copy-Item -LiteralPath $found.FullName -Destination $exe -Force } if ($found) { Copy-Item -LiteralPath $found.FullName -Destination $exe -Force }
# Pulisci cartella estratta e ZIP
Get-ChildItem -LiteralPath $RcloneDir -Directory | Where-Object { $_.Name -like 'rclone-*' } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue Get-ChildItem -LiteralPath $RcloneDir -Directory | Where-Object { $_.Name -like 'rclone-*' } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue
} }
@ -134,6 +126,21 @@ function Ensure-RcloneExe {
return $exe return $exe
} }
# === SOLO 7zr.exe =============================================================
function Ensure-SevenZipExe {
param([Parameter(Mandatory)][string]$SevenZipDir)
$exe = Join-Path $SevenZipDir '7zr.exe'
if (-not (Test-Path -LiteralPath $exe)) {
$url7zr = 'https://www.7-zip.org/a/7zr.exe'
if (Start-Download -Url $url7zr -Dest $exe) {
Write-Log "Installato 7-Zip minimal: $exe"
} else {
Write-Log "Impossibile installare 7-Zip (7zr.exe)." 'ERR'
}
}
return $exe
}
# ------------------------------ CONF PARSER ----------------------------------- # ------------------------------ CONF PARSER -----------------------------------
$global:ChildPids = New-Object System.Collections.ArrayList $global:ChildPids = New-Object System.Collections.ArrayList
function Track-Child($p){ if ($p -and $p.Id) { [void]$global:ChildPids.Add($p.Id) } } function Track-Child($p){ if ($p -and $p.Id) { [void]$global:ChildPids.Add($p.Id) } }
@ -289,7 +296,7 @@ $btnSaveConf.Add_Click({
} catch { Write-Log "Errore salvataggio backup.conf: $($_.Exception.Message)" 'ERR' } } catch { Write-Log "Errore salvataggio backup.conf: $($_.Exception.Message)" 'ERR' }
}) })
# FIX: avvio rclone.exe diretto (niente cmd.exe) per evitare errori di quoting # Avvio rclone config in console dedicata
$btnRcloneConfig.Add_Click({ $btnRcloneConfig.Add_Click({
try { try {
$layout = Ensure-ToolsLayout -Root $txtInstall.Text $layout = Ensure-ToolsLayout -Root $txtInstall.Text
@ -318,6 +325,12 @@ $btnInstall.Add_Click({
$root = $txtInstall.Text; Ensure-Dir $root $root = $txtInstall.Text; Ensure-Dir $root
$layout = Ensure-ToolsLayout -Root $root $layout = Ensure-ToolsLayout -Root $root
# Scarica/installa Rclone e SOLO 7zr.exe
$rcloneExe = Ensure-RcloneExe -RcloneDir $layout.RClone
if (-not (Test-Path -LiteralPath $rcloneExe)) { Write-Log "ATTENZIONE: rclone.exe non installato." 'WARN' }
$sevenExe = Ensure-SevenZipExe -SevenZipDir $layout.SevenZip
if (-not (Test-Path -LiteralPath $sevenExe)) { Write-Log "ATTENZIONE: 7-Zip (7zr.exe) non installato." 'WARN' }
# Script principale # Script principale
$scriptPath = Join-Path $root 'AdHoc-Backup.ps1' $scriptPath = Join-Path $root 'AdHoc-Backup.ps1'
if (-not (Start-Download -Url $txtScriptUrl.Text -Dest $scriptPath)) { throw "Impossibile scaricare lo script principale." } if (-not (Start-Download -Url $txtScriptUrl.Text -Dest $scriptPath)) { throw "Impossibile scaricare lo script principale." }