108 lines
4.0 KiB
PowerShell
108 lines
4.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Déploie l'extension « Remplissage découpe flexible » dans Inkscape.
|
|
|
|
.DESCRIPTION
|
|
Copie living_hinge.inx, living_hinge.py, living_hinge_core.py, le schéma de l'onglet
|
|
« Help » (images\parameters_en.png) et les traductions
|
|
compilées (locale\<langue>\LC_MESSAGES\livinghinge.mo) 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 : livingHinge
|
|
|
|
.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 'autre-nom'
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[string] $ExtensionsDir = (Join-Path $env:APPDATA 'inkscape\extensions'),
|
|
[string] $FolderName = 'livingHinge',
|
|
[switch] $Uninstall,
|
|
[switch] $Force
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$files = @('living_hinge.inx', 'living_hinge.py', 'living_hinge_core.py', 'images\parameters_en.png')
|
|
$localeDir = 'locale'
|
|
$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
|
|
}
|
|
exit 0
|
|
}
|
|
|
|
# --- Vérification des sources ------------------------------------------------
|
|
$missing = $files | Where-Object { -not (Test-Path -LiteralPath (Join-Path $source $_)) }
|
|
if (-not (Test-Path -LiteralPath (Join-Path $source $localeDir))) {
|
|
$missing = @($missing) + "$localeDir\ (lancer : python i18n.py)"
|
|
}
|
|
if ($missing) {
|
|
Write-Error "Fichier(s) introuvable(s) dans $source : $($missing -join ', ')"
|
|
exit 1
|
|
}
|
|
|
|
# --- 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é ' }
|
|
New-Item -ItemType Directory -Path (Split-Path $to) -Force | Out-Null
|
|
Copy-Item -LiteralPath $from -Destination $to -Force
|
|
Write-Host " $action $file"
|
|
}
|
|
|
|
# Traductions : le dossier est remplacé en entier (langue retirée => supprimée)
|
|
$localeTo = Join-Path $destination $localeDir
|
|
if (Test-Path -LiteralPath $localeTo) {
|
|
Remove-Item -LiteralPath $localeTo -Recurse -Force
|
|
}
|
|
Copy-Item -LiteralPath (Join-Path $source $localeDir) -Destination $localeTo -Recurse
|
|
$languages = Get-ChildItem -LiteralPath $localeTo -Directory | ForEach-Object Name
|
|
Write-Host " copié $localeDir\ ($($languages -join ', '))"
|
|
|
|
# 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 > Remplissage découpe flexible..."
|