Hi, often we need in our installer projects to calculate the disk space on the target machine.
Below code can be edited for this purpose:
function DiskSpace(hMSI)
NUMBER n;
STRING szAvailableSpace;
NUMBER nUnitUsed,nNum,nLocation;
BOOL bReq;
STRING sLoc;
begin
nUnitUsed = GBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1) then
nUnitUsed=MBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1024) then
nUnitUsed=KBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1048576) then
nUnitUsed=BYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit(BYTES ); //
MessageBox("Available space--> "+szAvailableSpace,TRUE);
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
endif;
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( KBYTES );
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
else
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( MBYTES );
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
endif;
endif;
//////////////
nLocation = StrFind (szAvailableSpace, ".");
NumToStr(sLoc,nLocation);
StrSub(szAvailableSpace,szAvailableSpace,0,2);
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( GBYTES );
//MessageBox("Available space--> "+szAvailableSpace,TRUE);
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
end;
Below code can be edited for this purpose:
function DiskSpace(hMSI)
NUMBER n;
STRING szAvailableSpace;
NUMBER nUnitUsed,nNum,nLocation;
BOOL bReq;
STRING sLoc;
begin
nUnitUsed = GBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1) then
nUnitUsed=MBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1024) then
nUnitUsed=KBYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
StrToNum(nNum,szAvailableSpace);
if(nNum<1048576) then
nUnitUsed=BYTES;
ISRT._GetDiskSpaceExEx(INSTALLDIR,szAvailableSpace,nUnitUsed,TRUE,TRUE);
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit(BYTES ); //
MessageBox("Available space--> "+szAvailableSpace,TRUE);
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
endif;
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( KBYTES );
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
else
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( MBYTES );
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
endif;
endif;
//////////////
nLocation = StrFind (szAvailableSpace, ".");
NumToStr(sLoc,nLocation);
StrSub(szAvailableSpace,szAvailableSpace,0,2);
szAvailableSpace = szAvailableSpace + " " + StrConvertSizeUnit( GBYTES );
//MessageBox("Available space--> "+szAvailableSpace,TRUE);
MsiSetProperty(hMSI,"DISKSPACE",szAvailableSpace);
end;