2012-11-09 51 views
0

我正在創建自定義安裝程序,並且在大多數情況下我已經設置我想要的方式,除了它缺少兩個我想要添加到安裝程序的功能。我已經做了大量的搜索,雖然我發現了很多類似的問題,但我一直未能對這些問題做出迴應,並根據自己的具體需求對其進行修改並取得任何成功。Inno Setup:如何爲當前安裝的DirectX版本創建「check:」函數,以及是否安裝MS VC++ 2005

基本上我需要做的是爲'Check:'創建一個自定義函數,用於檢查當前安裝的DirectX版本。我知道有'RegQueryStringValue'函數,並且我知道註冊表中包含版本(HKLM \ SOFTWARE \ Microsoft \ DirectX,Version)的密鑰的位置。我只是不知道如何實現代碼來檢查註冊表中包含的版本,並且如果它返回小於4.09.00.0904的值以繼續我在[文件]下輸入的DXSETUP。

我也想對Visual C++ 2005(x86)使用'Check:'來執行相同的例程。這一個我相信會更簡單,因爲它只需要檢查一個實際的鍵是否存在(RegQueryKey?)而不是一個值。我相信VC++ 2005的關鍵是HKLM \ SOFTWARE \ Microsoft \ VisualStudio \ 8.0

如果任何人都可以幫助我,我會非常感謝,因爲我已經搞了幾個小時,試圖獲得某些功能一起沒有太大的成功。如果您需要我的進一步信息,我會非常樂意提供。

回答

3

有一個檢查包含在Inno Setup中的先決條件的例子,在CodePrepareToInstall.iss中做這類事情的例子。 InitializeSetup顯示如何檢查是否存在註冊表項,並且您可以在DetectAndInstallPrerequisites中執行此操作。我添加了一個CheckDXVersion函數,您可以從DirectX註冊表項中傳遞Version字符串來檢查可以使用的4.9或更高版本(未經測試!)。

; -- CodePrepareToInstall.iss -- 
; 
; This script shows how the PrepareToInstall event function can be used to 
; install prerequisites and handle any reboots in between, while remembering 
; user selections across reboots. 

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 
DefaultGroupName=My Program 
UninstallDisplayIcon={app}\MyProg.exe 
OutputDir=userdocs:Inno Setup Examples Output 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}"; 
Source: "MyProg.chm"; DestDir: "{app}"; 
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme; 

[Icons] 
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe" 

[Code] 
const 
    (*** Customize the following to your own name. ***) 
    RunOnceName = 'My Program Setup restart'; 

    QuitMessageReboot = 'The installation of a prerequisite program was not completed. You will need to restart your computer to complete that installation.'#13#13'After restarting your computer, Setup will continue next time an administrator logs in.'; 
    QuitMessageError = 'Error. Cannot continue.'; 

var 
    Restarted: Boolean; 

function InitializeSetup(): Boolean; 
begin 
    Restarted := ExpandConstant('{param:restart|0}') = '1'; 

    if not Restarted then begin 
    Result := not RegValueExists(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName); 
    if not Result then 
     MsgBox(QuitMessageReboot, mbError, mb_Ok); 
    end else 
    Result := True; 
end; 

function CheckDXVersion(const VerString: String): Boolean; 
var 
    MajorVer, MinorVer: Integer; 
    StartPos: Integer; 
    TempStr: string; 
begin 
    (* Extract major version *) 
    StartPos := Pos('.', VerString); 
    MajorVer := StrToInt(Copy(VerString, 1, StartPos - 1); 
    (* Remove major version and decimal point that follows *) 
    TempStr := Copy(VerString, StartPos + 1, MaxInt); 
    (* Find next decimal point *) 
    StartPos := Pos('.', TempStr); 
    (* Extract minor version *) 
    MinorVer := Copy(TempStr, 1, StartPos - 1); 
    Result := (MajorVer > 4) or ((MajorVer = 4) and MinorVer >= 9)); 
end; 

function DetectAndInstallPrerequisites: Boolean; 
begin 
    (*** Place your prerequisite detection and installation code below. ***) 
    (*** Return False if missing prerequisites were detected but their installation failed, else return True. ***) 

    //<your code here> 

    Result := True; 

    (*** Remove the following block! Used by this demo to simulate a prerequisite install requiring a reboot. ***) 
    if not Restarted then 
    RestartReplace(ParamStr(0), ''); 
end; 

function Quote(const S: String): String; 
begin 
    Result := '"' + S + '"'; 
end; 

function AddParam(const S, P, V: String): String; 
begin 
    if V <> '""' then 
    Result := S + ' /' + P + '=' + V; 
end; 

function AddSimpleParam(const S, P: String): String; 
begin 
Result := S + ' /' + P; 
end; 

procedure CreateRunOnceEntry; 
var 
    RunOnceData: String; 
begin 
    RunOnceData := Quote(ExpandConstant('{srcexe}')) + ' /restart=1'; 
    RunOnceData := AddParam(RunOnceData, 'LANG', ExpandConstant('{language}')); 
    RunOnceData := AddParam(RunOnceData, 'DIR', Quote(WizardDirValue)); 
    RunOnceData := AddParam(RunOnceData, 'GROUP', Quote(WizardGroupValue)); 
    if WizardNoIcons then 
    RunOnceData := AddSimpleParam(RunOnceData, 'NOICONS'); 
    RunOnceData := AddParam(RunOnceData, 'TYPE', Quote(WizardSetupType(False))); 
    RunOnceData := AddParam(RunOnceData, 'COMPONENTS', Quote(WizardSelectedComponents(False))); 
    RunOnceData := AddParam(RunOnceData, 'TASKS', Quote(WizardSelectedTasks(False))); 

    (*** Place any custom user selection you want to remember below. ***) 

    //<your code here> 

    RegWriteStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName, RunOnceData); 
end; 

function PrepareToInstall(var NeedsRestart: Boolean): String; 
var 
    ChecksumBefore, ChecksumAfter: String; 
begin 
    ChecksumBefore := MakePendingFileRenameOperationsChecksum; 
    if DetectAndInstallPrerequisites then begin 
    ChecksumAfter := MakePendingFileRenameOperationsChecksum; 
    if ChecksumBefore <> ChecksumAfter then begin 
     CreateRunOnceEntry; 
     NeedsRestart := True; 
     Result := QuitMessageReboot; 
    end; 
    end else 
    Result := QuitMessageError; 
end; 

function ShouldSkipPage(PageID: Integer): Boolean; 
begin 
    Result := Restarted; 
end; 
相關問題