Display the previous value during upgrade - Advanced Installer Community
hsc
Posts: 117
Joined: Wed Mar 02, 2016 2:55 pm

Display the previous value during upgrade

Hi,
I created an installation package that asks the user to enter a remote computer name, and then uses the entered name to create an entry in an XML file. During first installation, this name defaults to "localhost"; thus, if the user doesn't change anything, the XML file contains "localhost", or otherwise, it contains the user's text. This works fine.
During an upgrade installation, this same mechanism is applied, so again, the user can enter their choice, and it is written to the XML file. This is intended because it is well possible that the user wants to pick a different remote computer during the upgrade process. However, I would like to have the previous value, which can be read from the XML file, as default which is presented to the user when the respective dialog is displayed. Any ideas on how to achieve this?

Thanks
Hans
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Display the previous value during upgrade

Hello Hans,

I think that you can achieve this through an "XML Search" and then use the search property's value in your dialog.

Hope this helps.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
hsc
Posts: 117
Joined: Wed Mar 02, 2016 2:55 pm

Re: Display the previous value during upgrade

Hi Catalin,

thank you for your reply. This is the first time I use XML search.

The example from the manual uses an XML file where all tags are different. In my case, I have several tags with identical names. Written as an XPath, the text I want to look up is

Code: Select all

/configuration/applicationSettings/RoadService.Properties.Settings/setting[@name="WorkerLoggingPath"]/value/text()
(This is a compiler-generated .NET configuration file. It has lots of "setting" elements with different "name" attributes, and each "setting" has a "value" sub-element.)

I am at loss about how to specify this in the XML Search. Especially the selection by attribute value...

Best
Hans
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Display the previous value during upgrade

Hello Hans,

Unfortunately, our XML Search does not support searching for an xPath. However, you can achieve that through a custom action. For instance, you can use a PowerShell script. Here is a PowerShell script which you can use to achieve what you want:

Code: Select all

[XML]$appConfigFile = Get-Content -Path "PathToYourConfig\RoadService.exe.config"
$appConfigFile | Select-Xml -XPath "/configuration/applicationSettings/RoadService.Properties.Settings/setting[@name=""WorkerLoggingPath""]/value/text()"
Write-Host "$appConfigFile"
Searches are executed at the beginning of the installation, during the "Searches" action group ("Custom Actions" page). With that being said, in order to imitate the behavior of your search, please schedule it before the "Searches" action group.

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
hsc
Posts: 117
Joined: Wed Mar 02, 2016 2:55 pm

Re: Display the previous value during upgrade

Thanks Catalin,
this solved my problem. Let me post a follow-up for the sake of others who may want to do the same.

I created a non-sequenced "run PowerShell inline script" custom action, and then I hooked execution of this script into an Init event of the first dialog where the data is required. I did this because I wanted to make sure that all variables are already initialized, which obviously is the case when the dialog is opened.

The script contains, in essence, the following code:

Code: Select all

# create a messagebox for testing and debugging (to be removed for the productive version)
Add-Type -AssemblyName System.Windows.Forms | Out-Null
[System.Windows.Forms.MessageBox]::Show("Hello it's me")

$appFolder = AI_GetMsiProperty APPDIR
$configFile = $appFolder + "myfile.exe.config"
if (($appFolder -ne "") -and (test-path "$configFile"))
{
  [xml] $oldConfig = Get-Content -Path "$configFile"
  $value = select-xml $oldConfig -XPath "/configuration/applicationSettings/myapp.Properties.Settings/setting[@name='mysetting1']/value"
  AI_SetMsiProperty MYSETTING1 $value.ToString()
  $value = select-xml $oldConfig -XPath "/configuration/applicationSettings/myapp.Properties.Settings/setting[@name='mysetting2']/value"
  AI_SetMsiProperty MYSETING2 $value.ToString()
  # etc.
}
The MYSETTING1 and MYSETTING2 properties are connected to the text edit fields in the dialog.
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Display the previous value during upgrade

Hello Hans,

Thank you for your followup on this and for contributing to our forums. I am sure this will be of help for further users facing a same scenario as you.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”