Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wix Installer - Create Folder hierarchy based on Property

I am using Wix 3.6 to create a setup. I am still learning as I go along. The information out there is still scattered around. I am just waiting for my Wix Developer Guide book arriving.

I currently have a custom UI dialog where the user enters some application configuration. Part of that configuration is to specify a log folder. This at present this just sets a property [LogFolder]. This is defaulted to something like D:\Logs.

I want the installer to create that directory when the setup is run. I have the following to try and do this but it just created a folder named [LOGFOLDER] on the D: drive when I run the setup.

<Product ...
    <Directory Id="TARGETDIR" Name="SourceDir" >
        <Directory Id="LogFolderDir" Name="[LOGFOLDER]" >
            <Component Id="LogFolderComponent" Guid="{7E7D6916-B321-40D6-ABAD-696B57A6E5FB}" KeyPath="yes">
                <CreateFolder />
            </Component>
        </Directory>
    </Directory>
    ...
</Product>

How can I do this with Wix?

like image 986
Andez Avatar asked Dec 18 '25 03:12

Andez


2 Answers

The first step is create a property set to the value you want:

<Product>
  <Property Id="LOGFOLDER" Value="D:\Logs" />
</Product>

The second step is to create a dialog where you set this property (or another thing to change its value):

<Dialog>
  <Control Id="Edit_LogFolder" Type="Edit" Property="LOGFOLDER" />
</Dialog>

Then you need to change your directories structure to create this folder in a default location:

<Directory Id="ProgramFilesFolder">
  <Directory Id="INSTALLFOLDER" Name="MyApp">

    <Directory Id="LOGFOLDER" Name="Logs" />

  </Directory>
</Directory>

The last step is to create a Component that will create the directory, like this:

<ComponentGroup Id="ComponentGroup_LogFolder">
  <Component Id="Component_LogFolder" Guid="" Directory="LOGFOLDER">

    <CreateFolder Directory="LOGFOLDER" />

  </Component>
</ComponentGroup>

Remark:

If D:\ is a disc drive and you have a disc inserted, the installation will fail because it will try to create the folder and it won't succeed.

like image 102
Marlos Avatar answered Dec 20 '25 20:12

Marlos


The Name attribute isn't formattable so you can use properties in it. The Id 'LogFolderDir' doesn't have a parent such as "ProgramFilesFolder' so it's defaulting to the volume with the largest amount of disk space. In this case D but YMMV.

It's dangerous to default to D: because D: might not exist. How I'd set this directory up is Id="LOGDIR" Name="Logs" and make it a child of the INSTALLDIR/INSTALLLOCATION directory element. Then in your custom UI, wire up another BrowseFolder dialog to give the user the ability to override it. Or, make it associated with a required Logs feature so that the stock feature selection dialog can be used to select the feature and browse the destination folder.

If you still want it to "default" to D:\Logs what I would do is have a custom action that checks to see if D: exists and is a fixed disk. If so, set the LOGDIR=D:\Logs

like image 32
Christopher Painter Avatar answered Dec 20 '25 19:12

Christopher Painter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!