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

@@ -15,6 +15,15 @@ SETTINGS = CONFIG / "settings.json"
CACHE = ROOT / "cache"
def admin_root() -> Path:
"""마이크 모듈(apo\\)과 그것을 붙이는 scripts\\mic-apo.ps1 이 있는 폴더. 관리자 권한으로 실행되는 부분이라
설치 프로그램은 앱 폴더가 아니라 Program Files\\VoiceChanger 에 둔다. 그곳에 없으면(zip 으로 푼 경우) 앱 폴더."""
pf = os.environ.get("ProgramW6432") or os.environ.get("ProgramFiles")
if pf and (Path(pf) / "VoiceChanger" / "scripts" / "mic-apo.ps1").is_file():
return Path(pf) / "VoiceChanger"
return ROOT
def keep_files_in_root():
"""라이브러리가 사용자 폴더(%TEMP% · %USERPROFILE%\\.cache · %APPDATA%)에 쓰는 캐시와 임시 파일을
모두 설치 폴더 안 cache\\ 로 돌린다. 다른 import 보다 먼저 돌아야 해서 이 모듈을 불러올 때 바로 한다."""

View File

@@ -13,7 +13,7 @@ import time
import tkinter as tk
from tkinter import messagebox, ttk
from common import ROOT, SETTINGS, load_json, save_json, use_engine
from common import SETTINGS, admin_root, load_json, save_json, use_engine
from models import GENDERS, auto_pitch, list_models
from record_servers import ServerDialog
@@ -34,7 +34,7 @@ def list_devices():
def hooked_mics() -> list:
"""설치할 때 마이크 모듈을 붙인 마이크들 (scripts/mic-apo.ps1 이 apo\\ 에 남긴 목록)."""
try:
items = json.loads((ROOT / "apo" / "mic-apo.json").read_text(encoding="utf-8-sig"))
items = json.loads((admin_root() / "apo" / "mic-apo.json").read_text(encoding="utf-8-sig"))
except (OSError, ValueError):
return []
items = items if isinstance(items, list) else [items]
@@ -47,7 +47,7 @@ def is_hooked(name: str, hooked: list) -> bool:
def reconnect_params(root=None) -> str:
"""관리자 PowerShell 에 넘길 인자. Windows 경로에는 " 가 들어갈 수 없어서 큰따옴표로만 감싸면 공백 · 한글 경로도 안전하다."""
root = ROOT if root is None else root
root = admin_root() if root is None else root
script, r = str(root / "scripts" / "mic-apo.ps1"), str(root)
if r.endswith("\\"): # "D:\" 처럼 \ 로 끝나면 닫는 따옴표가 이스케이프되므로 "D:\." 로
r += "."
@@ -57,7 +57,7 @@ def reconnect_params(root=None) -> str:
def mic_apo_log_tail(lines: int = 8) -> str:
"""scripts/mic-apo.ps1 이 apo\\mic-apo.log 에 남긴 마지막 기록."""
try:
text = (ROOT / "apo" / "mic-apo.log").read_text(encoding="utf-8-sig", errors="replace")
text = (admin_root() / "apo" / "mic-apo.log").read_text(encoding="utf-8-sig", errors="replace")
except OSError:
return "(기록 없음)"
return "\n".join(text.strip().splitlines()[-lines:])
@@ -83,7 +83,7 @@ def reconnect_mics() -> int:
k32.CloseHandle.argtypes = [wintypes.HANDLE]
sei = SHELLEXECUTEINFOW(cbSize=ctypes.sizeof(SHELLEXECUTEINFOW), fMask=0x40, # SEE_MASK_NOCLOSEPROCESS
lpVerb="runas", lpFile="powershell.exe", lpParameters=reconnect_params(),
lpDirectory=str(ROOT), nShow=0)
lpDirectory=str(admin_root()), nShow=0)
if not shell32.ShellExecuteExW(ctypes.byref(sei)):
return -ctypes.get_last_error()
try: