要確定特定文件夾的驅動器上的自由空間(在你的情況選擇的目錄),你可以調用GetSpaceOnDisk
或GetSpaceOnDisk64
功能。它們之間的區別在於,第一個能夠以字節和兆字節返回空間信息。後者僅以字節返回此信息。對於下面的例子中,我選擇了第一個提到的功能,這樣你就可以在你想通過修改一個布爾參數來操作這臺決定:
[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;
我已經運行在回答部分共享代碼和我連接錯誤在iamge – Axs
請參閱[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
@Deanna,如果用戶確認繼續而不需要再次啓動安裝程序,用戶將獲得足夠的時間獲得一些空間。 – TLama