0

Using WixUI_InstallDir I'm allowing the user to select a target directory for installing an add-in. After the user enters the directory, I would like to check if the chosen installation folder has a parent directory matching a certain name.

The folder of on the of the parents of the installation directory must be SPECIFIED_NAME:

C:/SPECIFIED_NAME/target --> okay
C:/SPECIFIED_NAME/foo/bar/target --> okay
C:/foo/bar/SPECIFIED_NAME/target --> okay

C:/Temp/target --> not okay

Is this possible using WiX 3.x?

Benjamin4991
  • 123
  • 7

1 Answers1

0

You can't do this with pure WixUI_InstallDir, you need to add extra validation of WIXUI_INSTALLDIR property using custom action.

  1. Declare in your code new property FOLDER_IS_OK. It will take values okay/not okay from your example.

  2. Write custom action, which will validate WixUI_InstallDir and write the result to FOLDER_IS_OK. Some information about this: change installer properties in C# custom action Something like that:

     [CustomAction]
     public static ActionResult MyPathValidation(Session session)
     {
         string installDir = session["WIXUI_INSTALLDIR"];
         session["FOLDER_IS_OK"] = ValidateInstallDir(installDir);
         return ActionResult.Success;
     }
     public string ValidateInstallDir(string dirName)
     {
         //TODO
     }
    
  3. Add this custom action to your code, like in Step 1 here: https://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html

  4. In Wix source code find file WixUI_InstallDir.wxs. Copy whole element <UI Id="WixUI_InstallDir">...</UI> to your code. Change Id value to MyWixUI_InstallDir and link that one in UIRef element in your project.

  5. Edit original block of your MyWixUI_InstallDir

<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

To something like that:

<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="MyPathValidation" Order="3">NOT WIXUI_DONTVALIDATEPATH</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="5">FOLDER_IS_OK<>"okay"</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="6">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>
Kirumata
  • 165
  • 1
  • 9