Jacob Darka
Posts: 23
Joined: Mon Jun 24, 2019 7:26 pm

Installation Path Dialog

hello

I'm trying to add "Display an error if a specific file or subfolder does not exist in the installation path" to my project
which its guide is available in this tutorial "https://www.advancedinstaller.com/user- ... ialog.html" but sadly, it doesn't explain anything at all, it's just some basic text and that's it!
so for instance, my project is an add-on to a program, how do I make my project display an error if installed to a folder doesn't contain that program?

also I got a second-related question if that's okay!
some users might have that project installed in C:\Program Files\program, some may have it installed to custom path like D:\apps\program
is there any way to make my project automatically searches the user's pc for the program's path/location/folder and place it in the 'folder edit' box
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Installation Path Dialog

Hi,

First of all we apologize for the outdated article you linked to. We will try to update and better rewrite it in the future, thank you for bringing this to our attention.

Have a look over our "Install in another application's folder" and "Find the folder which contains a file" article which should help you implement the search for target program install folder requirement.

Also, to display an error when the selected install folder does not contain your target program you could:

1. implement our "How to browse for a folder at install time" article steps
2. create a custom action that get the path stored into the property (e.g. MY_DIR) used by the implementation form step 1 and search for target program file inside this folder location; if it is missing then the custom action could set an installer property (MISSING_PROP)
3. finally add on [Next] button a "Display a specific child dialog" event using the following condition

Code: Select all

MISSING_PROP
Hope this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Jacob Darka
Posts: 23
Joined: Mon Jun 24, 2019 7:26 pm

Re: Installation Path Dialog

I successfully implemented the "How to browse for a folder at install time" article steps, but I didn't quite understand
create a custom action that get the path stored into the property (e.g. MY_DIR)
sorry but I'm not quite expert in advanced installer yet, but what custom action should I create exactly? or did you mean the one that I created while implementing the previously mentioned article's steps?

also this sentence...
and search for target program file inside this folder location
did you mean that I should create a new search?
Last edited by Jacob Darka on Fri Nov 29, 2019 9:00 am, edited 1 time in total.
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Installation Path Dialog

Hello Jacob,
sorry but I'm not quite expert in advanced installer yet, but what custom action should I create exactly?
What my colleague Daniel meant is that you can create, for instance, a script (e.g. PowerShell, VBScript, C#) and add it in your project as a custom action. This script should get the value of your property (in this case, MY_DIR property) and check if a file exists inside that directory. This is what he meant by:
and search for target program file inside this folder location
For your reference, I have created a small PowerShell script which does what you need:

Code: Select all

# Block for declaring the script parameters.
Param()

# Your code goes here.

# this is added so we can use the MessageBox class. It was added for testing purposes only and can be removed
Add-Type -AssemblyName PresentationFramework

# use the AI_GetMsiProperty cmdlet to get the value of the MY_DIR property and then we store it in the $path variable
$path = AI_GetMsiProperty MY_DIR

# we display the path. Again, this is for testing purposes only and can be removed
[System.Windows.MessageBox]::Show($path)

# the path we have earlier stored is a path to a directory. In this case, we will need the full path to a file, therefore we have to append the file name
# at the end of the path. To do so, we can use the Join-Path cmdlet
$fullPath = Join-Path -Path $path -ChildPath your_file.extension

# we display the full path
[System.Windows.MessageBox]::Show($fullPath)

# we test the full path using the Test-Path cmdlet. This returns True if the path exists and False otherwise.
$test_response = Test-Path -Path $fullPath

# we display the test response. This can be removed after testing is done
[System.Windows.MessageBox]::Show($test_response)

# I think that here, you may need only the else statement. Basically you only want to check if the file DOES NOT exist
if ($test_response -eq $true){
# this means the file is not missing
[System.Windows.MessageBox]::Show("The file is not missing")
}
else {
# this means the file is missing, therefore we should set the property, as explained by my colleague
AI_SetMsiProperty MISSING_PROP true
}


This custom action can be added in Advanced Installer as a "Run Inline PowerShell script" custom action.

Now, after executing this custom action, if the file does not exist ==> the property will be set (the MISSING_PROP) and you will be able to use that as a condition, as explained by my colleague Daniel.

Hope this helps and things are clearer for you now.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Jacob Darka
Posts: 23
Joined: Mon Jun 24, 2019 7:26 pm

Re: Installation Path Dialog

Thank you Catalin for making it clearer, but there's still one little thing, I created that custom action, but I can't add it correctly to the project, I tried the following:

1- Add it as a custom action with sequence after wizard dialogs stage > installdlg.
When I press the install button, the custom action works and the custom message appears {which says "true" or "false"}, however, it just proceeds to install whether the property is set to MISSING_PROP or not.


2- Add it as a custom action without sequence and add on the "Next" button the published event "Execute custom action", and the control conditions > MISSING_PROP = disable, NOT MISSING_PROP = Enable.
When I press the "Next" button, the custom action occurs, however, if the property is set to MISSING_PROP {the provided path does not contain the "your_file.extension"}, the button will always be disabled, whether if I changed the path to the correct one or not.


Then how can I implement this PowerShell script custom action correctly to the project?
Note: I tried to add on the "Next" button a "Display a specific child dialog" event using the "MISSING_PROP" condition as Daniel instructed, but it doesn't do anything on my end.
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Installation Path Dialog

Hello Jacob,

First of all, please accept my apologies for the delayed reply.

Here, I think that you may proceed as it follows:

- add the script on the "Next" button of the "FolderDlg" dialog.

- now, on the same "FolderDlg", please add, on the "Next" button, the event as described by my colleague Daniel. The condition to this should be the MISSING_PROP property which is set by the custom action.

In what regards the sequence, the custom action event must be the first in the list, while the "Display a specific child dialog" event must be the last in the list.
sequence.png
sequence.png (184.29 KiB) Viewed 5088 times

Additionally, if you expand "FolderDlg", you will then be able to see the child dialog and further edit it. For instance, you can display a message to the user.


Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”