PDA

View Full Version : Copy files into D drive or C drive based on availability of D drive.



PavanKumar1234
09-12-2013, 02:57 AM
Our Requirment:

1. Check if D: drive is present or not.
2. If present, then copy files into D:\Folder1 or else into C:\Folder1

I tried copying files using Files & Folders section. But there was no way over there to acheive the desired conditional copying.

Thanks,
Pavan

ITI_Randy
09-16-2013, 09:07 AM
Our Requirment:

1. Check if D: drive is present or not.
2. If present, then copy files into D:\Folder1 or else into C:\Folder1

I tried copying files using Files & Folders section. But there was no way over there to acheive the desired conditional copying.

Thanks,
Pavan


Go to the direct editor Directory table and add a folder for something like "CUSTOMVOLUME" and set the Directory_Parent to WindowsVolume as the default value.

You will need to check for a valid disk that is static, so you'll want a function to verify that there is a static D drive available, something like -

prototype BOOL IsValidDisk(HWND, STRING);

function BOOL IsValidDisk(hMSI, sDisk)
STRING sTestVolume;
BOOL isValid;
NUMBER nResult;
begin
try
isValid = FALSE;
sTestVolume = sDisk + ":";
if (GetSystemInfo (DRIVE, nResult, sTestVolume) >= 0) then
//IS_FIXED = 4, IS_CDROM = 6
if (nResult = IS_FIXED) then //Dirve is fixed
isValid = TRUE;
endif;
endif;
return isValid;
catch
endcatch;
end;

You'll need a method to check and set the disk, something like -

export prototype SetCustomDir(HWND);

function SetCustomDir(hMSI)
begin
//Disk is WindowsVolume by default,
//but if available, switch to D:\
if IsValidDisk(hMSI, "D:") then
MsiSetTargetPath(hMSI, "CUSTOMVOLUME", "D:\\");
endif;
end;

Any component with a root value of [CUSTOMVOLUME] will get the path you set in your custom action. You can set the InstallDir in your general properties to have a value of [CUSTOMVOLUME] if you wish, which will send everything to that drive. (Note that when you switch the InstallDir to [CUSTOMVOLUME] and click away from it, it will show WindowsVolume, indicating that the value equates to the default WindowsVolume, but this will change when the custom action runs if a static D: drive is available.

One final thing, schedule your customer to run at the appropriate time -

In the UI Sequence, run it early after CostFinalize
In the Execute sequence, After InstallValidate (condition: REMOVE <> "ALL")
Immediate Execution, Execute Only Once