$ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot $exe = Get-ChildItem -LiteralPath (Join-Path $root 'runtime') -Filter FreeCAD.exe -Recurse | Where-Object { $_.Directory.Name -eq 'bin' } | Select-Object -First 1 if (-not $exe) { throw 'Сначала выполните scripts/bootstrap.ps1.' } $engineRoot = Split-Path -Parent $exe.DirectoryName $modules = Join-Path $engineRoot 'Mod' if (-not (Test-Path -LiteralPath $modules)) { $modules = Join-Path $exe.DirectoryName 'Mod' } $destination = Join-Path $modules 'QInventor' New-Item -ItemType Directory -Path $destination -Force | Out-Null New-Item -ItemType Directory -Path (Join-Path $root 'data'),(Join-Path $root 'logs'),(Join-Path $root 'artifacts') -Force | Out-Null $source = Join-Path $root 'src\QInventor' $ownedManifest = Join-Path $root 'data\workbench-files.json' $ownedFiles = @(Get-ChildItem -LiteralPath $source -File -Recurse | Where-Object { $_.Extension -ne '.pyc' -and $_.FullName -notmatch '[\\/]__pycache__[\\/]' } | ForEach-Object { $_.FullName.Substring($source.Length + 1) } | Sort-Object) $destinationAbsolute = [IO.Path]::GetFullPath($destination) $destinationPrefix = $destinationAbsolute + [IO.Path]::DirectorySeparatorChar if (Test-Path -LiteralPath $ownedManifest) { $previousOwnedFiles = @(Get-Content -LiteralPath $ownedManifest -Raw | ConvertFrom-Json) foreach ($previous in $previousOwnedFiles) { if ($previous -notin $ownedFiles) { $obsolete = [IO.Path]::GetFullPath((Join-Path $destinationAbsolute $previous)) if (-not $obsolete.StartsWith($destinationPrefix, [StringComparison]::OrdinalIgnoreCase)) { throw 'Недопустимый путь в списке файлов рабочей среды QInventor.' } if ([IO.File]::Exists($obsolete)) { Remove-Item -LiteralPath $obsolete } } } } foreach ($file in $ownedFiles) { $target = Join-Path $destinationAbsolute $file New-Item -ItemType Directory -Path (Split-Path -Parent $target) -Force | Out-Null Copy-Item -LiteralPath (Join-Path $source $file) -Destination $target -Force } # This is our own module only. Avoid stale Python bytecode when two edits have # equal sizes and fall in the same timestamp second; preserve upstream caches. foreach ($cached in Get-ChildItem -LiteralPath $destinationAbsolute -File -Filter '*.pyc' -Recurse) { if (-not $cached.FullName.StartsWith($destinationPrefix, [StringComparison]::OrdinalIgnoreCase)) { throw 'Путь кэша выходит за пределы рабочей среды QInventor.' } Remove-Item -LiteralPath $cached.FullName } ConvertTo-Json -InputObject $ownedFiles | Set-Content -LiteralPath $ownedManifest -Encoding utf8 $relative = $exe.FullName.Substring($root.Length + 1) Set-Content -LiteralPath (Join-Path $root 'data\runtime-path.txt') -Value $relative -Encoding utf8 Write-Host "Рабочая среда QInventor обновлена: $destination"