Check File exists before copy - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Check File exists before copy

I have a package which has multiple features, including one which needs to copy a file specified by the user using the installation GUI. I am struggling to check the file exists and copy it as part of the feature. This is what I have so far:
  • I have 2 install parameters; "LICENSEFILE" (the name of the license file) and "LICENSEDIR" (the source folder where the license is normally found when the installation begins. Both contain default values.
  • In the "Begin" action of both the "InstallUISequence" and "InstallExecuteSequence", I have a "Property set with Formatted" action which sets the "LICENSEDIR" value to the "[SETUPEXEDIR]License\[LICENSEFILE]" resolved value.
  • I have a "File To Search" search called "LICENSEFILE_EXISTS" to search for the file "[SETUPEXEDIR]License\[LICENSEFILE]".
  • I have a custom dialog in the "First Time Install" list. This has the following controls:
    - a PathEdit control for the "LICENSEDIR" property
    - a Browse button with 2 Published Events; "[_BrowseProperty]" event with "LICENSEDIR" argument, then a "SpawnDialog" event with "BrowseDlg" argument.
    - a Next button with 2 Control Conditions; "NOT LICENSEFILE_EXISTS" condition with "Disable" action, and "LICENSEFILE_EXISTS" condition with "Enable" action.
  • I have followed the instructions on how to install a user specific file (http://www.advancedinstaller.com/user-g ... -file.html) and have a "File Copy/Move" item in the "Files and Folders" list.
The problems I need help to solve:
  • 1. When my custom dialog is displayed, the Next button is disabled even though the file searched for by "LICENSEFILE_EXISTS" exists. It appears the "LICENSEFILE_EXISTS" search does not work?
  • 2. After the user has clicked the Browse button, the "LICENSEDIR" property is updated and the value displayed in the PathEdit control. An automated check then needs to be performed to check that the file specified by the updated "[LICENSEDIR][LICENSEFILE]" resolved value exists, so that the Next button is then enabled. How do I achieve this?
  • 3. The "File Copy/Move" should only be performed IF one of my features is being installed, otherwise it should not be performed. How do I make this file copy specific to only one of my features?
Please be specific in instructions.
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: Check File exists before copy

ash_microsec wrote: 3. The "File Copy/Move" should only be performed IF one of my features is being installed, otherwise it should not be performed. How do I make this file copy specific to only one of my features?
It appears that the "File Copy/Move" item is added as an item in the Organisation's Features and Components list when it is created, although the location appears to be random as it was included as part of an existing component (I only found the "File Copy/Move" item when I expanded all the items in the Organization's Features and Components list). I have now moved this item under the appropriate feature, so that should now mean it is only performed if the feature is installed.

1 down, 2 solutions to find...
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Check File exists before copy

Hi,
1. When my custom dialog is displayed, the Next button is disabled even though the file searched for by "LICENSEFILE_EXISTS" exists. It appears the "LICENSEFILE_EXISTS" search does not work?
Can you add an edit box on this dialog and attach to it the property "LICENSEFILE_EXISTS", to see its value. Maybe something is changing it along the way. Also a verbose log can give us more details.
2. After the user has clicked the Browse button, the "LICENSEDIR" property is updated and the value displayed in the PathEdit control. An automated check then needs to be performed to check that the file specified by the updated "[LICENSEDIR][LICENSEFILE]" resolved value exists, so that the Next button is then enabled. How do I achieve this?
For this you will need to add a UI Custom Action on the "OK" button that appears in BrowseDlg dialog. After you select the file and press the button OK to validate it the custom action should be triggered.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: Check File exists before copy

Thanks for your replay, Bogdan.
Bogdan wrote:
2. After the user has clicked the Browse button, the "LICENSEDIR" property is updated and the value displayed in the PathEdit control. An automated check then needs to be performed to check that the file specified by the updated "[LICENSEDIR][LICENSEFILE]" resolved value exists, so that the Next button is then enabled. How do I achieve this?
For this you will need to add a UI Custom Action on the "OK" button that appears in BrowseDlg dialog. After you select the file and press the button OK to validate it the custom action should be triggered.
Does this not require a custom implementation of the BrowseDlg? If I add it to the standard BrowseDlg listed under my custom dialog, then it affects all instances where the BrowseDlg is used.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Check File exists before copy

Hi,

You can very easily set a condition on the published event that you set on the OK button from the BrowseDlg. This condition should be true only when you browse for the license file, for example a property
that is set to a certain value only when you enter the dialog where the user selects the license file, i.e. the one preceding BrowseDlg.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: Check File exists before copy

Following on from Bogdan's suggestion, I have created a custom dialog called "LicenseBrowseDlg" wchi is a duplicate of BrowseDlg. So what do I need to put on the OK button's published events to get the LICENSEFILE_EXISTS search to be updated?
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Check File exists before copy

Hi,
So what do I need to put on the OK button's published events to get the LICENSEFILE_EXISTS search to be updated?
I'm afraid you will need to make your own custom action, for example a VBScript or C++ DLL, that verifies the path. You cannot trigger a search to be executed at a certain moment.

All searches are executed during the standard action AppSearch, you cannot use a published event to trigger the execution of this standard action. This standard action is executed automatically by Windows Installer.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ash_microsec
Posts: 38
Joined: Thu Dec 16, 2010 9:35 am
Location: Emsworth

Re: Check File exists before copy

An update on progress:
ash_microsec wrote: 1. When my custom dialog is displayed, the Next button is disabled even though the file searched for by "LICENSEFILE_EXISTS" exists. It appears the "LICENSEFILE_EXISTS" search does not work?
This was a sneaky one. My Next button had 2 control coditions, "LICENSEFILE_EXISTS" and "NOT LICENSEFILE_EXISTS". This was incorrect. The control conditions needed to be "LICENSEFILE_EXISTS = 1" and "LICENSEFILE_EXISTS = 0". The Next button was then correctly enabled/disabled when the dialog was first displayed.
ash_microsec wrote: 2. After the user has clicked the Browse button, the "LICENSEDIR" property is updated and the value displayed in the PathEdit control. An automated check then needs to be performed to check that the file specified by the updated "[LICENSEDIR][LICENSEFILE]" resolved value exists, so that the Next button is then enabled. How do I achieve this?
This took what I consider to be a hack to get it working. Firstly, I created my own copy of the BrowseDlg so I could change it without breaking anything else (and when I set the "Property Name" to "_BrowseProperty" on the "Directory Combo", "Directory List" and "Path Edit", it worked like the original).

On the OK button, I had 3 events:

1. "DoAction" event with "CheckLicenseFileExists" argument (vb script).
2. "SetTargetPath" event with "[_BrowseProperty]" argument for the "LICENSEFILE_EXISTS = 1" condition.
3. "EndDialog" event with "Return" argument for the "LICENSEFILE_EXISTS = 1" condition.

On the Cancel button, I had 3 events:

1. "Reset" event with "0" argument.
2. "DoAction" event with "CheckLicenseFileExists" argument (vb script).
3. "EndDialog" event with "Return" argument.

My "CheckLicenseFileExists" script is as follows:

Code: Select all

Function checkLicenseFileExists()

    dim license_file
    license_file = Session.Property("LICENSEDIR")
    If Right(license_file, 1) = "\" Then
        license_file = license_file & Session.Property("LICENSEFILE")
    Else
        license_file = license_file & "\" & Session.Property("LICENSEFILE")
    End If

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(license_file) Then
        Session.Property("LICENSEFILE_EXISTS") = "1"
    Else
        Session.Property("LICENSEFILE_EXISTS") = "0"
        MsgBox "Selected folder must contain the '" & Session.Property("LICENSEFILE") & "' license file." & vbCrLf & vbCrLf & "Please select a valid folder.",vbOKOnly,"Invalid License Folder"
    End If
    checkLicenseFileExists = 1 ' msiDoActionStatusSuccess
End Function
This provides the following behaviour:
  • When the Cancel button is pressed, the Browse dialog is closed.
  • When the OK button is pressed and an invalid folder has been specified, the script fails to find the file and displays a popup message is displayed. When closed, the Browse dialog is not closed.
  • When the OK button is pressed and a valid folder has been specified, the Browse dialog is closed.
The Next button is enabled/disabled based upon the value the script set the "LICENSEFILE_EXISTS" property to.

Return to “Common Problems”