Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove trailing slash from paths in WiX

I am using WiX to install a plugin for a software that I am not controlling. To install the plugin, I have to put the target folder in a registry key:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LocalAppDataFolder">
    <Directory Id="APPROOTFOLDER" Name="Foobar Plugin" />
  </Directory>
</Directory>

...

<DirectoryRef Id="APPROOTFOLDER">
  <Component Id="register" Guid="240C21CC-D53B-45A7-94BD-6833CF1568BE">
    <RegistryKey Root="HKCU" Key="Software\ACME\Plugins\FooBar">
      <RegistryValue Name="InstallDir" Value="[APPROOTFOLDER]" Type="string"/>
    </RegistryKey>
  </RegistryKey>
</DirectoryRef>

After the installation, the registry key HKCU\Software\ACME\Plugins\FooBar\InstallDir will contain the installation target path, but with a trailing "\". Unfortunately, for some strange reasons, the host application (the provides the plugin architecture) crashes due to that. If there is no trailing slash, everything works fine!

Is there a way in WiX to get rid of the trailing slash?

One solution I was thinking of is simply adding a "." at the end of the path, however, this seems not to work in my scenario :( ..

like image 326
beef2k Avatar asked Jun 03 '09 20:06

beef2k


2 Answers

You should not be using scripts in custom actions, but if you could limit down to only a few lines and to something as simple as this example, you should be Ok...

<CustomAction Id="VBScriptCommand" Script="vbscript">
  <![CDATA[         
    value = Session.Property("INSTALLFOLDER")

    If Right(value, 1) = "\" Then
      value = Left(value, Len(value) - 1) 
    End If

    Session.Property("SOME_PROPERTY") = value      
  ]]>
</CustomAction>

<InstallExecuteSequence>
  <Custom Action="VBScriptCommand" After="CostFinalize">NOT REMOVE</Custom>
</InstallExecuteSequence>
like image 183
Ostati Avatar answered Sep 19 '22 07:09

Ostati


The only string manipulation you really have in Windows Installer is the manipulation of formatted data types. See MSDN for more information.

Windows Installer provides a trailing directory separator by design, so there isn't any way to remove this aside from a custom action. I'd suggest lodging a bug with the developers of the source package you're developing a plugin for, if you're encountering this error then other developers likely are too.

like image 44
saschabeaumont Avatar answered Sep 22 '22 07:09

saschabeaumont