116 lines
4.0 KiB
PowerShell
116 lines
4.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Déploie l'extension « Boîte à créneaux » dans Inkscape.
|
|
|
|
.DESCRIPTION
|
|
Copie box_maker.inx, box_maker.py, box_core.py et images 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 : boxMaker
|
|
|
|
.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 'ma-boite'
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $ExtensionsDir = (Join-Path $env:APPDATA 'inkscape\extensions'),
|
|
[string] $FolderName = 'boxMaker',
|
|
[switch] $Uninstall,
|
|
[switch] $Force
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$files = @('box_maker.inx', 'box_maker.py', 'box_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"
|
|
}
|
|
|
|
# Schéma affiché dans l'onglet « Schéma » de la boîte de dialogue
|
|
$images = Join-Path $source 'images'
|
|
if (Test-Path -LiteralPath $images) {
|
|
Copy-Item -LiteralPath $images -Destination $destination -Recurse -Force
|
|
Write-Host " copié images\"
|
|
}
|
|
|
|
# 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 > AlexDesign > Boîte à créneaux..."
|