File Substitution for ALL variables, not just specifically-named substitutions

Comments

2 comments

  • Avatar
    drivera

    Additionally, specifying an "interpolation pattern" would help in files where variable interpolation is already in play (i.e. ${} is already in use). For instance, patterns like %{VARIABLE} would be interpolated by resolving VARIABLE in the installer's existing variables/parameters.

    I've seen other installers use @@VARIABLE@@. The idea is to not have to enumerate every single possible variable in the substitution since this can be quite time consuming and error-prone.

    Thanks!

  • Avatar
    michiel

    Unfortunately there is no built in action to substitute all variables. As a workaround you could use the following custom action:

     

      <functionDefinitionList>
            <actionDefinition>
                <name>substituteAllVariables</name>
                <actionList>
                    <globalVariables>
                        <names>${textVariable}</names>
                    </globalVariables>
                    <setInstallerVariable>
                        <name>result</name>
                        <value></value>
                    </setInstallerVariable>
                    <setInstallerVariable>
                        <name>remaining</name>
                        <value>${${textVariable}}</value>
                    </setInstallerVariable>
                    <while>
                        <actionList>
                            <setInstallerVariableFromRegEx>
                                <name>before</name>
                                <pattern>^(.*?)${prefix}(.*?)${suffix}(.*?)$</pattern>
                                <substitution>\1</substitution>
                                <text>${remaining}</text>
                            </setInstallerVariableFromRegEx>
                            <setInstallerVariableFromRegEx>
                                <name>variableName</name>
                                <pattern>^(.*?)${prefix}(.*?)${suffix}(.*?)$</pattern>
                                <substitution>\2</substitution>
                                <text>${remaining}</text>
                            </setInstallerVariableFromRegEx>
                            <setInstallerVariableFromRegEx>
                                <name>remaining</name>
                                <pattern>^(.*?)${prefix}(.*?)${suffix}(.*?)$</pattern>
                                <substitution>\3</substitution>
                                <text>${remaining}</text>
                            </setInstallerVariableFromRegEx>
                            <globalVariables>
                                <names>${variableName}</names>
                            </globalVariables>
                            <setInstallerVariable>
                                <name>result</name>
                                <value>${result}${before}${${variableName}}</value>
                            </setInstallerVariable>
                        </actionList>
                        <conditionRuleList>
                            <regExMatch>
                                <logic>matches</logic>
                                <pattern>^(.*?)${prefix}(.*?)${suffix}(.*?)$</pattern>
                                <text>${remaining}</text>
                            </regExMatch>
                        </conditionRuleList>
                    </while>
                    <setInstallerVariable>
                        <name>${textVariable}</name>
                        <value>${result}${remaining}</value>
                    </setInstallerVariable>
                </actionList>
                <parameterList>
                    <stringParameter name="textVariable" value="" default="">
                        <description></description>
                        <explanation></explanation>
                        <allowEmptyValue>1</allowEmptyValue>
                        <width>40</width>
                    </stringParameter>
                    <stringParameter name="prefix" value="" default="">
                        <description></description>
                        <explanation></explanation>
                        <allowEmptyValue>1</allowEmptyValue>
                        <width>40</width>
                    </stringParameter>
                    <stringParameter name="suffix" value="" default="">
                        <description></description>
                        <explanation></explanation>
                        <allowEmptyValue>1</allowEmptyValue>
                        <width>40</width>
                    </stringParameter>
                </parameterList>
            </actionDefinition>
        </functionDefinitionList>
    

    You can then run the action in the following way:

    <setInstallerVariable>
                <name>text</name>
                <value>INSTALLDIR={{installdir}}
    
    INSTALLDIR2={{installdir}}
    
    INSTALLDIR3={{installdir}}
    
    PL={{platform_name}}</value>
            </setInstallerVariable>
            <substituteAllVariables>
                <prefix>\{\{</prefix>
                <suffix>\}\}</suffix>
                <textVariable>text</textVariable>
            </substituteAllVariables>
            <showInfo>
                <text>${text}</text>
            </showInfo>

    You can then run the action in the following way:

    <setInstallerVariable>
                <name>text</name>
                <value>INSTALLDIR={{installdir}}
    
    INSTALLDIR2={{installdir}}
    
    INSTALLDIR3={{installdir}}
    
    PL={{platform_name}}</value>
            </setInstallerVariable>
            <substituteAllVariables>
                <prefix>\{\{</prefix>
                <suffix>\}\}</suffix>
                <textVariable>text</textVariable>
            </substituteAllVariables>
            <showInfo>
                <text>${text}</text>
            </showInfo>
    

    Please note that the prefix and suffix are regular expressions, if you are using {{ for example they should be escaped \{\{.

    You can find more information about custom actions in the following section of our manual:

    https://installbuilder.bitrock.com/docs/installbuilder-userguide.html#_creating_custom_actions

Please sign in to leave a comment.