voice-changer: allow installing under user-owned folders (Desktop); move admin-run parts to Program Files

The installer refused folders whose parent is user-owned (Desktop, Documents) because a user could swap
the whole install folder and get the elevated/audiodg-run parts replaced. Instead of refusing, the parts
that run with admin rights or inside audiodg now live in {commonpf}\VoiceChanger, which only admins can
change; the chosen folder keeps the app, Python, engine, models and data.

- VoiceChanger.iss: SysDir = {commonpf}\VoiceChanger holds apo\ (VoiceChangerAPO.dll), scripts\mic-apo.ps1
  and the uninstaller (UninstallFilesDir). CheckParent removed. Upgrade detection also matches the previous
  install dir from the uninstall registry (PrevAppDir) since uninstall\ is no longer inside the app folder.
  Stop the audio service when either the new or the v1.0.1-layout APO exists. Ask before installing into
  a OneDrive-synced folder.
- secure-dir.ps1: drop CheckParent; Prepare takes -Upgrade.
- mic-apo.ps1: -From <previous app folder> migrates a v1.0.1 apo\ or 21b4278 config\ backup (validated as
  before) into the Program Files apo\, removing the emptied old apo\.
- app: admin_root() finds Program Files\VoiceChanger (falls back to the app folder for the zip layout);
  hooked-mic list, mic-apo log and the reconnect button use it.

Windows 11 VM (Inno 6.7.4 build, AppVersion 1.0.2): v1.0.1 at C:\VoiceChanger -> upgrade: backup moved
byte-equal, APO re-pointed to Program Files, old apo\ scripts\mic-apo.ps1 uninstall\ gone; fresh install to
C:\Users\ci\Desktop\VoiceChanger (owner WIN-CI\ci) with full engine download: exit 0, audiodg loads
C:\Program Files\VoiceChanger\apo\VoiceChangerAPO.dll, 440 Hz APO test + Communications stream PASS;
basic-user token can rename the Desktop folder but every Program Files write/rename is ERROR_ACCESS_DENIED;
reinstall over the same folder keeps user files; uninstall restores FxProperties (only the endpoint
timestamp properties differ, same as v1.0.1) and removes both folders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-11 22:09:39 +09:00
parent 32ad429773
commit c24cd1f9c0
7 changed files with 156 additions and 60 deletions

View File

@@ -1,12 +1,12 @@
# 설치 폴더 보안 (설치 프로그램이 관리자 권한으로 {tmp} 에서 실행). 종료 코드로 결과를 알린다.
# -Mode CheckParent -App <폴더> 가장 가까운 상위 폴더가 드라이브 루트이거나 관리자 · SYSTEM · TrustedInstaller 소유인지
# 0 = 괜찮음, 20 = 일반 사용자 소유 (그 사용자가 설치 폴더를 통째로 바꿔치기할 수 있음)
# -Mode Prepare -App <폴더> 파일을 풀기 전: 폴더를 만들고 소유자를 Administrators 로, 권한을 관리자 · SYSTEM 전체 +
# Users 읽기로 잠근다. 업데이트면 이전 버전이 사용자 쓰기 폴더에 두었던 실행 부분을 지운다.
# (상위 폴더는 일반 사용자 소유여도 된다. 관리자 권한으로 실행되는 APO · mic-apo.ps1 · 제거 프로그램은 설치 폴더가 아니라
# Program Files\VoiceChanger 에 있어서, 사용자가 설치 폴더를 통째로 바꿔쳐도 관리자 권한을 얻지 못한다)
# -Mode Prepare -App <폴더> [-Upgrade] 파일을 풀기 전: 폴더를 만들고 소유자를 Administrators 로, 권한을 관리자 · SYSTEM 전체 +
# Users 읽기로 잠근다. 업데이트(-Upgrade 또는 v1.0.1 까지의 uninstall\ 이 있음)면 이전 버전이 사용자 쓰기 폴더에 두었던 실행 부분을 지운다.
# 10 = 다른 파일이 있는 폴더, 11 = 링크(정션 · 심볼릭 링크)가 있음, 12 = 잠그지 못함
# -Mode Finish -App <폴더> 파일을 푼 뒤: 데이터 폴더에만 Users 수정 권한을 주고, 관리자 권한으로 실행되는 파일이
# 관리자 소유이고 일반 사용자가 쓸 수 없는지 확인한다. 13 = 확인 실패
param([Parameter(Mandatory)][string]$Mode, [Parameter(Mandatory)][string]$App)
param([Parameter(Mandatory)][string]$Mode, [Parameter(Mandatory)][string]$App, [switch]$Upgrade)
$ErrorActionPreference = 'Stop'
$SY = 'S-1-5-18'; $BA = 'S-1-5-32-544'; $BU = 'S-1-5-32-545'
$TI = 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464'
@@ -46,20 +46,9 @@ function Find-Link([string]$dir) {
return $null
}
function Owner-Sid([string]$p) { (Get-Acl -LiteralPath $p).GetOwner($Sid).Value }
if ($Mode -eq 'CheckParent') {
$p = Split-Path -Parent $App
while ($p -and -not (Test-Path -LiteralPath $p)) { $p = Split-Path -Parent $p }
if (-not $p -or $p -eq [IO.Path]::GetPathRoot($p)) { Say "상위: 드라이브 루트"; exit 0 }
$o = Owner-Sid $p
Say "상위: $p 소유자 $o"
if ($o -in @($BA, $SY, $TI)) { exit 0 }
exit 20
}
if ($Mode -eq 'Prepare') {
$upgrade = Test-Path -LiteralPath (Join-Path $App 'uninstall\unins000.exe')
$upgrade = $Upgrade -or (Test-Path -LiteralPath (Join-Path $App 'uninstall\unins000.exe'))
if (Test-Path -LiteralPath $App) {
if (Is-Link $App) { Say "설치 폴더가 링크: $App"; exit 11 }
if (-not $upgrade -and [IO.Directory]::EnumerateFileSystemEntries($App).GetEnumerator().MoveNext()) { exit 10 }