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!

csoltenborn
Posts: 9
Joined: Wed Nov 20, 2019 1:05 pm

Checking for existence of file in [APPDIR]

Hi,

during installation, my installer has a dialog which asks for an URL and a port (stored in properties API_URL and API_PORT) and writes that info to a file "Application Folder/config/config.yaml", making use of the (rather cool) feature Text file update and the above properties. Example file content:

Code: Select all

api:
  url: https://myurl.com
  port: 4001
Now, if my application is uninstalled, the user has the option to not delete that file (for the sake of reusing the information in case the application is installed again). This is the case I'm currently working on. I basically have two ideas which would both suire my needs (although the second one is ceratinly nicer):

Idea 1) Check whether the config file already exists. If this is the case, skip the dialog asking for URL and port (and implicitly reuse the existing config file - maybe also show a dialog explaing this and pointing to the config file).
My problem with this approach is that I was not able to configure an according file search for some weird reason. My search looks like this:

File search: CONFIG_YAML (Name: config.yaml)
| Search location: Folder (Path: [APPDIR]\config)

For some reason, the config file is not found. The logfile contains the following, but I'm having a hard time intepreting it.

AppSearch: Eigenschaft: CONFIG_YAML, Signatur: FileSearchSign
MSI (c) (1C:4C) [15:33:28:762]: Note: 1: 1324 2: \config 3: 1
MSI (c) (1C:4C) [15:33:28:762]: Note: 1: 1324 2: \config 3: 1
Aktion beendet um 15:33:28: AppSearch. Rückgabewert 1.

Additionally, I have added an extra Text control to the dialog, with Property Name CONFIG_YAML and Default Value "unset". The text control always displays "unset".

What am I doing wrong?


Idea 2) The nicest solution would obviously be to parse the existing config.yaml file in case it exists, to prefill the dialogs URL and port text controls with the values found, and to just rewrite the config file. I have already tried to invoke the installer with arguments

Code: Select all

API_URL=https://myurl.com API_PORT=4001
, which indeed prefills the text controls. Is it possible to parse yaml from within my installer, and to store the found values into my properties?


Thanks in advance,
Christian
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Checking for existence of file in [APPDIR]

Hello Christian,

Thank you for the detailed explanation.

Now, please allow me to answer your points:

1. In what regards your first solution, this is not a bad solution. However, it does not work because, when the searches are performed, the APPDIR property is not resolved, to be more exact, it does not exist. The searches are performed during the "Searches" action group (in the "Custom Actions" page). The APPDIR property is resolved during the "CostFinalize" standard action, which is part of the "Paths Resolution" action group (if you go to "Custom Actions" page, it is visually visible that the actions that are part of the "Paths Resolution" action group are executing after searches).

Therefore, your search which is based on the APPDIR property will fail, due to the fact that the APPDIR property is not resolved at that point in time.

If you open your Advanced Installer project and go to "Registry" page, you will notice that there are two registry entries, "Path" respectively "Version". These are created, by default, in every Advanced Installer project and they retain the APPDIR property ("Path") and the version of your setup. If you right click, for instance, on "Path" --> "Go to Component", this will redirect you to "Organization" page. Here, you can notice that there is a component, named "ProductInformation", which controls the creation of these registries. Basically, the registry entries are only written if this component is installed.

A solution to your first approach would be to set this component to "Permanent" (in the "Attributes" section). This option will prevent the registry entries to be deleted during uninstall. After doing so, you can create a registry search in the "Search" page that will look for the "Path" entry (which, bu default, stores the APPDIR property).

Hope things are clearer now for you. If there is anything that is still not clear, please let me know and I will gladly assist.

2. In what regards the second solution, yes, it is possible to parse a file. To achieve this, you will need a custom action. For instance, you can have a PowerShell script which will look for your file and, if found on the system, will parse it and then, after parsing it, set the required properties (e.g. API_URL and API_PORT) to the values you need.

This custom action should be scheduled in the "Wizard Dialogs Stage", before the "User Selection" action group (this is where the main dialogs are spawned. By scheduling the custom action before, your properties will be set before the dialogs are spawned, therefore the fields will be populated accordingly).

For more information about how you can set an installer property from within a custom action, please have a look on our "How to set an installer property using custom actions"

If you require any further assistance with this, please let me know and I will gladly assist.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
csoltenborn
Posts: 9
Joined: Wed Nov 20, 2019 1:05 pm

Re: Checking for existence of file in [APPDIR]

Hello Catalin,

thanks for your fast reply and the good answer! I implemented option 2, and it works just fine. The only remaining issue is that the script is executed very early - I can even use the APPDIR property, but this contains its default value (and not the value chosen by the user at the second dialog, which would be the right choice). I again see a couple of options:

1) Defer execution of the script until that path is chosen by the user, but before the dialog to enter the URL and port ist shown. Is that possible at all? I fear that setting the according properties bound to the Text controls is too late then to work because of your statement that "By scheduling the custom action before, your properties will be set before the dialogs are spawned, therefore the fields will be populated accordingly"...
2) Write code to find the actual installation folder. This might be rather slow, though, depending on the target system...
3) Do not give the user the option to change the installation folder.

Can you please comment on these options (or even suggest a different one not on my radar)?

Thanks
Christian
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Checking for existence of file in [APPDIR]

Hello Christian,

Thank you for the detailed explanation.

I'm glad my answer was useful to you.

In what regards your second question, I think we can proceed as it follows:

The dialog where the user inputs the data should be placed after the "FolderDlg" dialog. Basically, the order of the dialogs should be like this: PrepareDlg --> WelcomeDlg --> FolderDlg --> YourDialog --> rest of the dialogs.

Now, another thing you can do is to change the sequencing of your custom action, from "custom action with sequence" --> "custom action without sequence". We mainly do this to execute our custom action as a dialog event (I will explain this a bit later).

In order to change the sequencing of a custom action, you can go to "Custom Actions" page --> right click on your custom action --> "Sequence" --> "Without Sequence"
CAWithoutSeq.png
CAWithoutSeq.png (97.14 KiB) Viewed 5222 times

Now that the custom action is without sequence, we can execute it as a dialog event. To do so, you can go to "Dialogs" page --> select your dialog (where you need to pre-populate the edit boxes) and add, under "Init Events" tab, an event as it follows:

Event: Execute Custom Action
Argument: your_custom_action
Condition: leave unchanged

InitEvent.png
InitEvent.png (134.56 KiB) Viewed 5222 times

This way, the custom action will be executed right before your dialog is spawned, which will result in the edit boxes being pre-populated.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
csoltenborn
Posts: 9
Joined: Wed Nov 20, 2019 1:05 pm

Re: Checking for existence of file in [APPDIR]

Catalin,

just wanted to shoot you a quick Thanks! for your great explanation - works like a charm!

Cheers,
Christian
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Checking for existence of file in [APPDIR]

You are always welcome, Christian.

I am really glad this worked for you.

Also, thank you for taking your time to do a followup on this. This might be useful for further users facing a similar scenario (knowing that this works as intended).

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

Return to “Building Installers”