<# .SYNOPSIS Déploie l'extension « Remplissage par cercles » dans Inkscape. .DESCRIPTION Copie circle_packing.inx, circle_packing.py et packing_core.py dans un sous-dossier dédié du répertoire des extensions utilisateur d'Inkscape (Inkscape explore récursivement ce répertoire). Refuse de s'exécuter si Inkscape est ouvert : les extensions ne sont chargées qu'au démarrage. .PARAMETER ExtensionsDir Répertoire des extensions Inkscape. Par défaut : %APPDATA%\inkscape\extensions .PARAMETER FolderName Nom du sous-dossier de l'extension. Par défaut : circlePacking .PARAMETER Uninstall Supprime le sous-dossier de l'extension au lieu de le créer. .PARAMETER Force Déploie même si Inkscape est en cours d'exécution. .EXAMPLE .\deploy.ps1 .\deploy.ps1 -Uninstall .\deploy.ps1 -FolderName 'mes-cercles' #> [CmdletBinding()] param( [string] $ExtensionsDir = (Join-Path $env:APPDATA 'inkscape\extensions'), [string] $FolderName = 'circlePacking', [switch] $Uninstall, [switch] $Force ) $ErrorActionPreference = 'Stop' $files = @('circle_packing.inx', 'circle_packing.py', 'packing_core.py') $source = $PSScriptRoot $destination = Join-Path $ExtensionsDir $FolderName # --- Inkscape doit être fermé : les extensions sont lues au démarrage --------- $running = Get-Process -Name 'inkscape' -ErrorAction SilentlyContinue if ($running -and -not $Force) { Write-Error "Inkscape est ouvert. Fermez-le puis relancez le script (ou utilisez -Force)." exit 1 } # --- Désinstallation --------------------------------------------------------- if ($Uninstall) { if (Test-Path -LiteralPath $destination) { Remove-Item -LiteralPath $destination -Recurse -Force Write-Host "Supprimé : $destination" -ForegroundColor Green } else { Write-Host "Rien à supprimer : $destination n'existe pas." -ForegroundColor Yellow } # Fichiers d'une installation « à plat » antérieure, à la racine des extensions foreach ($file in $files) { $legacy = Join-Path $ExtensionsDir $file if (Test-Path -LiteralPath $legacy) { Remove-Item -LiteralPath $legacy -Force Write-Host " supprimé (ancienne installation) $file" } } exit 0 } # --- Vérification des sources ------------------------------------------------ $missing = $files | Where-Object { -not (Test-Path -LiteralPath (Join-Path $source $_)) } if ($missing) { Write-Error "Fichier(s) introuvable(s) dans $source : $($missing -join ', ')" exit 1 } # --- Nettoyage d'une installation « à plat » antérieure ---------------------- foreach ($file in $files) { $legacy = Join-Path $ExtensionsDir $file if (Test-Path -LiteralPath $legacy) { Remove-Item -LiteralPath $legacy -Force Write-Host " nettoyé (ancienne installation à plat) $file" -ForegroundColor Yellow } } # --- Copie ------------------------------------------------------------------- if (-not (Test-Path -LiteralPath $destination)) { New-Item -ItemType Directory -Path $destination -Force | Out-Null Write-Host "Dossier créé : $destination" } foreach ($file in $files) { $from = Join-Path $source $file $to = Join-Path $destination $file $action = if (Test-Path -LiteralPath $to) { 'remplacé' } else { 'copié ' } Copy-Item -LiteralPath $from -Destination $to -Force Write-Host " $action $file" } # Le cache Python d'une version précédente peut masquer les fichiers copiés $pycache = Join-Path $destination '__pycache__' if (Test-Path -LiteralPath $pycache) { Remove-Item -LiteralPath $pycache -Recurse -Force } Write-Host "" Write-Host "Extension déployée dans $destination" -ForegroundColor Green Write-Host "Redémarrez Inkscape, puis : Extensions > Rendu > Remplissage par cercles (circle packing)..."