Hello Simon,
Unfortunately, I was ill last week, so I couldn't test your solution.
No worries about this. I hope you feel better now.
I am really glad the solution worked for you.
Now let's address your issue. Indeed, if the file is not present, then the PowerShell script will fail (this is the expected behavior).
1. Look for the file and parse the path
In what regards the first part of the problem, could you please give me some more details as to how you would like to look for the file? Here, I would say that we should be pretty straightforward.
Since the setup installs your configuration file, I believe we should straight up test that location, instead of doing a recursive search (which will take a lot of time - i.e. search for your file in the entire C:\ directory).
Please let me know if you see anything wrong with this approach. If not, let's get started:
We can test if a file exist by using the
"Test Path" cmdlet. Here is how we can achieve this:
Code: Select all
$path = "C:\Users\Catalin\Desktop\testFile.txt"
Test-Path -Path $path
If the file exists, the above should return $true, otherwise it should return $false. To verify such a condition, we can proceed as it follows:
Code: Select all
if ((Test-Path -Path $path) -eq $true){
#do-something
}
In what regards the parsing part, could you please give me some more details about it, as I am not quite sure how you would like to parse it.
2. If the file is not available copy a certain file to a default path (e.g. C:\Temp)
For this, please refer to what I've written above, as I believe that will help.
In what regards the copying of a file, there are two ways that I can think of:
1. you can use the
"Copy-Item" cmdlet. This can look something similar to this:
Code: Select all
Copy-Path -Path "your_path_here" -Destination "your_destination_here"
2. you can use our predefined support
Temporary Files. Temporary files are files that are copied on the machine at the beginning of an installation and deleted at the end of it.
Temporary files location is the %temp% folder, which resolves to:
%windowsvolume%\Users\<username_here>\AppData\Local\Temp
Here is how we can achieve what you need:
We will add the file you want to be copied as a temporary file in the
"Files and Folders" page (using the
"Add temporary file" button from the ribbon). After doing so, if you double click on it, you will notice that it has a
"Condition" field. We can condition this based on the result of our custom action. Here is how your script may look like:
Code: Select all
if(your_condition -eq $true){
# we set an installer property that we will use for our condition
AI_SetMsiProperty YOUR_PROPERTY "YourPropertyValue"
}
The condition for your temporary file may look like this:
Code: Select all
YOUR_PROPERTY = "YourPropertyValue"
In this case, the custom action should take place before the files are copied in the temporary location (this happens during the
"CostFinalize" standard action -->
"Paths Resolution" action group)
3. If the path could be extracted, copy a certain file to the extracted path
Not quite sure I understand what you want to achieve here. Would be gread if you could give me some more details so I can better understand this.
Also, least but not last (because I forgot to mention this in my last thread) - we will start working on a method that will allow you to achieve your scenario much easier (without having to work it around using a custom action). I will update this thread as soon as that improvement will be added to Advanced Installer.
Hope this helps.
Best regards,
Catalin