2014-02-14 28 views
1

我已經構建了一個安裝程序來使用inno setup來安裝應用程序。但是我想顯示一條錯誤消息,顯示沒有足夠的空間驅動器或路徑,如果沒有可用空間,我將安裝應用程序。默認情況下,我收到inno內置的硬盤或選定路徑中沒有可用空間時顯示消息的功能。但它顯示YES和NO按鈕繼續或取消。在這裏,我想用OK按鈕顯示錯誤消息,當用戶單擊確定按鈕時,它應該停止安裝。請幫我解決這個問題。我找不到任何方法來這樣做。 我已經調用GetSpaceOnDisk64()和GetSpaceOnDisk()哪些不工作,並拋出異常如何使用inno安裝程序安裝程序檢查硬盤中是否有可用的空間來安裝應用程序

我得到的錯誤。請看看添附圖像enter image description here

+0

我已經運行在回答部分共享代碼和我連接錯誤在iamge – Axs

+0

請參閱[this comment](http://stackoverflow.com/questions/21700995/how-to-show-ok-button-only-in-message-box-when-there-is-not-enough-爲什麼Inno沒有使用致命的消息強制退出,因此您的[上一篇文章](http://stackoverflow.com/q/21700995/588306)會將這篇文章分爲以下幾個部分:空間到任務#comment32913347_21700995)。這很可能是錯誤的,在此時你的應用程序將拒絕安裝,直到它真正適合。 – Deanna

+0

@Deanna,如果用戶確認繼續而不需要再次啓動安裝程序,用戶將獲得足夠的時間獲得一些空間。 – TLama

回答

4

要確定特定文件夾的驅動器上的自由空間(在你的情況選擇的目錄),你可以調用GetSpaceOnDiskGetSpaceOnDisk64功能。它們之間的區別在於,第一個能夠以字節和兆字節返回空間信息。後者僅以字節返回此信息。對於下面的例子中,我選擇了第一個提到的功能,這樣你就可以在你想通過修改一個布爾參數來操作這臺決定:

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 

[Code] 
procedure ExitProcess(uExitCode: UINT); 
    external '[email protected] stdcall'; 

function IsEnoughFreeSpace(const Path: string; MinSpace: Cardinal): Boolean; 
var 
    FreeSpace, TotalSpace: Cardinal; 
begin 
    // the second parameter set to True means that the function operates with 
    // megabyte units; if you set it to False, it will operate with bytes; by 
    // the chosen units you must reflect the value of the MinSpace paremeter 
    if GetSpaceOnDisk(Path, True, FreeSpace, TotalSpace) then 
    Result := FreeSpace >= MinSpace 
    else 
    RaiseException('Failed to check free space.'); 
end; 

function NextButtonClick(CurPageID: Integer): Boolean; 
begin 
    Result := True; 

    if CurPageID = wpSelectDir then 
    begin 
    // the second parameter in this function call is the expected min. space in 
    // units specified by the commented parameter above; in this example we are 
    // checking if there's at least 1 MB of free space on drive of the selected 
    // directory; we need to extract a drive portion of the selected directory, 
    // because it's probable that the directory won't exist yet when we check 
    if not IsEnoughFreeSpace(ExtractFileDrive(WizardDirValue), 1) then 
    begin 
     MsgBox('There is not enough space on drive of the selected directory. ' + 
     'Setup will now exit.', mbCriticalError, MB_OK); 
     // in this input parameter you can pass your own exit code which can have 
     // some meaningful value indicating that the setup process exited because 
     // of the not enough space reason 
     ExitProcess(666); 
    end; 
    end; 
end; 
+0

我試過GetSpaceOnDisk()和GetSpaceOnDisk64()。兩者均返回錯誤消息爲「無法檢查可用空間」 – Axs

+1

此功能存在問題,您無法獲知失敗的原因。但是我在代碼中發現了一個問題,並且可能是你失敗的根源。檢查空間信息時,該目錄必須存在,因此如果您輸入的文件夾不存在,則失敗。我會馬上修復... – TLama

+0

已更新的修復程序不存在目錄。 – TLama

0

也許我的回答貌似跑題。 我有或多或少相同的問題。

如果你在files部分有一個自己做的檢查函數,setup只能計算那些具有「normal」檢查標記的文件的(兆)字節數。

避免這種情況的方法就是自己往上計數的字節,並把結果在ExtraDiskSpaceRequired指令中的[設置]部分

相關問題