Files
voice_copy/voice-changer/tests/test_admin_root.py
EJClaw c24cd1f9c0 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>
2026-11-11 22:09:39 +09:00

28 lines
1.0 KiB
Python

"""관리자 권한으로 도는 부분(apo\\ · mic-apo.ps1)을 설치 프로그램이 둔 Program Files\\VoiceChanger 에서 찾는지."""
import os
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "app"))
import common # noqa: E402
class AdminRootTest(unittest.TestCase):
def test_installed_uses_program_files(self):
with tempfile.TemporaryDirectory() as pf:
(Path(pf) / "VoiceChanger" / "scripts").mkdir(parents=True)
(Path(pf) / "VoiceChanger" / "scripts" / "mic-apo.ps1").write_text("x")
with mock.patch.dict(os.environ, {"ProgramW6432": pf}):
self.assertEqual(common.admin_root(), Path(pf) / "VoiceChanger")
def test_zip_layout_uses_app_folder(self):
with tempfile.TemporaryDirectory() as pf, mock.patch.dict(os.environ, {"ProgramW6432": pf}):
self.assertEqual(common.admin_root(), common.ROOT)
if __name__ == "__main__":
unittest.main()