- installer: lock the install folder (admins/SYSTEM full, Users read) and grant Users modify only on data dirs (models/training/datasets/config/cache/env/engine/tools); download the engine as the original (non-elevated) user; refuse non-empty folders; uninstall deletes only app-managed dirs - mic-apo.ps1: backup/list/log moved to admin-only apo\; register SFX for DEFAULT, COMMUNICATIONS, SPEECH and MEDIA when the endpoint has no mode list; admin TEMP for Add-Type; run log + trap - app: '마이크 다시 연결' launches one elevated PowerShell via ShellExecuteExW(runas) with double-quoted -File args and waits for its exit code; shows apo\mic-apo.log on failure - tests: reconnect argument splitting (Korean/space/quote/drive root) Verified on the Windows 11 VM: basic-user token gets ERROR_ACCESS_DENIED on scripts/apo/exe/ uninstall/app and write access only on data dirs; Communications-category capture receives the converted signal (440 Hz); reconnect exits 0 from a Korean+space install path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""'마이크 다시 연결' 이 관리자 PowerShell 에 넘기는 인자가 공백 · 한글 · 작은따옴표 · 드라이브 루트 경로에서도 깨지지 않는지."""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path, PureWindowsPath
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "app"))
|
|
os.environ.setdefault("VC_ROOT", tempfile.mkdtemp())
|
|
|
|
try:
|
|
import tkinter # noqa: F401 (voice_changer 가 불러옴)
|
|
except ImportError:
|
|
tkinter = None
|
|
|
|
|
|
def split_windows_args(s: str) -> list:
|
|
"""CommandLineToArgvW 규칙 (백슬래시 + 따옴표 처리 포함)."""
|
|
args, cur, i, quoted, has = [], [], 0, False, False
|
|
while i < len(s):
|
|
c = s[i]
|
|
if c == "\\":
|
|
n = 0
|
|
while i < len(s) and s[i] == "\\":
|
|
n += 1
|
|
i += 1
|
|
if i < len(s) and s[i] == '"':
|
|
cur.append("\\" * (n // 2))
|
|
if n % 2:
|
|
cur.append('"')
|
|
i += 1
|
|
has = True
|
|
continue
|
|
cur.append("\\" * n)
|
|
has = True
|
|
continue
|
|
if c == '"':
|
|
quoted = not quoted
|
|
has = True
|
|
elif c in " \t" and not quoted:
|
|
if has:
|
|
args.append("".join(cur))
|
|
cur, has = [], False
|
|
else:
|
|
cur.append(c)
|
|
has = True
|
|
i += 1
|
|
if has:
|
|
args.append("".join(cur))
|
|
return args
|
|
|
|
|
|
@unittest.skipUnless(tkinter, "tkinter 없음")
|
|
class ReconnectParamsTest(unittest.TestCase):
|
|
def test_korean_space_quote_path(self):
|
|
from voice_changer import reconnect_params
|
|
|
|
root = PureWindowsPath(r"C:\음성 변환기 테스트\it's here")
|
|
args = split_windows_args(reconnect_params(root))
|
|
self.assertEqual(args, ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File",
|
|
r"C:\음성 변환기 테스트\it's here\scripts\mic-apo.ps1", "-Install", "-Root", r"C:\음성 변환기 테스트\it's here"])
|
|
|
|
def test_drive_root(self):
|
|
from voice_changer import reconnect_params
|
|
|
|
args = split_windows_args(reconnect_params(PureWindowsPath("D:\\")))
|
|
self.assertEqual(args[4], r"D:\scripts\mic-apo.ps1")
|
|
self.assertEqual(args[-1], "D:\\.") # 닫는 따옴표가 \ 에 먹히지 않음
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|