admin 发表于 2017-3-6 18:46:13

安装空间不足屏蔽下一步按钮

; 脚本用 Inno Setup 脚本向导 生成。
; 查阅文档获取创建 INNO SETUP 脚本文件的详细资料!

#define MyAppName "我的程序"
#define MyAppVersion "1.5"
#define MyAppPublisher "我的公司"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

#define NeedSize "60000"
#define AfterSize "5871"
#define NeedMem "512"
#define Color "000000"




; 注意: AppId 的值是唯一识别这个程序的标志。
; 不要在其他程序中使用相同的 AppId 值。
; (在编译器中点击菜单“工具 -> 产生 GUID”可以产生一个新的 GUID)
AppId={{86EB5FFA-D719-4B91-AD87-25AAFCEE7B3F}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes


Name: "default"; MessagesFile: "compiler:Default.isl"


Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked


Source: "D:Program FilesInno Setup 5ExamplesMyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; 注意: 不要在任何共享的系统文件使用 "Flags: ignoreversion"


Name: "{group}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"
Name: "{commondesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: desktopicon


Filename: "{app}{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent


FreeSpace=剩余空间
NeedSpace=安装所需
AfterInstallSpace=当前分区可用空间
TotalSpace=当前分区总容量



var
NeedSpaceLabel, FreeSpaceLabel,TotalSpaceLabel,DirEditLabel: TLabel;
FreeMB, TotalMB: Cardinal;
SizeInt, AfterInt: Longint;

//procedure DirChange(Sender: TObject);
//var
// CurrentDisk: String;
//begin
//CurrentDisk:=ExtractFileDrive(WizardForm.DirEdit.Text);
//DirEditLabel.Caption:=MinimizePathName(WizardForm.DirEdit.Text, DirEditLabel.Font, DirEditLabel.Width);
//end;

Function NumToStr(Float: Extended): String;
Begin
Result:= Format('%.2n', ); StringChange(Result, ',', ',');
while ((Result = '0') or (Result = ',')) and (Pos(',', Result) > 0) do
SetLength(Result, Length(Result)-1);
End;

function CompareNum(FirstNum, SecondNum: Integer): Boolean;
begin
if FirstNum < SecondNum then Result:= False else Result:= True;
end;

Function MbOrTb(Byte: Extended): String;
begin
if Byte < 1024 then Result:= NumToStr(Byte) + 'TB' else
if Byte/1024 < 1024 then Result:= NumToStr(round(Byte/1024*100)/100) + ' GB' else
   Result:= NumToStr(round((Byte/(1024*1024))*100)/100) + ' MB'
end;

procedure DirEditOnChange(Sender: TObject);
var Drive: String;
begin
// DirEditLabel.Caption:=MinimizePathName(WizardForm.DirEdit.Text, DirEditLabel.Font, DirEditLabel.Width);
Drive:= ExtractFileDrive(WizardForm.DirEdit.Text);
GetSpaceOnDisk(Drive, True, FreeMB, TotalMB);
    TotalSpaceLabel.Caption:= ExpandConstant('{cm:TotalSpace} ')+MbOrTb(TotalMB);
    FreeSpaceLabel.Caption:= ExpandConstant('{cm:FreeSpace} ') + MbOrTB(FreeMb) + ' (' + IntToStr((FreeMb*100) div TotalMB) + ' %)';
    NeedSpaceLabel.Caption := ExpandConstant('{cm:NeedSpace} ') + MbOrTb(SizeInt)
    if (FreeMB>{#NeedSize}) then FreeSpaceLabel.Font.Color:=${#Color} else FreeSpaceLabel.Font.Color:=$0000FF;
//if WizardForm.CurPageID = wpSelectDir then begin
//if(FreeMB>{#NeedSize}) then begin
WizardForm.NextButton.Enabled:= (FreeMB>{#NeedSize});
//BtnSetEnabled(hNextBtn, True);
//WizardForm.NextButton.Enabled:=True;
//end else begin
//WizardForm.NextButton.Enabled:= (FreeMB>{#NeedSize});
//BtnSetEnabled(hNextBtn, False);
//    WizardForm.NextButton.Enabled:=False;
//end;
//end;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
if WizardForm.CurPageID = wpSelectDir then
    WizardForm.NextButton.Enabled:= (FreeMB>{#NeedSize});
end;


procedure NeedSpace;
begin
WizardForm.DiskSpaceLabel.Hide;
AfterInt:= {#AfterSize}
SizeInt:= {#NeedSize}

TotalSpaceLabel:= TLabel.Create(WizardForm);
TotalSpaceLabel.Transparent:=true;
TotalSpaceLabel.Font.Name:='Arial';
TotalSpaceLabel.Font.Size:= 10;
TotalSpaceLabel.Font.Color:=${#Color};
//TotalSpaceLabel.SetBounds(ScaleX(253),ScaleY(260), ScaleX(209), ScaleY(13));
TotalSpaceLabel.SetBounds(ScaleX(0),ScaleY(159), ScaleX(209), ScaleY(13));
TotalSpaceLabel.Parent:= WizardForm.SelectDirPage;
//TotalSpaceLabel.Parent:= WizardForm;
TotalSpaceLabel.Font.Style := ;

FreeSpaceLabel := TLabel.Create(WizardForm);
//FreeSpaceLabel.SetBounds(ScaleX(253), ScaleY(276), ScaleX(209), ScaleY(13))
FreeSpaceLabel.SetBounds(ScaleX(0), ScaleY(179), ScaleX(209), ScaleY(13))
//FreeSpaceLabel.Parent := WizardForm;
FreeSpaceLabel.Parent:= WizardForm.SelectDirPage;
FreeSpaceLabel.Font.Name:='Arial';
FreeSpaceLabel.Font.Size:= 10;
FreeSpaceLabel.Font.Color:=${#Color};
FreeSpaceLabel.Transparent:=true;
FreeSpaceLabel.Font.Style := ;

NeedSpaceLabel := TLabel.Create(WizardForm);
//NeedSpaceLabel.SetBounds(ScaleX(253), ScaleY(292), ScaleX(209), ScaleY(13))
NeedSpaceLabel.SetBounds(ScaleX(0), ScaleY(199), ScaleX(209), ScaleY(13))
//NeedSpaceLabel.Parent := WizardForm;
NeedSpaceLabel.Parent:= WizardForm.SelectDirPage;
NeedSpaceLabel.Font.Name:='Arial';
NeedSpaceLabel.Font.Size:= 10;
NeedSpaceLabel.Font.Color:=${#Color};
NeedSpaceLabel.Transparent:=true;
NeedSpaceLabel.Font.Style:= ;

WizardForm.DirEdit.OnChange:= @DirEditOnChange;
WizardForm.DirEdit.Text:= WizardForm.DirEdit.Text + #0;
end;

procedure InitializeWizard();
begin
    NeedSpace;
end;
页: [1]
查看完整版本: 安装空间不足屏蔽下一步按钮