Wix Installer - Create Folder hierarchy based on Property

丶灬走出姿态 提交于 2019-12-12 15:40:08

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/12478566/wix-installer-create-folder-hierarchy-based-on-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!