[CmdletBinding()] param() $ErrorActionPreference = "Stop" $source = $PSScriptRoot $target = Join-Path $env:APPDATA "Zed" $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $backup = Join-Path $target "backups\portable-install-$timestamp" $utf8 = New-Object System.Text.UTF8Encoding($false) New-Item -ItemType Directory -Force -Path $target, $backup, (Join-Path $target "scripts") | Out-Null foreach ($name in @("settings.json", "keymap.json", "tasks.json")) { $existing = Join-Path $target $name if (Test-Path -LiteralPath $existing) { Copy-Item -LiteralPath $existing -Destination (Join-Path $backup $name) } } Copy-Item -LiteralPath (Join-Path $source "settings.json") -Destination (Join-Path $target "settings.json") -Force Copy-Item -LiteralPath (Join-Path $source "keymap.json") -Destination (Join-Path $target "keymap.json") -Force Copy-Item -LiteralPath (Join-Path $source "scripts\toggle-file-scan-exclusions.mjs") -Destination (Join-Path $target "scripts\toggle-file-scan-exclusions.mjs") -Force Copy-Item -LiteralPath (Join-Path $source "scripts\file-exclusions.json") -Destination (Join-Path $target "scripts\file-exclusions.json") -Force Copy-Item -LiteralPath (Join-Path $source "scripts\zed-settings-sync.mjs") -Destination (Join-Path $target "scripts\zed-settings-sync.mjs") -Force $syncConfig = Join-Path $target "scripts\settings-sync.json" if (-not (Test-Path -LiteralPath $syncConfig)) { Copy-Item -LiteralPath (Join-Path $source "scripts\settings-sync.json") -Destination $syncConfig } else { $existingState = Get-Content -LiteralPath $syncConfig -Raw | ConvertFrom-Json $migratedState = [ordered]@{ gist_id = if ($existingState.gist_id -is [string]) { $existingState.gist_id } else { "" } last_synced_hash = if ($existingState.last_synced_hash -is [string]) { $existingState.last_synced_hash } else { "" } auto_sync = $existingState.auto_sync -eq $true interval_minutes = if ($existingState.interval_minutes -is [int] -and $existingState.interval_minutes -ge 5) { $existingState.interval_minutes } else { 15 } last_run_at = if ($existingState.last_run_at -is [string]) { $existingState.last_run_at } else { "" } last_result = if ($existingState.last_result -is [string]) { $existingState.last_result } else { "" } } | ConvertTo-Json [IO.File]::WriteAllText($syncConfig, "$migratedState`n", $utf8) } $toggleScriptPath = (Join-Path $target "scripts\toggle-file-scan-exclusions.mjs").Replace("\", "/") $syncScriptPath = (Join-Path $target "scripts\zed-settings-sync.mjs").Replace("\", "/") $tasks = [IO.File]::ReadAllText((Join-Path $source "tasks.json")) $tasks = $tasks.Replace("__TOGGLE_SCRIPT__", $toggleScriptPath) $tasks = $tasks.Replace("__SYNC_SCRIPT__", $syncScriptPath) [IO.File]::WriteAllText((Join-Path $target "tasks.json"), $tasks, $utf8) Write-Host "Installed Zed configuration to $target" Write-Host "Previous configuration backed up to $backup"