sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Best way to preserve old configuration files and use in upgrade/update

Tue Aug 31, 2021 12:56 pm

I have built different installers for products and plugins, all of them have a lot of configurations, ports, URL, domains, special properties and all have been saved in the configuration file the idea is now is when doing update/upgrade to be able to use this old configuration files and to save the user from entering old settings.

Or when doing an upgrade/update if a user is using old configuration (ports, databases, server) to have a smooth upgrade without need a user to know anything about the configuration


The question is what is your suggestion for the best approach to accomplish this, how to preserve old files from the previous installer.

Regards
Last edited by sonda on Thu Sep 02, 2021 1:26 pm, edited 1 time in total.

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Wed Sep 01, 2021 11:03 am

Hi,
The question is what is your suggestion for the best approach to accomplish this, how to preserve old files from the previous installer.

To preserve the old files from the previous installation, just follow these steps:
  1. In the newer version of your project, go to the "Files and Folders" page.
  2. Select the file you want to preserve, right click → Properties.
  3. From the "Operations" tab, check the "Do not overwrite existing file" option and on "Condition" add:

    Code: Select all

     OLDPRODUCTS
    oldFile.png
    oldFile.png (36.68KiB)Viewed 13159 times
Let us know if this helped!

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Thu Sep 02, 2021 1:22 pm

Will be OLDPRODUCTS variable available/ fiiled if i use only Automatically upgrade older product version :
img_1.png
img_1.png (13.17KiB)Viewed 13110 times
or i will need also do set customized advanced installer upgrade rules OLDPRODUCTS variable to be filled?
img_2.png
img_2.png (17.75KiB)Viewed 13110 times

The idea is to preserve old configfile from the previous installation and when the upgrade is done if file is present just to skip all screens that asking for configurations, just installer simply change the rest of the files.


Regards

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Thu Sep 02, 2021 5:30 pm

Hello,

In the newer version, if i set do not overwrite i think it will not take effect because we have already doing uninstall the old version and the config file is deleted first and then the new installation is done with checking to overwrite and will not preserve old config file, old config file will be missing


Regards

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Fri Sep 03, 2021 9:54 am

Hi,
In the newer version, if i set do not overwrite i think it will not take effect because we have already doing uninstall the old version and the config file is deleted first and then the new installation is done with checking to overwrite and will not preserve old config file, old config file will be missing
If you set the "Do not overwrite" option, it will work. This way the old file will be backed-up before the old product being removed during the "Preparing" action group (more exactly during the "RemoveExistingProducts" action) and will be restored at the end.
The idea is to preserve old configfile from the previous installation and when the upgrade is done if file is present just to skip all screens that asking for configurations, just installer simply change the rest of the files.

Advanced Installer offers you multiple ways to preserve the user settings:

1. If you have access to the first version of the setup project (i.e. you did not released its build yet) you can follow these steps:

- go to the "Properties" page, check the "Show properties with empty value or used in dialog controls" option.

- for each property that you want to save, right click and check the "Set persistent property". If you enable this option, the property is stored in the registry and available during the upgrade installation.
persistent.jpg
persistent.jpg (42.45KiB)Viewed 12988 times


2. If you already released the first version, then in the newer version of your application you need to check the "Do not overwrite existing file" option with the "OLDPRODUCTS" condition for the setting file.

To skip all the dialogs that ask for configuration if the file exists go to the "Dialogs" page, right click on the dialog you want to skip if the file exists, and select "Show only if..". On "Expression" add "NOT OLDPRODUCTS".
showif.jpg
showif.jpg (93.41KiB)Viewed 12988 times
Attached is a sample project. When you install the setup a dialog will ask for your name and save it in a file. If you change the application version and install again the setup, the dialog is not displayed.

Hope this helps!

Best regards,
Liviu
Attachments
sample app.zip
(3.93KiB)Downloaded 242 times
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Fri Sep 03, 2021 4:55 pm

Hi Liviu

Thanks for your detailed answer I think with your guidance I succeed to achieve what I was expecting and for the start look good and working (i have attached my test) [attachment=0]MyTest.zip[/attachment)

I will start to edit the real project but just have another question before I proceed with implementing to the real project:

this is a clean and good implementation of what I want to achieve but let say what if I try to achieve the same behaviour with PowerShell custom action (copy to temp before the start and then return in the finish of installation) will be wrong (not sure if I will have success with this but just to have like an option in my mind)? (I know that sometimes antivirus can be alerting about executing PowerShell scripts) but just for information before I start, I want to know if doing the same with the PowerShell script will be bad implementation?


Many thanks and best regards
Attachments
MyTest.zip
(17.83KiB)Downloaded 264 times

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Mon Sep 06, 2021 8:08 am

Hi,

You can achieve what you want with a script too (PowerShell, VBScript). I just presented you the above solutions because they are easier to implement, but feel free to use your own custom script.

You can find more on our How To Backup and Restore Files during a Major Upgrade using Custom Actions article.

Also, you can check my answer on another forum thread here:
Reinstall BackupFolder
. There is an example using PowerShell for restoring files.

From what I can see in your attached project, you are using a .json file. For that, another solution is to uncheck “Remove only if it was created at install” option on the first version. For more information have a look on this forum thread Edit .json file on install which it may debates your subject.
json.png
json.png (25.51KiB)Viewed 12790 times

Hope this helps! If you have any other questions, please don't hesitate to contact us.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Thu Oct 07, 2021 3:10 pm

I have succeeded to make an upgrade of my normal installer and restoring old config files and everything seems ok for now.

But now I have my other installer with features and also I will need to apply the same. Users can choose to install feature One of feature Two or Feature Three when doing an upgrade I will need to detect which feature is installed and to run upgrade only on that feature.

Also if I use to show only if on ConfigureDlg Not OLDPRODUTS when an old product is detected I can't choose which features to be upgraded maybe that is ok but the problem is what will happen if, for example, I have installed Only a feature one on this machine and then I try to upgrade I don't want other features to be installed I want only existing feature to be upgraded.

So not sure how to detect if the feature is installed in the previous version and how to disable a feature to be installed in a new version when doing an upgrade if ConfigureDlg is not shown, I was looking at this blog post https://www.advancedinstaller.com/foru ... hp?t=10740 but I have an error when adding upgrade action also not sure how to execute MsiQueryFeatureState ( i was also doing this on dialogs by Feature example)
feature..png
feature..png (46.77KiB)Viewed 8743 times
also tried this but without success
feature1..png
feature1..png (63.44KiB)Viewed 8734 times
Any help appreciated
Regards

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Fri Oct 08, 2021 1:21 pm

Hello,

By default, this is already implemented. When you install for example, in version 1 only Feature3, then in version 2 that is detected. If you delete the "OptionalFeatsDlg" or "ConfigureDlg" dialog from the second version, the user can not change the features and will be updated only the Feature3 from the first version.

This is happening due to the "MigrateFeatureState" action, whose purpose is to take the state of the features from the old package and transfer that to the new package.

Attached is a sample project with v1 and v2 projects.

Open the v1 project, go to the "Files and Folders" page and see the 2 .txt files I added:
  • FeatureA_1.txt - for FeatureA
  • FeatureB_v1.txt - for FeatureB
Now, in the "Dialogs" page, you can see the "ConfigureDlg" dialog added, so the user can choose which Feature to install. You can also use the "OptionalFeatsDlg" dialog for features.

Build and run the package, choose "FeatureB" and finish the installation.

Now, open the v2 project, see that for the FeatureB I added another .txt file named "FeatureB_v2.txt".
I have installed Only a feature one on this machine and then I try to upgrade I don't want other features to be installed I want only existing feature to be upgraded.
Also from the "Dialogs" page I deleted the "ConfigureDlg" dialog and now the user can not change the Features when installing v2.

If you build and run the package you will see that only the files for the FeatureB are installed during upgrade.

Let me know if that helped you!

Best regards,
Liviu
Attachments
feature demo.zip
(8.22KiB)Downloaded 126 times
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Tue Oct 12, 2021 2:11 pm

Hi, thanks for your answer,

but what will happen if let say on the first installation I disable feature A and install only feature B, and in the update or version 2, I have a condition not to install feature B

I see that files from feature b are installed I have attached some modifications to your example so you can check.
So not sure how to prepare the condition if i detect that with that version feature B is not compatible to be in disabled state and files not to be added or copied. Also what will happen with uninstalling will be uninstalled process be affected with this kind installation?

2021_10_12_15_05_34_Window.png
2021_10_12_15_05_34_Window.png (100.78KiB)Viewed 7965 times
Regards
Attachments
feat.zip
(7.88KiB)Downloaded 104 times

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Wed Oct 13, 2021 9:33 am

Hi,
I see that files from feature b are installed I have attached some modifications to your example so you can check.
So not sure how to prepare the condition if i detect that with that version feature B is not compatible to be in disabled state and files not to be added or copied.
If you do not want to automatically migrate the feature and to conditionally install it in version 2, then you have to disable the “Enable Migrate Features action” option. But this is in contradiction with your previous request, first you wanted to automatically migrate the feature but now you do not want that, I’m a little bit confused.

The migration is happening due to the "MigrateFeatureState" action, whose purpose is to take the state of the features from the old package and transfer that to the new package.

In order to avoid this, please proceed as it follows:

  • In the newer version of your project:

    1. Go to the “Upgrades” page.
    2. Check the “Customize Advanced Installer upgrade rules” option from the “Application Versions” section.
    3. In the "Upgrades" table, double click on the upgrade code which has the property set to "OLDPRODUCTS".
    4. Select the “Upgrade Action” tab and uncheck the “Enable Migrate Features action” option.
    disableMigrate.png
    disableMigrate.png (39.29KiB)Viewed 7799 times
    Now, if you install the version 2 you attached, then your FeatureB will not be installed since the condition is “TEST = 1”.
Also what will happen with uninstalling will be uninstalled process be affected with this kind installation?
The uninstall process won't be affected by the Feature install condition. The setup package will uninstall as expected all the installed files.

Hope this helps!

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

sonda
Posts: 95
Joined: Mon Apr 30, 2018 12:01 pm

Re: Best way to preserve old configuration files and use in upgrade/update

Wed Oct 13, 2021 6:29 pm

Hi, an apology for the misunderstanding I will try to explain, the situation with a simple flow if I can:

But this is in contradiction with your previous request, first, you wanted to automatically migrate the feature but now you do not want that, I’m a little bit confused.
Let say on your computer you have powershell.exe 1.0

Now your installer v1.0 will install features: Feature A and Feature B on the machine (fracture b is working ok with PowerShell 1.0).
Version 2.0 will do an upgrade of your software (will skip all configurations and restore the old config) have also Feature A and Feature B but now in version 2.0 feature B is not compatible with PowerShell 1.0 and asking for a bigger version if you do an automatic upgrade Feature B will be installed but will be not functional since is asking for a bigger version of powershell.

This is a situation that I'm trying to resolve.

The best way is to stop the install process with some compatibility message, but I need to know that both features are selected not sure how to acquire this state with MsiQueryFeatureState on upgrade.

Sorry again for not be clear about the current situation I hope that now is more understanding.

Thanks for all help I really appreciated it.

Regards

Liviu
Posts: 199
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: Best way to preserve old configuration files and use in upgrade/update

Thu Oct 14, 2021 2:56 pm

Hello,
but I need to know that both features are selected not sure how to acquire this state with MsiQueryFeatureState on upgrade.
You can save the feature state in a persistent property when the first version is installed and check that property during the upgrade.

Another solution, which may be easier, is to use the "MsiQueryFeatureState" Windows Installer function to see the state a feature had in a specific version.

About how to use that function, you can have a look on the following article: Scripted check for a specific feature from an msi installer.

Hope this helps!

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”