Files
voice_copy/voice-changer/installer/VoiceChanger.iss
EJClaw c1d9242b81 voice-changer installer 1.0.4: refuse admin-token deploy; do not carry over the v1.0.2 uninstall log
Review/arbiter REVISE on 85f5782:
- If the installer is started elevated ("Run as administrator", admin terminal), ExecAsOriginalUser is
  elevated too, so deploy.ps1 copied into the user's folder and ran its scripts with admin rights.
  deploy.ps1 now checks the real token first (WindowsPrincipal.IsInRole(Administrator)) and exits 33
  before touching any path; the installer explains to start it by double-click. The post-install launch
  only runs when deploy succeeded (Check: DeployDone).
- v1.0.2 and later share AppId and uninstall dir, and the default UninstallLogMode=append kept v1.0.2's
  entries for files in the user's folder, which the elevated uninstaller would delete through a junction.
  UninstallLogMode=overwrite starts a fresh log. Since pre-existing folders are then not recorded as
  created, the uninstaller removes Program Files\VoiceChanger's apo\ scripts\ payload\ itself and launches
  a detached `rmdir` for the then-empty uninstall\ and install folder (Program Files only).

Windows 11 VM, Inno 6.7.4, AppVersion 1.0.4 (final build):
- A: setup started from an elevated process with /DATADIR=<Desktop>\VCA: deploy exit 33, the folder was
  never created, no shortcuts; REFUSED_BEFORE_WRITE PASS.
- L: deploy.ps1 under the logged-on user's limited token (Administrators deny-only) copies the app,
  folder owned by the user.
- C (control): v1.0.2 on Desktop -> v1.0.3, unins000.dat mentions Desktop\VC2; folder swapped for a junction
  to admin-only C:\vctarget, uninstall deletes the target's same-named files (FAIL, the bug).
- B: v1.0.2 on Desktop -> 1.0.4: unins000.dat no longer mentions it; same swap + uninstall: target files and
  SDDL unchanged (PASS); Program Files\VoiceChanger fully removed.
- R: fresh -> reinstall -> uninstall: Program Files\VoiceChanger fully removed; FxProperties restored.
- python unittest: 16 run, 2 skipped (tkinter missing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 23:04:18 +09:00

333 lines
16 KiB
Plaintext

; 음성 변환기 설치 프로그램 (Inno Setup 6). 빌드: scripts/build-release.sh 가 만든 dist\payload 를 담는다.
; ISCC.exe installer\VoiceChanger.iss → dist\VoiceChangerSetup.exe
; 하는 일
; 1. 설치할 폴더를 고르게 한다 (바탕 화면 · 문서 아래도 됨). 앱 · Python · 엔진 · 모델 · 설정 · 캐시가 모두 그 폴더에 생긴다.
; 2. 관리자 권한 · 오디오 서비스가 실행하는 부분(마이크 모듈 APO · mic-apo.ps1 · 제거 프로그램)은
; Program Files\VoiceChanger({app})에 두고, 마이크마다 APO 를 붙인다 (가상 오디오 장치 설치 없음).
; 3. 고른 폴더는 관리자 권한으로 건드리지 않는다. 앱 파일 복사와 Python · 엔진 · 기본 모델 내려받기는
; 설치를 시작한 사용자 권한으로 한다 (scripts\deploy.ps1 → install.ps1, 10~20분).
; 고른 폴더의 상위가 사용자 소유면 설치 중에 그 폴더를 다른 곳을 가리키는 정션으로 바꿔칠 수 있어서,
; 관리자 권한으로 그 경로에 쓰거나 권한을 바꾸면 엉뚱한 곳이 바뀔 수 있기 때문이다.
; 제거할 때는 마이크 설정을 원래대로 되돌리고 Program Files 쪽을 지운다. 고른 폴더는 남긴다 (사용자가 직접 지울 수 있음).
#define AppName "음성 변환기"
#ifndef AppVersion
#define AppVersion "1.0.0"
#endif
[Setup]
AppId={{8C3F2A51-6D0B-4E7A-9F3C-2B5E1D7A4C90}
AppName={#AppName}
AppVersion={#AppVersion}
AppPublisher=voice_copy
; {app} 은 항상 Program Files\VoiceChanger. 사용자가 고르는 폴더는 아래 [Code] 의 DataPage
DefaultDirName={commonpf}\VoiceChanger
DisableDirPage=yes
UsePreviousAppDir=no
DisableProgramGroupPage=yes
PrivilegesRequired=admin
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
MinVersion=10.0.19041
OutputDir=..\dist
OutputBaseFilename=VoiceChangerSetup
Compression=lzma2
SolidCompression=yes
WizardStyle=modern
UninstallFilesDir={app}\uninstall
; 이전 제거 기록을 이어 쓰지 않는다. v1.0.2 의 기록에는 고른 폴더(바탕 화면 등)의 파일이 들어 있어서,
; 이어 쓰면 제거할 때 관리자 권한으로 그 경로의 파일을 지우게 된다 (정션으로 바꿔치면 다른 곳의 같은 이름 파일이 지워짐)
UninstallLogMode=overwrite
UninstallDisplayIcon={app}\payload\VoiceChanger.exe
UninstallDisplayName={#AppName}
[Languages]
Name: "ko"; MessagesFile: "compiler:Languages\Korean.isl"
[Messages]
ko.DiskSpaceMBLabel=설치 중에 약 8GB 를 더 내려받습니다. 15GB 이상 비어 있는 드라이브를 권합니다.
[Tasks]
Name: "desktopicon"; Description: "바탕 화면에 바로 가기 만들기"; Flags: unchecked
[Files]
Source: "legacy.ps1"; Flags: dontcopy
Source: "deploy.ps1"; DestDir: "{app}\scripts"; Flags: ignoreversion
Source: "..\dist\payload\apo\*"; DestDir: "{app}\apo"; Flags: ignoreversion
Source: "..\dist\payload\scripts\mic-apo.ps1"; DestDir: "{app}\scripts"; Flags: ignoreversion
; 고른 폴더에 사용자 권한으로 복사할 앱 파일
Source: "..\dist\payload\*"; DestDir: "{app}\payload"; Excludes: "\apo,\apo\*,\scripts\mic-apo.ps1"; Flags: recursesubdirs createallsubdirs ignoreversion
; 바로 가기는 앱을 복사한 뒤 [Code] 에서 만든다 ([Icons] 는 대상 파일이 아직 없을 때 만들어져 대상이 빈 바로 가기가 됨)
[UninstallDelete]
Type: files; Name: "{autoprograms}\{#AppName}.lnk"
Type: files; Name: "{autodesktop}\{#AppName}.lnk"
[Run]
Filename: "{code:DataDir}\VoiceChanger.exe"; Description: "음성 변환기 실행"; Flags: postinstall nowait skipifsilent unchecked runasoriginaluser; Check: DeployDone
[UninstallRun]
Filename: "powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\scripts\mic-apo.ps1"" -Uninstall -Root ""{app}"""; Flags: runhidden waituntilterminated; RunOnceId: "MicApoUninstall"
[Code]
const
UninstKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{8C3F2A51-6D0B-4E7A-9F3C-2B5E1D7A4C90}_is1';
var
DataPage: TInputDirWizardPage;
LegacyOld: String;
DeployOk: Boolean;
UninstDataDir: String;
{ Program Files\VoiceChanger. 설치 폴더 상수와 같지만 그 상수는 InitializeWizard 때 아직 정해지지 않아서 따로 둔다 }
function SysDir: String;
begin
Result := ExpandConstant('{commonpf}\VoiceChanger');
end;
{ 앱 복사가 사용자 권한으로 끝났을 때만 설치 뒤 바로 실행한다.
설치 프로그램을 관리자 권한으로 시작하면 "원래 사용자" 도 관리자라 deploy.ps1 이 거부(33)하고, 실행도 하지 않는다 }
function DeployDone: Boolean;
begin
Result := DeployOk;
end;
function DataDir(Param: String): String;
begin
Result := RemoveBackslashUnlessRoot(DataPage.Values[0]);
end;
{ 명령줄 인자로 넘길 경로. "D:\" 처럼 \ 로 끝나면 닫는 따옴표가 이스케이프되므로 "D:\." 로 }
function ArgPath(const S: String): String;
begin
Result := S;
if Copy(Result, Length(Result), 1) = '\' then
Result := Result + '.';
end;
function PowerShellExe: String;
begin
Result := ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe');
end;
procedure InitializeWizard;
var
Def, Prev: String;
begin
DataPage := CreateInputDirPage(wpSelectDir, '설치할 폴더', '음성 변환기를 어디에 설치할까요?',
'앱 · Python · 변환 엔진 · 목소리 모델 · 설정 · 학습 파일 · 캐시가 모두 이 폴더에 저장됩니다. ' +
'바탕 화면이나 문서 아래도 됩니다. 설치 중에 약 8GB 를 내려받고, 모델을 만들면 더 늘어나므로 15GB 이상 여유가 있는 드라이브를 골라 주세요.',
False, 'VoiceChanger');
DataPage.Add('');
{ 기본값: /DATADIR=, 지난 설치에서 고른 폴더, v1.0.2 까지의 설치 폴더(제거 정보의 App Path), C:\VoiceChanger }
Def := ExpandConstant('{param:DATADIR|}');
if Def = '' then
Def := GetPreviousData('DataDir', '');
if (Def = '') and RegQueryStringValue(HKLM, UninstKey, 'Inno Setup: App Path', Prev) and
(CompareText(RemoveBackslashUnlessRoot(Prev), SysDir) <> 0) then
Def := Prev;
if Def = '' then
Def := ExpandConstant('{sd}\VoiceChanger');
DataPage.Values[0] := Def;
end;
procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
SetPreviousData(PreviousDataKey, 'DataDir', DataDir(''));
end;
function IsEmptyDir(const Dir: String): Boolean;
var
F: TFindRec;
begin
Result := True;
if FindFirst(AddBackslash(Dir) + '*', F) then
try
repeat
if (F.Name <> '.') and (F.Name <> '..') then
begin
Result := False;
Exit;
end;
until not FindNext(F);
finally
FindClose(F);
end;
end;
function IsUnder(const Child, Parent: String): Boolean;
begin
Result := Pos(Lowercase(AddBackslash(Parent)), Lowercase(AddBackslash(Child))) = 1;
end;
{ OneDrive 로 동기화되는 폴더(바탕 화면이 OneDrive 로 옮겨진 PC 가 많음)인지 }
function InOneDrive(const Dir: String): Boolean;
var
I: Integer;
OD: String;
begin
Result := False;
for I := 0 to 2 do
begin
case I of
0: OD := GetEnv('OneDrive');
1: OD := GetEnv('OneDriveConsumer');
else
OD := GetEnv('OneDriveCommercial');
end;
if (OD <> '') and IsUnder(Dir, OD) then
begin
Result := True;
Exit;
end;
end;
end;
{ 고른 폴더 확인 (읽기만 함). 문제가 있으면 안내 문구 }
function CheckDataDir(const Dir: String): String;
begin
Result := '';
if (Length(Dir) < 3) or (Copy(Dir, 2, 2) <> ':\') then
Result := '드라이브 문자로 시작하는 폴더를 골라 주세요. (예: C:\VoiceChanger)'
else if IsUnder(Dir, SysDir) or IsUnder(SysDir, Dir) then
Result := SysDir + ' 은 설치 프로그램이 쓰는 곳입니다. 다른 폴더를 골라 주세요.'
{ 다른 파일이 든 폴더에는 설치하지 않는다 (예: 바탕 화면 자체). 이 앱이 이미 설치된 폴더(업데이트)는 된다 }
else if DirExists(Dir) and not IsEmptyDir(Dir) and not FileExists(AddBackslash(Dir) + 'VoiceChanger.exe') then
Result := '이 폴더에는 이미 다른 파일이 있습니다. 비어 있는 폴더나 새 폴더를 골라 주세요. (예: ' + AddBackslash(Dir) + 'VoiceChanger)';
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
Msg: String;
begin
Result := True;
if CurPageID <> DataPage.ID then Exit;
Msg := CheckDataDir(DataDir(''));
if Msg <> '' then
begin
SuppressibleMsgBox(Msg, mbError, MB_OK, IDOK);
Result := False;
Exit;
end;
if InOneDrive(DataDir('')) and (SuppressibleMsgBox('이 폴더는 OneDrive 로 동기화됩니다.' + #13#10 +
'설치하면서 받는 8GB 이상(Python · 엔진 · 모델)이 OneDrive 에 올라가고, OneDrive 가 공간 확보로 파일을 내리면 음성 변환기가 실행되지 않을 수 있습니다.' + #13#10#13#10 +
'그래도 여기에 설치할까요? ("아니요" 를 누르고 C:\VoiceChanger 처럼 OneDrive 밖의 폴더를 고르는 것을 권합니다)',
mbConfirmation, MB_YESNO, IDYES) <> IDYES) then
Result := False;
end;
procedure StartAudio;
var
Code: Integer;
begin
Exec(PowerShellExe, '-NoProfile -Command "Start-Service Audiosrv"', '', SW_HIDE, ewWaitUntilTerminated, Code);
end;
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
Code: Integer;
ApoInUse: Boolean;
begin
Result := CheckDataDir(DataDir('')); { 조용한 설치(/DATADIR=)에서도 확인 }
if Result <> '' then Exit;
{ 다시 설치(업데이트)할 때 오디오 엔진이 쥐고 있는 APO 파일을 바꿀 수 있게 잠깐 오디오 서비스를 멈춘다.
v1.0.1 까지는 APO 가 고른 폴더의 apo\ 에 있었다 (legacy.ps1 이 지움). 설치 뒤 mic-apo.ps1 이 다시 켠다. }
ApoInUse := FileExists(ExpandConstant('{app}\apo\VoiceChangerAPO.dll')) or FileExists(DataDir('') + '\apo\VoiceChangerAPO.dll');
if ApoInUse then
Exec(PowerShellExe, '-NoProfile -Command "Stop-Service -Name AudioEndpointBuilder -Force"', '', SW_HIDE, ewWaitUntilTerminated, Code);
{ v1.0.0 · v1.0.1 이 관리자 소유로 잠가 둔 폴더면, 그 실행 부분을 지우고 <폴더>.old 로 비켜 둔다 (관리자 권한).
상위 폴더가 관리자 소유라 일반 사용자가 바꿔칠 수 없을 때만 legacy.ps1 이 한다. }
LegacyOld := DataDir('') + '.old';
ExtractTemporaryFile('legacy.ps1');
if not Exec(PowerShellExe, '-NoProfile -ExecutionPolicy Bypass -File "' + ExpandConstant('{tmp}\legacy.ps1') +
'" -App "' + ArgPath(DataDir('')) + '" -Sys "' + ExpandConstant('{app}') + '" -Old "' + LegacyOld + '"',
'', SW_HIDE, ewWaitUntilTerminated, Code) then
Code := -1;
Log('legacy exit=' + IntToStr(Code));
case Code of
0: LegacyOld := '';
1: ;
20: Result := '이 폴더에 있는 이전 버전을 안전하게 옮길 수 없습니다. 새 폴더를 골라 주세요.';
22: Result := LegacyOld + ' 폴더가 이미 있습니다. 그 폴더를 지우거나 다른 폴더를 골라 주세요.';
else
Result := '이전 버전 폴더를 정리하지 못했습니다 (코드 ' + IntToStr(Code) + '). 다른 폴더를 골라 다시 설치해 주세요.';
end;
if (Result <> '') and ApoInUse then
StartAudio;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
Code: Integer;
Args: String;
begin
if CurStep <> ssPostInstall then Exit;
WizardForm.StatusLabel.Caption := '마이크에 변환 모듈을 붙이는 중... (윈도우 소리가 잠깐 끊깁니다)';
if not Exec(PowerShellExe, '-NoProfile -ExecutionPolicy Bypass -File "' + ExpandConstant('{app}\scripts\mic-apo.ps1') +
'" -Install -Root "' + ExpandConstant('{app}') + '"', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, Code) or (Code <> 0) then
begin
StartAudio;
SuppressibleMsgBox('마이크에 변환 모듈을 붙이지 못했습니다. 설치가 끝난 뒤 음성 변환기의 "마이크 다시 연결" 을 눌러 주세요.', mbError, MB_OK, IDOK);
end;
WizardForm.StatusLabel.Caption := '앱을 복사하고 Python · 변환 엔진 · 기본 모델을 내려받는 중... (10~20분, 검은 창에 진행 상황이 나옵니다)';
{ 설치를 시작한 사용자 권한으로: 고른 폴더에 앱 파일 복사 → 이전 버전의 데이터 폴더 옮기기 → install.ps1 }
Args := '-NoProfile -ExecutionPolicy Bypass -File "' + ExpandConstant('{app}\scripts\deploy.ps1') + '" -Data "' + ArgPath(DataDir('')) + '"';
if LegacyOld <> '' then
Args := Args + ' -From "' + LegacyOld + '"';
if not ExecAsOriginalUser(PowerShellExe, Args, ExpandConstant('{app}'), SW_SHOWNORMAL, ewWaitUntilTerminated, Code) then
Code := -1;
Log('deploy exit=' + IntToStr(Code));
DeployOk := Code = 0;
case Code of
0: ;
33: SuppressibleMsgBox('설치 프로그램이 관리자 권한으로 시작되어 앱 파일을 복사하지 않았습니다.' + #13#10 +
'관리자 권한으로 실행하지 말고 VoiceChangerSetup.exe 를 그냥 더블클릭해서 다시 설치해 주세요.' + #13#10 +
'(관리자 권한 확인 창이 뜨는 것은 정상입니다)', mbError, MB_OK, IDOK);
31: SuppressibleMsgBox(DataDir('') + ' 이 다른 곳을 가리키는 링크(정션)라서 앱을 복사하지 않았습니다.' + #13#10 +
'링크를 지우거나 다른 폴더를 골라 다시 설치해 주세요.', mbError, MB_OK, IDOK);
32: SuppressibleMsgBox(DataDir('') + ' 에 앱 파일을 복사하지 못했습니다 (쓰기 권한이 없는 폴더일 수 있습니다).' + #13#10 +
'내 계정으로 쓸 수 있는 폴더(예: C:\VoiceChanger, 바탕 화면)를 골라 다시 설치해 주세요.', mbError, MB_OK, IDOK);
else
SuppressibleMsgBox('엔진을 내려받지 못했습니다 (인터넷 연결을 확인해 주세요).' + #13#10 +
DataDir('') + '\install.bat 을 실행하면 받은 곳부터 이어서 받습니다.', mbError, MB_OK, IDOK);
end;
if FileExists(DataDir('') + '\VoiceChanger.exe') then
begin
CreateShellLink(ExpandConstant('{autoprograms}\{#AppName}.lnk'), '{#AppName}', DataDir('') + '\VoiceChanger.exe', '', DataDir(''), '', 0, SW_SHOWNORMAL);
if WizardIsTaskSelected('desktopicon') then
CreateShellLink(ExpandConstant('{autodesktop}\{#AppName}.lnk'), '{#AppName}', DataDir('') + '\VoiceChanger.exe', '', DataDir(''), '', 0, SW_SHOWNORMAL);
end;
{ legacy.ps1 이 비켜 둔 이전 버전 폴더: 데이터 폴더를 다 옮겼으면 비어 있다 (상위가 관리자 소유라 이 경로는 안전) }
if (LegacyOld <> '') and DirExists(LegacyOld) and not RemoveDir(LegacyOld) then
SuppressibleMsgBox('이전 버전 폴더 ' + LegacyOld + ' 에 옮기지 못한 파일이 남아 있습니다. 확인한 뒤 지워 주세요.', mbInformation, MB_OK, IDOK);
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
Code: Integer;
begin
if CurUninstallStep = usUninstall then
begin
if not RegQueryStringValue(HKLM, UninstKey, 'Inno Setup CodeFile: DataDir', UninstDataDir) then
UninstDataDir := '';
Exit;
end;
{ 마이크 되돌리기([UninstallRun])와 설치 파일 지우기가 끝난 뒤 }
if CurUninstallStep <> usPostUninstall then Exit;
{ Program Files 쪽(관리자만 쓰는 곳)은 남은 기록 · 빈 폴더까지 지운다.
제거 기록을 이어 쓰지 않아서(overwrite) 업그레이드 전부터 있던 폴더는 Inno 가 지우지 않는다. 제거 프로그램 파일은
이 뒤에 지워지므로, 끝난 뒤 빈 uninstall 폴더와 설치 폴더를 지우는 cmd 를 따로 띄운다 (rmdir 은 빈 폴더만 지움) }
DelTree(ExpandConstant('{app}\apo'), True, True, True);
DelTree(ExpandConstant('{app}\scripts'), True, True, True);
DelTree(ExpandConstant('{app}\payload'), True, True, True);
Exec(ExpandConstant('{cmd}'), '/c ping -n 4 127.0.0.1 >nul & rmdir "' + ExpandConstant('{app}\uninstall') + '" & rmdir "' + ExpandConstant('{app}') + '"',
'', SW_HIDE, ewNoWait, Code);
{ 고른 폴더는 관리자 권한으로 지우지 않는다 (정션으로 바꿔쳐 다른 곳을 지우게 만들 수 있음). 내 계정 폴더라 직접 지울 수 있다 }
if (UninstDataDir <> '') and DirExists(UninstDataDir) and not UninstallSilent then
MsgBox('마이크 설정을 되돌리고 프로그램을 지웠습니다.' + #13#10#13#10 +
'앱 · Python · 엔진 · 목소리 모델 · 녹음 · 설정이 든 폴더는 남겨 두었습니다:' + #13#10 + UninstDataDir + #13#10#13#10 +
'필요 없으면 이 폴더를 직접 지워 주세요.', mbInformation, MB_OK);
end;