2012-10-18 49 views
9

我需要安裝程序檢查目標位置是否存在文件,如果不存在,則安裝將中止。我的項目是一個更新補丁,因此如果應用程序的主要exe文件不在目標中,我希望安裝程序避免安裝更新文件。我怎樣才能做到這一點?Inno Setup - 檢查文件是否存在於目標位置,或者如果不中止安裝

有人可以舉一個代碼示例來檢查通過Windows註冊表的文件版本嗎?

[Files] 
Source C:\filename.exe; DestDir {app}; Flags: ignoreversion; BeforeInstall: CheckForFile; 

[code] 

procedure CheckForFile(): Boolean; 
begin 
    if (FileExists('c:\somefile.exe')) then 
    begin 
    MsgBox('File exists, install continues', mbInformation, MB_OK); 
    Result := True; 
    end 
    else 
    begin 
    MsgBox('File does not exist, install stops', mbCriticalError, MB_OK); 
    Result := False; 
    end; 
end; 
+1

通常情況下,更新安裝,你只需要使用相同的AppID,以及創新科技將處理剩下的給你。有關更多詳細信息,請參閱[本文](http://www.vincenzo.net/isxkb/index.php?title=Upgrades)。 – Deanna

回答

10

只是不讓用戶繼續,直到他們選擇正確的文件夾。

function NextButtonClick(PageId: Integer): Boolean; 
begin 
    Result := True; 
    if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\yourapp.exe')) then begin 
     MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK); 
     Result := False; 
     exit; 
    end; 
end; 

當然,這也是一個好主意,嘗試自動選擇正確的文件夾,對他們來說,如。通過從註冊表中檢索正確的位置。

+0

這對我來說很完美......謝謝! – Dielo

+0

那麼你應該[接受答案](http://meta.stackexchange.com/a/5235/179541)。無論如何,你說過你想在你的問題中放棄安裝。那麼,沒關係...... – TLama

+0

這實際上是一箇中止。對於交互式安裝,除了糾正路徑或取消之外,它不會給用戶任何其他選項。對於非交互式(無聲)安裝,它只會中止。 (雖然在那個筆記上,如果你期待沉默的安裝,你應該使用'SuppressibleMsgBox'代替。) – Miral

3

另一種解決辦法是InitializeSetup()

信用:Manfred

[code] 
    function InitializeSetup(): Boolean; 
    begin 
    if (FileExists(ExpandConstant('{pf}\{#MyAppName}\somefile.exe'))) then 
    begin 
     MsgBox('Installation validated', mbInformation, MB_OK); 
     Result := True; 
    end 
    else 
    begin 
     MsgBox('Abort installation', mbCriticalError, MB_OK); 
     Result := False; 
    end; 
    end; 
相關問題