[Code]
// 检查 .NET Framework 4.8
function IsNetFramework48Installed(): Boolean;
var
RegKey: String;
Release: Cardinal;
begin
Result := False;
RegKey := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full';
if RegKeyExists(HKLM, RegKey) then
begin
if RegQueryDWordValue(HKLM, RegKey, 'Release', Release) then
begin
// Release >= 528040 表示已安装 .NET Framework 4.8
Result := Release >= 528040;
end;
end;
end;
// 检查 WebView2 Runtime
function IsWebView2Installed(): Boolean;
var
RegKey: String;
begin
Result := False;
// 检查 32 位注册表
RegKey := 'SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
if RegKeyExists(HKLM, RegKey) then
begin
Result := True;
Exit;
end;
// 检查 64 位注册表
RegKey := 'SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
if RegKeyExists(HKLM, RegKey) then
begin
Result := True;
end;
end;
// 检查 VC++ Runtime
function IsVCRedistInstalled(): Boolean;
var
RegKey: String;
begin
Result := False;
// 检查最新版本的 VC++ Runtime (14.0)
RegKey := 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64';
if RegKeyExists(HKLM, RegKey) then
begin
Result := True;
Exit;
end;
// 32位系统检查
RegKey := 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86';
if RegKeyExists(HKLM, RegKey) then
begin
Result := True;
end;
end;
// 在安装前检查所有依赖
function InitializeSetup(): Boolean;
var
ErrorMsg: String;
MissingDependencies: Boolean;
begin
Result := True;
MissingDependencies := False;
ErrorMsg := '请安装以下缺失的组件:' + #13#10#13#10;
if not IsNetFramework48Installed() then
begin
ErrorMsg := ErrorMsg + '- .NET Framework 4.8' + #13#10;
MissingDependencies := True;
end;
if not IsWebView2Installed() then
begin
ErrorMsg := ErrorMsg + '- WebView2 Runtime' + #13#10;
MissingDependencies := True;
end;
if not IsVCRedistInstalled() then
begin
ErrorMsg := ErrorMsg + '- Visual C++ Runtime' + #13#10;
MissingDependencies := True;
end;
if MissingDependencies then
begin
ErrorMsg := ErrorMsg + #13#10 + '是否继续安装?';
if MsgBox(ErrorMsg, mbConfirmation, MB_YESNO) = IDNO then
begin
Result := False;
end;
end;
end;