Files
voice_copy/voice-changer/installer/deploy.ps1
EJClaw 85f5782876 voice-changer installer: never touch the chosen folder with admin rights (1.0.3)
Review of c24cd1f: with a user-owned parent (Desktop), the user could swap the chosen folder for a junction
to a protected folder after secure-dir Prepare, and the elevated Finish would grant Users modify on the
target's config\ etc. Any elevated path operation on a user-controlled path has this race, so the elevated
installer now only works in Program Files.

- VoiceChanger.iss: {app} is always {commonpf}\VoiceChanger (apo\, scripts\mic-apo.ps1, scripts\deploy.ps1,
  uninstall\, payload\). The user's folder comes from a custom page (/DATADIR=, previous DataDir, or the
  v1.0.x App Path) and is only read for checks. deploy.ps1 runs with ExecAsOriginalUser: copies payload,
  moves data folders of an older install, runs install.ps1. Shortcuts are created after the copy
  (CreateShellLink; [Icons] made empty-target links) and the postinstall launch runs as the original user.
  Uninstall restores the mic settings and removes Program Files only; the user's folder is left (message).
- legacy.ps1 (replaces secure-dir.ps1): for a v1.0.0/1.0.1 folder (admin-locked, uninstall\ inside) deletes the
  old executable parts by name, moves the mic backup to Program Files and renames the folder to <dir>.old,
  only if no non-admin principal can delete/rename the folder or any ancestor (owner + ACL check; ACLs can
  only be changed by admins, so the check stays valid during the operation). Otherwise refuses (exit 20).
- deploy.ps1 (user level): refuses a junction; a v1.0.2 admin-locked folder under a user-owned parent is
  renamed aside by the user and its data folders moved into a fresh folder.
- mic-apo.ps1: back to its pre-c24cd1f logic (no -From); header documents the Program Files root.

Windows 11 VM, Inno 6.7.4, AppVersion 1.0.3:
- J: chosen folder = junction to admin-owned C:\vctarget (config\keep.txt, protected ACL): setup exit 0,
  legacy exit 0, deploy exit 31; target files + SDDL unchanged after setup, after limited-token deploy
  (exit 31), after limited-token write/icacls/rename attempts (all denied), and after uninstall.
- J2: same target with uninstall\unins000.exe: legacy exit 20, setup aborted (exit 7), target unchanged.
- U1: v1.0.1 at C:\VoiceChanger -> 1.0.3 with the default folder: legacy exit 1, backup moved byte-equal,
  models\mine.txt kept, C:\VoiceChanger.old removed, APO from Program Files; uninstall restores FxProperties.
- U2: v1.0.2 on Desktop -> limited-token deploy renamed it aside, moved models, new folder owned by the user;
  1.0.3 setup on it exit 0; uninstall restores FxProperties, folder and models kept.
- D: fresh Desktop install with full engine download: deploy exit 0, admin_root = Program Files,
  audiodg loads the Program Files DLL, APO 440 Hz + Communications PASS, Start menu/desktop shortcuts point
  at <Desktop>\VoiceChanger\VoiceChanger.exe and are removed on uninstall.
- python unittest: 16 run, 2 skipped (tkinter missing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 22:51:52 +09:00

52 lines
2.9 KiB
PowerShell

# 고른 폴더에 앱을 설치한다. 설치 프로그램이 "설치를 시작한 사용자" 권한으로 실행한다 (ExecAsOriginalUser).
# 고른 폴더(바탕 화면 등)는 상위가 사용자 소유일 수 있어서 관리자 권한으로는 건드리지 않는다:
# 관리자 권한으로 경로를 다루는 도중에 폴더를 정션으로 바꿔치면 엉뚱한 곳에 쓰거나 권한을 바꾸게 되기 때문.
# deploy.ps1 -Data <고른 폴더> [-From <이전 버전 폴더>]
# 1. 이전 버전 폴더에서 데이터 폴더(models · config · env 등)를 옮겨 온다
# - v1.0.0 · v1.0.1: 설치 프로그램(legacy.ps1)이 <폴더>.old 로 비켜 두고 -From 으로 알려 줌
# - v1.0.2: 고른 폴더가 관리자 소유로 잠겨 있으면, 상위 폴더가 내 것일 때 이름을 바꿔 비켜 두고 새로 만든다
# 2. Program Files\VoiceChanger\payload 의 앱 파일을 복사한다
# 3. scripts\install.ps1 로 Python · 엔진 · 기본 모델을 받는다
# 종료 코드: 0 성공, 31 고른 폴더가 링크(정션), 32 폴더를 만들거나 복사하지 못함, 그 밖 = install.ps1 실패
param([Parameter(Mandatory)][string]$Data, [string]$From)
$ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [Text.Encoding]::UTF8
$Payload = Join-Path (Split-Path -Parent $PSScriptRoot) 'payload'
$DataDirs = 'models', 'training', 'datasets', 'config', 'cache', 'env', 'engine', 'tools'
$Data = [IO.Path]::GetFullPath($Data).TrimEnd('\')
function Say($m) { Write-Host "[deploy] $m" }
function Is-Link([string]$p) { ([IO.File]::GetAttributes($p) -band [IO.FileAttributes]::ReparsePoint) -ne 0 }
function Can-Write([string]$d) {
$t = Join-Path $d ".vc-write-test-$PID"
try { [IO.File]::WriteAllText($t, ''); Remove-Item -LiteralPath $t -Force; return $true } catch { return $false }
}
try {
if (Test-Path -LiteralPath $Data) {
if (Is-Link $Data) { Say "고른 폴더가 링크(정션)입니다: $Data"; exit 31 }
if (-not (Can-Write $Data)) {
$old = "$Data.old-$(Get-Date -Format yyyyMMddHHmmss)"
Rename-Item -LiteralPath $Data -NewName (Split-Path -Leaf $old)
Say "이전 버전 폴더를 비켜 둠: $old"
$From = $old
}
}
New-Item -ItemType Directory -Force -Path $Data | Out-Null
if ($From -and (Test-Path -LiteralPath $From)) {
foreach ($d in $DataDirs) {
$s = Join-Path $From $d
$t = Join-Path $Data $d
if ((Test-Path -LiteralPath $s) -and -not (Test-Path -LiteralPath $t)) { Move-Item -LiteralPath $s -Destination $t; Say "옮김: $d" }
}
}
} catch {
Say "실패: $($_.Exception.Message)"
exit 32
}
& robocopy $Payload $Data /E /R:1 /W:1 /NFL /NDL /NJH /NJS /NP | Out-Host
if ($LASTEXITCODE -ge 8) { Say "앱 파일을 복사하지 못함 (robocopy $LASTEXITCODE)"; exit 32 }
$global:LASTEXITCODE = 0
& (Join-Path $Data 'scripts\install.ps1')
exit $LASTEXITCODE