-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download and install vc++ runtime if missing/outdated
- Loading branch information
1 parent
6f1479f
commit fc4f64f
Showing
2 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
[Code] | ||
// Fork of https://github.com/DomGries/InnoDependencyInstaller | ||
// types and variables | ||
type | ||
TDependency_Entry = record | ||
Filename: String; | ||
Parameters: String; | ||
Title: String; | ||
URL: String; | ||
Checksum: String; | ||
ForceSuccess: Boolean; | ||
RestartAfter: Boolean; | ||
end; | ||
var | ||
Dependency_Memo: String; | ||
Dependency_List: array of TDependency_Entry; | ||
Dependency_NeedToRestart, Dependency_ForceX86: Boolean; | ||
Dependency_DownloadPage: TDownloadWizardPage; | ||
procedure Dependency_Add(const Filename, Parameters, Title, URL, Checksum: String; const ForceSuccess, RestartAfter: Boolean); | ||
var | ||
Dependency: TDependency_Entry; | ||
DependencyCount: Integer; | ||
begin | ||
Dependency_Memo := Dependency_Memo + #13#10 + '%1' + Title; | ||
Dependency.Filename := Filename; | ||
Dependency.Parameters := Parameters; | ||
Dependency.Title := Title; | ||
if FileExists(ExpandConstant('{tmp}{\}') + Filename) then begin | ||
Dependency.URL := ''; | ||
end else begin | ||
Dependency.URL := URL; | ||
end; | ||
Dependency.Checksum := Checksum; | ||
Dependency.ForceSuccess := ForceSuccess; | ||
Dependency.RestartAfter := RestartAfter; | ||
DependencyCount := GetArrayLength(Dependency_List); | ||
SetArrayLength(Dependency_List, DependencyCount + 1); | ||
Dependency_List[DependencyCount] := Dependency; | ||
end; | ||
<event('InitializeWizard')> | ||
procedure Dependency_InitializeWizard; | ||
begin | ||
Dependency_DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), nil); | ||
end; | ||
<event('PrepareToInstall')> | ||
function Dependency_PrepareToInstall(var NeedsRestart: Boolean): String; | ||
var | ||
DependencyCount, DependencyIndex, ResultCode: Integer; | ||
Retry: Boolean; | ||
TempValue: String; | ||
begin | ||
DependencyCount := GetArrayLength(Dependency_List); | ||
if DependencyCount > 0 then begin | ||
Dependency_DownloadPage.Show; | ||
for DependencyIndex := 0 to DependencyCount - 1 do begin | ||
if Dependency_List[DependencyIndex].URL <> '' then begin | ||
Dependency_DownloadPage.Clear; | ||
Dependency_DownloadPage.Add(Dependency_List[DependencyIndex].URL, Dependency_List[DependencyIndex].Filename, Dependency_List[DependencyIndex].Checksum); | ||
Retry := True; | ||
while Retry do begin | ||
Retry := False; | ||
try | ||
Dependency_DownloadPage.Download; | ||
except | ||
if Dependency_DownloadPage.AbortedByUser then begin | ||
Result := Dependency_List[DependencyIndex].Title; | ||
DependencyIndex := DependencyCount; | ||
end else begin | ||
case SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of | ||
IDABORT: begin | ||
Result := Dependency_List[DependencyIndex].Title; | ||
DependencyIndex := DependencyCount; | ||
end; | ||
IDRETRY: begin | ||
Retry := True; | ||
end; | ||
end; | ||
end; | ||
end; | ||
end; | ||
end; | ||
end; | ||
if Result = '' then begin | ||
for DependencyIndex := 0 to DependencyCount - 1 do begin | ||
Dependency_DownloadPage.SetText(Dependency_List[DependencyIndex].Title, ''); | ||
Dependency_DownloadPage.SetProgress(DependencyIndex + 1, DependencyCount + 1); | ||
while True do begin | ||
ResultCode := 0; | ||
#ifdef Dependency_CustomExecute | ||
if {#Dependency_CustomExecute}(ExpandConstant('{tmp}{\}') + Dependency_List[DependencyIndex].Filename, Dependency_List[DependencyIndex].Parameters, ResultCode) then begin | ||
#else | ||
if ShellExec('', ExpandConstant('{tmp}{\}') + Dependency_List[DependencyIndex].Filename, Dependency_List[DependencyIndex].Parameters, '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then begin | ||
#endif | ||
if Dependency_List[DependencyIndex].RestartAfter then begin | ||
if DependencyIndex = DependencyCount - 1 then begin | ||
Dependency_NeedToRestart := True; | ||
end else begin | ||
NeedsRestart := True; | ||
Result := Dependency_List[DependencyIndex].Title; | ||
end; | ||
break; | ||
end else if (ResultCode = 0) or Dependency_List[DependencyIndex].ForceSuccess then begin // ERROR_SUCCESS (0) | ||
break; | ||
end else if ResultCode = 1641 then begin // ERROR_SUCCESS_REBOOT_INITIATED (1641) | ||
NeedsRestart := True; | ||
Result := Dependency_List[DependencyIndex].Title; | ||
break; | ||
end else if ResultCode = 3010 then begin // ERROR_SUCCESS_REBOOT_REQUIRED (3010) | ||
Dependency_NeedToRestart := True; | ||
break; | ||
end; | ||
end; | ||
case SuppressibleMsgBox(FmtMessage(SetupMessage(msgErrorFunctionFailed), [Dependency_List[DependencyIndex].Title, IntToStr(ResultCode)]), mbError, MB_ABORTRETRYIGNORE, IDIGNORE) of | ||
IDABORT: begin | ||
Result := Dependency_List[DependencyIndex].Title; | ||
break; | ||
end; | ||
IDIGNORE: begin | ||
break; | ||
end; | ||
end; | ||
end; | ||
if Result <> '' then begin | ||
break; | ||
end; | ||
end; | ||
if NeedsRestart then begin | ||
TempValue := '"' + ExpandConstant('{srcexe}') + '" /restart=1 /LANG="' + ExpandConstant('{language}') + '" /DIR="' + WizardDirValue + '" /GROUP="' + WizardGroupValue + '" /TYPE="' + WizardSetupType(False) + '" /COMPONENTS="' + WizardSelectedComponents(False) + '" /TASKS="' + WizardSelectedTasks(False) + '"'; | ||
if WizardNoIcons then begin | ||
TempValue := TempValue + ' /NOICONS'; | ||
end; | ||
RegWriteStringValue(HKA, 'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce', '{#SetupSetting("AppName")}', TempValue); | ||
end; | ||
end; | ||
Dependency_DownloadPage.Hide; | ||
end; | ||
end; | ||
#ifndef Dependency_NoUpdateReadyMemo | ||
<event('UpdateReadyMemo')> | ||
#endif | ||
function Dependency_UpdateReadyMemo(const Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String; | ||
begin | ||
Result := ''; | ||
if MemoUserInfoInfo <> '' then begin | ||
Result := Result + MemoUserInfoInfo + Newline + NewLine; | ||
end; | ||
if MemoDirInfo <> '' then begin | ||
Result := Result + MemoDirInfo + Newline + NewLine; | ||
end; | ||
if MemoTypeInfo <> '' then begin | ||
Result := Result + MemoTypeInfo + Newline + NewLine; | ||
end; | ||
if MemoComponentsInfo <> '' then begin | ||
Result := Result + MemoComponentsInfo + Newline + NewLine; | ||
end; | ||
if MemoGroupInfo <> '' then begin | ||
Result := Result + MemoGroupInfo + Newline + NewLine; | ||
end; | ||
if MemoTasksInfo <> '' then begin | ||
Result := Result + MemoTasksInfo; | ||
end; | ||
if Dependency_Memo <> '' then begin | ||
if MemoTasksInfo = '' then begin | ||
Result := Result + SetupMessage(msgReadyMemoTasks); | ||
end; | ||
Result := Result + FmtMessage(Dependency_Memo, [Space]); | ||
end; | ||
end; | ||
<event('NeedRestart')> | ||
function Dependency_NeedRestart: Boolean; | ||
begin | ||
Result := Dependency_NeedToRestart; | ||
end; | ||
function Dependency_IsX64: Boolean; | ||
begin | ||
Result := not Dependency_ForceX86 and Is64BitInstallMode; | ||
end; | ||
function Dependency_String(const x86, x64: String): String; | ||
begin | ||
if Dependency_IsX64 then begin | ||
Result := x64; | ||
end else begin | ||
Result := x86; | ||
end; | ||
end; | ||
function Dependency_ArchSuffix: String; | ||
begin | ||
Result := Dependency_String('', '_x64'); | ||
end; | ||
function Dependency_ArchTitle: String; | ||
begin | ||
Result := Dependency_String(' (x86)', ' (x64)'); | ||
end; | ||
procedure Dependency_AddVCppRuntime; | ||
begin | ||
// https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist | ||
if not IsMsiProductInstalled(Dependency_String('{65E5BD06-6392-3027-8C26-853107D3CF1A}', '{36F68A90-239C-34DF-B58C-64B30153CE35}'), PackVersionComponents(14, 40, 33810, 0)) then begin | ||
Dependency_Add('vcredist2022' + Dependency_ArchSuffix + '.exe', | ||
'/passive /norestart', | ||
'Visual C++ 2015-2022 Redistributable' + Dependency_ArchTitle, | ||
Dependency_String('https://aka.ms/vs/17/release/vc_redist.x86.exe', 'https://aka.ms/vs/17/release/vc_redist.x64.exe'), | ||
'', False, False); | ||
end; | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters