$ErrorActionPreference = "Stop" Write-Host "" Write-Host "=== YouTube Personal - Memoire Export / Import V1 ===" -ForegroundColor Cyan Write-Host "Projet : $PWD" Write-Host "" if (-not (Test-Path ".\pubspec.yaml")) { throw "pubspec.yaml introuvable. Lance ce script depuis la racine du projet Flutter." } $settingsPath = ".\lib\screens\settings_page.dart" if (-not (Test-Path $settingsPath)) { throw "lib/screens/settings_page.dart introuvable." } $backupPath = "$settingsPath.before_memory_v1" if (-not (Test-Path $backupPath)) { Copy-Item $settingsPath $backupPath Write-Host "[OK] Sauvegarde settings_page : $backupPath" -ForegroundColor Green } else { Write-Host "[INFO] Sauvegarde settings_page deja presente." -ForegroundColor DarkGray } Write-Host "[1/4] Ajout de file_picker..." -ForegroundColor Yellow flutter pub add "file_picker:^11.0.3" if ($LASTEXITCODE -ne 0) { throw "flutter pub add file_picker a echoue." } Write-Host "[2/4] Integration dans Reglages..." -ForegroundColor Yellow $content = Get-Content $settingsPath -Raw $importLine = "import '../widgets/memory_transfer_settings.dart';" if ($content -notmatch [regex]::Escape($importLine)) { $anchorImport = "import '../services/preferred_language_service.dart';" if ($content.Contains($anchorImport)) { $content = $content.Replace( $anchorImport, "$anchorImport`r`n$importLine" ) } else { $firstFlutterImport = "import 'package:flutter/material.dart';" if (-not $content.Contains($firstFlutterImport)) { throw "Impossible de trouver un point d'insertion pour l'import. Le fichier n'a pas ete modifie." } $content = $content.Replace( $firstFlutterImport, "$firstFlutterImport`r`n`r`n$importLine" ) } Write-Host "[OK] Import MemoryTransferSettings ajoute." -ForegroundColor Green } else { Write-Host "[OK] Import deja present." -ForegroundColor Green } if ($content -notmatch "const MemoryTransferSettings\(\)") { $marker = @" SizedBox(height: 14), _SettingsSection( title: 'Navigation', "@ $replacement = @" SizedBox(height: 14), const MemoryTransferSettings(), SizedBox(height: 14), _SettingsSection( title: 'Navigation', "@ if (-not $content.Contains($marker)) { # Variante CRLF normalisee par Get-Content -Raw / environnements differents. $regex = "(?ms)(\s*SizedBox\(height:\s*14\),\s*)(_SettingsSection\(\s*title:\s*'Navigation',)" if ($content -notmatch $regex) { throw "Section Navigation introuvable. Restauration du fichier d'origine." } $content = [regex]::Replace( $content, $regex, "`r`n SizedBox(height: 14),`r`n const MemoryTransferSettings(),`r`n SizedBox(height: 14),`r`n `$2", 1 ) } else { $content = $content.Replace($marker, $replacement) } Write-Host "[OK] Bloc Memoire ajoute dans Reglages." -ForegroundColor Green } else { Write-Host "[OK] Bloc Memoire deja present." -ForegroundColor Green } Set-Content -Path $settingsPath -Value $content -Encoding UTF8 Write-Host "[3/4] Formatage Dart..." -ForegroundColor Yellow dart format ".\lib\services\memory_backup_service.dart" ".\lib\widgets\memory_transfer_settings.dart" $settingsPath if ($LASTEXITCODE -ne 0) { throw "dart format a echoue." } Write-Host "[4/4] Dependances..." -ForegroundColor Yellow flutter pub get if ($LASTEXITCODE -ne 0) { throw "flutter pub get a echoue." } Write-Host "" Write-Host "[OK] Memoire Export / Import V1 installee." -ForegroundColor Green Write-Host "" Write-Host "Test Windows : flutter run -d windows" Write-Host "Test Android : flutter run -d " Write-Host ""