vrc-get/vrc-get-gui/bundle/windows-setup.iss

211 lines
7.8 KiB
Text

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; Non-commercial use only
#ifndef ApplicationVersion
#error ApplicationVersion is not defined. Define with -DApplicationVersion=
#endif
#ifndef WebView2SetupPath
#error WebView2SetupPath is not defined. Define with -DWebView2SetupPath=
#endif
#ifndef ApplicationPath
#error ApplicationPath is not defined. Define with -DApplicationPath=LicensePath
#endif
#ifndef LicensePath
#error LicensePath is not defined. Define with -DLicensePath=
#endif
#define MyAppName "ALCOM"
#define MyAppPublisher "anatawa12"
#define MyAppURL "https://vrc-get.anatawa12.com/alcom/"
#define MyAppExeName "ALCOM.exe"
#define MyAppAssocName "ALCOM Template"
#define MyAppAssocExt ".alcomtemplate"
#define MyAppAssocKey "ALCOM Project Template"
[Setup]
AppId={{4C3D0631-AE29-4D20-A231-678D9CF8D6DB}
AppName={#MyAppName}
AppVersion={#ApplicationVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
UninstallDisplayIcon={app}\{#MyAppExeName}
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
ChangesAssociations=yes
DisableProgramGroupPage=yes
LicenseFile={#LicensePath}
; Remove the following line to run in administrative install mode (install for all users).
PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
OutputBaseFilename=alcom
SolidCompression=yes
WizardStyle=modern dynamic
; allow users to install ALCOM to different location than before.
; this would cause ALCOM to be installed to multiple location, but user may move ALCOM
; without uninstalling ALCOM so this is 'safer' option than normal one.
DisableDirPage=no
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "{#ApplicationPath}"; DestDir: "{app}"; DestName: "{#MyAppExeName}"; Flags: ignoreversion
Source: "{#WebView2SetupPath}"; DestName: "MicrosoftEdgeWebView2Setup.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
; No skipifsilent to relaunch after application quit
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall runasoriginaluser
[Code]
// NSIS to inno setup migrations
// There are many differences between nsis and inno setup.
// (There are more changes than following in default settings but can be fixed by changing settings)
// We'll fix following changes in each ways.
// (Following uses bash-like fallback style: ${Variable:-fallbackValue} and HKLM/-style path for reference
// - default installation path changes
// NSIS: ${LOCALAPPDATA}\ALCOM
// Inno Setup: ${FOLDERID_UserProgramFiles:-${LOCALAPPDATA}/Programs}/${AppName}
// No relocation will be done for installation location since updating will break existing shortcuts.
// We'll let inno setup to use old location when no inno setup detected
// - Registry key for remove entry
// NSIS: HKA\Software\Microsoft\Windows\CurrentVersion\Uninstall\ALCOM
// Inno Setup: HKA\Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppId}_is1
// (source: https://github.com/jrsoftware/issrc/blob/7d001a7eaa056a4b43bc89f6ff09c4edd213585d/Projects/Src/Setup.MainFunc.pas#L3123)
// We will remove the old key
// - Previous installation registry entry
// NSIS: HKA\Software\anatawa12\vrc-get-gui ""
// Inno Setup: HKA\Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppId}_is1 "Inno Setup: App Path"
// We will remove the old key and copy previous install to new one
// - Previous installer language
// NSIS: HKA\Software\anatawa12\vrc-get-gui "Installer Language"
// Inno Setup: HKA\Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppId}_is1 "Inno Setup: Language"
// We will remove the old key, but no migration will be done
var NsisMigration: Boolean;
procedure InitializeWizard();
var
NsisInstallPath: string;
begin
if (WizardForm.PrevAppDir = '') and not IsAdminInstallMode then
begin
// Inno setup previous installation not found.
// We'll find NSIS install information
Log('No Inno Setup installation found while single user installation is enabled, trying migration from NSIS');
if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\anatawa12\vrc-get-gui', '', NsisInstallPath) then
begin
Log('Previous NSIS installation path found: ' + NsisInstallPath);
NsisMigration := True;
WizardForm.DirEdit.Text := NsisInstallPath;
// We want to set PrevAppDir to new value to prevent 'directly alredy exists' warning,
// but pascal runtime in inno setup doesn't allow us to access private fields so we leave it.
end
end;
end;
procedure PostInstallNsisMigration();
begin
if NsisMigration then
begin
// remove old uninstall entry
RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'Software\anatawa12\vrc-get-gui');
RegDeleteKeyIfEmpty(HKEY_CURRENT_USER, 'Software\anatawa12');
RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\ALCOM');
// remove uninstaller from NSIS
DeleteFile(ExpandConstant('{app}\uninstall.exe'))
end;
end;
// webview2 installation
const WebView2RegKey = 'SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
// Check both HKLM32 and HKCU for user install.
// Check HKLM32 twice for system install.
// We always check HKLM32 even our system use 64bit.
function IsWebView2Installed: Boolean;
begin
Result := RegKeyExists(HKLM32, WebView2RegKey) or RegKeyExists(HKA, WebView2RegKey);
end;
function InstallWebView2: Boolean;
var
InstallerPath: string;
ResultCode: Integer;
begin
Result := False;
InstallerPath :=
ExpandConstant('{tmp}\MicrosoftEdgeWebView2Setup.exe');
if not Exec(
InstallerPath,
'/silent /install',
'',
SW_HIDE,
ewWaitUntilTerminated,
ResultCode
) then
begin
MsgBox('Failed to launch WebView2 installer.', mbError, MB_OK);
exit;
end;
if ResultCode <> 0 then
begin
MsgBox(
'WebView2 installation failed. Exit code: ' + IntToStr(ResultCode),
mbError,
MB_OK
);
exit;
end;
Result := True;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
if not IsWebView2Installed then
begin
if not InstallWebView2 then
begin
Abort;
end;
end;
end;
if CurStep = ssPostInstall then
begin
PostInstallNsisMigration;
end;
end;