$ErrorActionPreference = "Stop" Set-StrictMode -Version Latest $ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $ProjectRoot Write-Host "" Write-Host "=== YouTube Personal - Creation installateur Windows V2 ===" -ForegroundColor Cyan Write-Host "Projet : $ProjectRoot" Write-Host "" if (-not (Get-Command flutter -ErrorAction SilentlyContinue)) { throw "Flutter est introuvable dans le PATH. Ouvre le terminal Flutter habituel puis relance ce script." } $PubspecPath = Join-Path $ProjectRoot "pubspec.yaml" if (-not (Test-Path $PubspecPath)) { throw "pubspec.yaml introuvable. Copie ce pack a la racine de ton projet Flutter." } $Pubspec = Get-Content $PubspecPath -Raw $Version = "1.0.0" if ($Pubspec -match '(?m)^version:\s*([^\s+]+)(?:\+\S+)?\s*$') { $Version = $Matches[1].Trim() } Write-Host "[INFO] Version : $Version" -ForegroundColor DarkCyan Write-Host "" Write-Host "[1/3] Compilation Windows Release..." -ForegroundColor Yellow flutter pub get if ($LASTEXITCODE -ne 0) { throw "flutter pub get a echoue." } flutter build windows --release if ($LASTEXITCODE -ne 0) { throw "flutter build windows --release a echoue." } $ReleaseDir = Join-Path $ProjectRoot "build\windows\x64\runner\Release" $ExePath = Join-Path $ReleaseDir "youtube_personal.exe" if (-not (Test-Path $ExePath)) { throw "Executable introuvable apres compilation : $ExePath" } Write-Host "[OK] Application Windows : $ExePath" -ForegroundColor Green function Find-InnoSetupCompiler { # 1. PATH $Cmd = Get-Command ISCC.exe -ErrorAction SilentlyContinue if ($Cmd) { return $Cmd.Source } # 2. Emplacements standards Windows, y compris Program Files (x86) $PF64 = [Environment]::GetFolderPath([Environment+SpecialFolder]::ProgramFiles) $PF86 = [Environment]::GetFolderPath([Environment+SpecialFolder]::ProgramFilesX86) $Candidates = @() if ($PF86) { $Candidates += (Join-Path $PF86 "Inno Setup 6\ISCC.exe") $Candidates += (Join-Path $PF86 "Inno Setup 5\ISCC.exe") } if ($PF64) { $Candidates += (Join-Path $PF64 "Inno Setup 6\ISCC.exe") $Candidates += (Join-Path $PF64 "Inno Setup 5\ISCC.exe") } if ($env:LOCALAPPDATA) { $Candidates += (Join-Path $env:LOCALAPPDATA "Programs\Inno Setup 6\ISCC.exe") $Candidates += (Join-Path $env:LOCALAPPDATA "Programs\Inno Setup 5\ISCC.exe") } foreach ($Path in $Candidates) { if ($Path -and (Test-Path $Path)) { return $Path } } # 3. Registre: installations machine/utilisateur, 32 et 64 bits $RegistryRoots = @( "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" ) foreach ($Root in $RegistryRoots) { try { $Apps = Get-ItemProperty $Root -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -like "Inno Setup*" } foreach ($App in $Apps) { if ($App.InstallLocation) { $Path = Join-Path $App.InstallLocation "ISCC.exe" if (Test-Path $Path) { return $Path } } } } catch { } } # 4. Dernier recours: recherche ciblee dans les dossiers Inno Setup uniquement $Roots = @($PF86, $PF64, (Join-Path $env:LOCALAPPDATA "Programs")) | Where-Object { $_ -and (Test-Path $_) } foreach ($Root in $Roots) { try { $Dirs = Get-ChildItem -Path $Root -Directory -Filter "Inno Setup*" -ErrorAction SilentlyContinue foreach ($Dir in $Dirs) { $Path = Join-Path $Dir.FullName "ISCC.exe" if (Test-Path $Path) { return $Path } } } catch { } } return $null } Write-Host "" Write-Host "[2/3] Detection de Inno Setup..." -ForegroundColor Yellow $ISCC = Find-InnoSetupCompiler if (-not $ISCC) { $Winget = Get-Command winget -ErrorAction SilentlyContinue if ($Winget) { Write-Host "[INFO] ISCC.exe non trouve. Tentative d'installation/reparation avec winget..." # Ne pas considerer 'deja installe / aucune mise a jour' comme une erreur fatale. & winget install --id JRSoftware.InnoSetup -e --accept-package-agreements --accept-source-agreements --silent $WingetExit = $LASTEXITCODE Write-Host "[INFO] winget termine avec le code $WingetExit. Nouvelle detection..." $ISCC = Find-InnoSetupCompiler } } if (-not $ISCC) { Write-Host "" Write-Host "Inno Setup semble installe mais ISCC.exe reste introuvable." -ForegroundColor Red Write-Host "Teste cette commande pour le localiser :" -ForegroundColor Yellow Write-Host 'Get-ChildItem "C:\Program Files*" -Filter ISCC.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName' -ForegroundColor Cyan throw "ISCC.exe introuvable." } Write-Host "[OK] Inno Setup : $ISCC" -ForegroundColor Green Write-Host "" Write-Host "[3/3] Creation du Setup.exe..." -ForegroundColor Yellow $InstallerDir = Join-Path $ProjectRoot "installer\windows" $IssFile = Join-Path $InstallerDir "youtube_personal.iss" $DistDir = Join-Path $ProjectRoot "dist" New-Item -ItemType Directory -Force -Path $DistDir | Out-Null if (-not (Test-Path $IssFile)) { throw "Fichier Inno Setup introuvable : $IssFile" } Push-Location $InstallerDir try { & $ISCC "/DAppVersion=$Version" "/DSourceDir=$ReleaseDir" "/DOutputDir=$DistDir" $IssFile if ($LASTEXITCODE -ne 0) { throw "La compilation Inno Setup a echoue avec le code $LASTEXITCODE." } } finally { Pop-Location } $SetupPath = Join-Path $DistDir "YouTube_Personal_Setup_$Version.exe" if (-not (Test-Path $SetupPath)) { throw "Le Setup n'a pas ete trouve a l'emplacement attendu : $SetupPath" } Write-Host "" Write-Host "=============================================" -ForegroundColor Green Write-Host " INSTALLATEUR WINDOWS CREE AVEC SUCCES" -ForegroundColor Green Write-Host "=============================================" -ForegroundColor Green Write-Host "" Write-Host $SetupPath -ForegroundColor Cyan Write-Host "" Start-Process explorer.exe -ArgumentList $DistDir