At times, we need Custom Functions (over & above the InstallShield's default behaviour) to check the availability of disc space before proceeding with the installation. Here is the code sample for the same.
///////////////////////////////////////////////////////////////////////////////
// FUNCTION: CheckRequiredSpace
// Purpose: Performs space requirements check for selected targetdir.
///////////////////////////////////////////////////////////////////////////////
function CheckRequiredSpace()
STRING svRequired;
BOOL bCheck;
NUMBER nResult, nvTotalRequiredSpace, nvTotalAvailableSpace;
begin
//Get total required disk space
nResult = FeatureGetTotalCost(MEDIA, TARGETDIR, nvTotalRequiredSpace);
if (nResult < 0) then
return -1;
endif;
//Add 10000 KB as safety buffer to required space
nvTotalRequiredSpace = nvTotalRequiredSpace + 10000;
//Get total available disk space
nvTotalAvailableSpace = GetDiskSpaceEx(TARGETDIR, KBYTES);
if (nResult < 0) then
return -1;
endif;
//Convert nvTotalRequiredSpace to string
NumToStr(svRequired, nvTotalRequiredSpace);
//Check if there is enough space available
if (nvTotalRequiredSpace > nvTotalAvailableSpace) then
MessageBox(@CheckRequiredDiskSpace_Error + svRequired + " KB", WARNING);
return 0;
endif;
return 1;
end;
This function applies to Pure InstallScript & InstallScript MSI Projects.
thank you so much, you saved my time...
ReplyDeleteGlad to hear that it was helpful, Dhanaraj.
ReplyDeleteRegards
Bhuvana