-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
193 lines (174 loc) · 10.6 KB
/
setup.ps1
File metadata and controls
193 lines (174 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Setup one-click per Skin Analyzer Pro — Flutter Windows Desktop
Installa i prerequisiti mancanti (VS C++ Build Tools) e prepara il progetto.
.USAGE
Aprire PowerShell come Amministratore e lanciare:
Set-ExecutionPolicy Bypass -Scope Process; .\setup.ps1
#>
$ErrorActionPreference = 'Stop'
$ProjectDir = $PSScriptRoot
# ─────────────────────────────────────────────────────────────────────────────
# Helpers
# ─────────────────────────────────────────────────────────────────────────────
function Write-Step([string]$msg) {
Write-Host "`n==> $msg" -ForegroundColor Cyan
}
function Write-OK([string]$msg) {
Write-Host " [OK] $msg" -ForegroundColor Green
}
function Write-Warn([string]$msg) {
Write-Host " [!] $msg" -ForegroundColor Yellow
}
function Write-Fail([string]$msg) {
Write-Host " [X] $msg" -ForegroundColor Red
}
# ─────────────────────────────────────────────────────────────────────────────
# 1. Flutter
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Verifica Flutter..."
try {
$flutterVer = (flutter --version 2>&1 | Select-Object -First 1).ToString()
Write-OK "Flutter trovato: $flutterVer"
} catch {
Write-Fail "Flutter non trovato. Installalo da https://flutter.dev e aggiungi al PATH."
exit 1
}
# ─────────────────────────────────────────────────────────────────────────────
# 2. Visual Studio — verifica workload C++
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Verifica Visual Studio C++ Build Tools..."
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$msvcOk = $false
if (Test-Path $vsWhere) {
$vsPath = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath 2>$null
if ($vsPath) {
$msvcOk = $true
Write-OK "MSVC v143 trovato in: $vsPath"
}
}
if (-not $msvcOk) {
Write-Warn "MSVC v143 e/o Windows 10 SDK mancanti. Avvio installazione..."
$vsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installer.exe"
if (-not (Test-Path $vsInstallerPath)) {
Write-Fail "Visual Studio Installer non trovato. Installa VS 2022 da https://visualstudio.microsoft.com/"
Write-Warn "Poi seleziona: 'Sviluppo di applicazioni desktop con C++'"
exit 1
}
Write-Host " Installazione componenti in corso (può richiedere qualche minuto)..." -ForegroundColor Yellow
$args = @(
'modify',
'--installPath', (& $vsWhere -latest -products * -property installationPath),
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'--add', 'Microsoft.VisualStudio.Component.Windows10SDK.19041',
'--quiet', '--norestart'
)
$proc = Start-Process -FilePath $vsInstallerPath -ArgumentList $args -Wait -PassThru
if ($proc.ExitCode -eq 0 -or $proc.ExitCode -eq 3010) {
Write-OK "Componenti installati con successo."
if ($proc.ExitCode -eq 3010) {
Write-Warn "RIAVVIO RICHIESTO per completare l'installazione. Riavvia e riesegui questo script."
exit 0
}
} else {
Write-Fail "Installazione fallita (exit code: $($proc.ExitCode)). Installa manualmente."
exit 1
}
}
# ─────────────────────────────────────────────────────────────────────────────
# 3. Crea il progetto Flutter Windows se non esiste già
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Inizializzazione progetto Flutter..."
$windowsDir = Join-Path $ProjectDir "windows"
if (Test-Path $windowsDir) {
Write-OK "Cartella windows/ già presente — skip flutter create."
} else {
Write-Host " Esecuzione 'flutter create --platforms=windows .' ..." -ForegroundColor Yellow
Push-Location $ProjectDir
try {
flutter create --platforms=windows . 2>&1 | Tee-Object -Variable createOut
if ($LASTEXITCODE -ne 0) {
Write-Fail "flutter create fallito. Output: $createOut"
exit 1
}
Write-OK "Progetto Flutter creato."
} finally {
Pop-Location
}
}
# ─────────────────────────────────────────────────────────────────────────────
# 4. Crea cartella assets/ se mancante
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Setup assets..."
$assetsDir = Join-Path $ProjectDir "assets"
if (-not (Test-Path $assetsDir)) {
New-Item -ItemType Directory -Path $assetsDir | Out-Null
}
Write-OK "assets/ presente."
# ─────────────────────────────────────────────────────────────────────────────
# 5. flutter pub get
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Installazione dipendenze Flutter (pub get)..."
Push-Location $ProjectDir
try {
flutter pub get 2>&1 | Tee-Object -Variable pubOut
if ($LASTEXITCODE -ne 0) {
Write-Fail "flutter pub get fallito."
Write-Host $pubOut
exit 1
}
Write-OK "Dipendenze installate."
} finally {
Pop-Location
}
# ─────────────────────────────────────────────────────────────────────────────
# 6. Configurazione Windows manifest (nome app in italiano)
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Aggiornamento runner.rc (nome app)..."
$rcFile = Join-Path $ProjectDir "windows\runner\Runner.rc"
if (Test-Path $rcFile) {
$rc = Get-Content $rcFile -Raw
$rc = $rc -replace 'VALUE "FileDescription",.*', 'VALUE "FileDescription", "Skin Analyzer Pro\0"'
$rc = $rc -replace 'VALUE "ProductName",.*', 'VALUE "ProductName", "Skin Analyzer Pro\0"'
Set-Content $rcFile $rc -Encoding UTF8
Write-OK "Runner.rc aggiornato."
} else {
Write-Warn "Runner.rc non trovato — skip."
}
# ─────────────────────────────────────────────────────────────────────────────
# 7. Build di verifica (optional — commenta se vuoi solo pub get)
# ─────────────────────────────────────────────────────────────────────────────
Write-Step "Build Windows Release..."
Push-Location $ProjectDir
try {
flutter build windows --release 2>&1 | Tee-Object -Variable buildOut
if ($LASTEXITCODE -ne 0) {
Write-Fail "Build fallita. Controlla i messaggi sopra."
Write-Host ($buildOut | Select-Object -Last 30 | Out-String)
exit 1
}
Write-OK "Build completata."
} finally {
Pop-Location
}
# ─────────────────────────────────────────────────────────────────────────────
# Done
# ─────────────────────────────────────────────────────────────────────────────
$exePath = Join-Path $ProjectDir "build\windows\x64\runner\Release\skin_analyzer.exe"
Write-Host "`n" -NoNewline
Write-Host "╔══════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ Skin Analyzer Pro — Setup Completato! ║" -ForegroundColor Green
Write-Host "╠══════════════════════════════════════════════════════╣" -ForegroundColor Green
Write-Host "║ Eseguibile: build\windows\x64\runner\Release\ ║" -ForegroundColor Green
Write-Host "║ ║" -ForegroundColor Green
Write-Host "║ Per avviare in debug: flutter run -d windows ║" -ForegroundColor Green
Write-Host "║ Per rebuild release: flutter build windows ║" -ForegroundColor Green
Write-Host "╚══════════════════════════════════════════════════════╝" -ForegroundColor Green
if (Test-Path $exePath) {
Write-Host "`nVuoi avviare l'app ora? (s/n): " -NoNewline -ForegroundColor Cyan
$ans = Read-Host
if ($ans -eq 's' -or $ans -eq 'S') {
Start-Process $exePath
}
}