PDA

View Full Version : Handling Quotes



musabio
06-18-2008, 06:58 PM
I'm a little confused about the proper syntax/techniques for dealing with special string characters, particularly quotes.

I see that Setup Builder automatically quotes certain strings, like %_SB_INSTALLDIR%. But if you manipulate such a string, such as with one of the the Handle Strings "split" functions, you end up with a pair of strings that have mismatched quotes. For example, this function:

Set Variable %PART1% and %PART2% to FUNCTION:Split Source String at First Occurrence of Search String(%SOME_PATH%, "\")

results in %PART1% having a leading quote and %PART2% having a trailing quote.

Appending a new filename to the directory in the first part doesn't automatically fix the mis-matched quotes, and trying to use such a file spec to reference an actual file doesn't work.

To re-balance the quotes, I tried using the Set Variable function with the append option, but it isn't clear: A) what the proper syntax for specifying a string consisting of one double-quote character is, or B) whether the Set Variable with append strips recognizes a single quote. It does seem you can enter the single character " as the value to be assigned to a string in the Set Variable function, but it doesn't appear to work when appending.

Eventually, I managed to work around the problem by using the Mid function to remove the un-matched quote at the front, but it seems like a circuitous roundabout for what seems like a common operation in installers.

I couldn't find any reference in the help file to escaping special characters (e.g. "\042", "%x22", "\q", """, """", etc.), or other guidelines for dealing with partial directory specs resulting from splitting a larger path, so any suggestions or clarifications would be most appreciated.

andrea
06-19-2008, 06:28 AM
Hello,

Would it be possible for you to send us a small project (.sb6) to demosntrate which "quotes" you mean. There is no quote in %_SB_INSTALLDIR%.

Thanks,

musabio
06-19-2008, 12:11 PM
Sorry, I think I overlooked the actual source of the quotes. Since this is my first effort with SetupBuilder (still evaluating actually), I'm apparently unable to use the Detect Previous Version function (given that the application, if already installed, was installed by some other installer.) So instead, I've identified a Registry item that allows me to locate the current installation. That string is a complete filespec to the main executable, which just happens to be enclosed in quotes (e.g. "c:\program files\company\product\bin\file.exe"). So my goal is to split off the \bin\file.exe and set the result to %_SB_INSTALLDIR%, so that the update operation can proceed without needing the user to verify the location where it was previously installed.

My script code looks something like this:

Set Variable %OLDPATH% to FUNCTION:Get Registry ...

At this point, %OLDPATH% contains "c:\program files\company\prod\bin\file.exe" (including quotes)
Now use Split Source function to split off the last two segments of the path in order to get to the desired install directory...

If %_SB_ERRORCODE% Not Equals "0" Then
Set Variable %OLDPATH% and %OLDFILE% to FUNCTION:Split Source String at Last Occurrence of Search String(%OLDPATH%, "\")
Set Variable %_SB_INSTALLDIR% and %BINDIR% to FUNCTION:Split Source String at Last Occurrence of Search String(%OLDPATH%, "\")

Now %_SB_INSTALLDIR% contains "c:\program files\company\prod (no trailing quote). Because I am unsure of whether the Registry string contains quotes, I now need to detect the presence of the leading quote and either remove it or add one to the end. It seems that removing the leading quote is the best way to go, since %_SB_INSTALLDIR% seems to work better without explicitly quoted paths. So here's what I did, although it seems pretty cumbersome...

Set Variable %QUOTE% to FUNCTION:Left(%_SB+_INSTALLDIR%,1)
If %QUOTE% Equals """ Then
Set Variable %PATHLEN% to FUNCTION:Len(%_SB_INSTALLDIR%)
Set Variable %_SB_INSTALLDIR% to FUNCTION:Mid(%_SB_INSTALLDIR%, %PATHLEN%, 2)
End

By trial and error I figured out that I could use three double-quotes (""") to check if %QUOTE% equaled one, i.e. ASCII 42. And I'm not sure whether the Mid function supports a special value for the length, indicating from the start point to the end of the string.

I guess what I'm looking for is the definitive syntax for referencing special characters like quotes and spaces, and clarification on whether they are treated specially for the purposes of string operations such as comparisons, appends, InStr, etc. Related to that, any other guidance on best practices or functions for manipulating path strings would be helpful.

linder
06-19-2008, 12:32 PM
Hello,

I have developed and attached a quick and dirty demo for you. It takes a full qualified pathname (including exe and double-quotes around it) and converts it into file and path.

Set Variable %OLDPATH% to ""c:\program files\company\prod\bin\file.exe""
! Remove quotes
Set Variable %OLDPATH% to FUNCTION:Replace(%OLDPATH%, ", )
! Get filename
Set Variable %FILENAME% to FUNCTION:Extract File(%OLDPATH%)
! Extract pathname
Set Variable %FOLDERNAME% to FUNCTION:Extract Full Folder(%OLDPATH%)
Display Message Box "Filename: %FILENAME%\n\nFoldername: %FOLDERNAME%" -- "Result"

Does the attached test.sb6 project help?

Friedrich

musabio
06-19-2008, 02:49 PM
Indeed, that works (although you'll have to admit that the syntax of the Replace() statement looks somewhat odd, with the apparently dangling quote and comma.) For some reason I expected that the Replace strings would themselves have to be quoted, but I see now that is not the case.

The doc could be a little more explicit, but the support certainly is excellent. Thanks.

linder
06-20-2008, 01:50 AM
I agree. We'll change this, so in the next SB6 build it looks like this:

FUNCTION:Replace(%OLDPATH%, """, "")

And we'll add a new example project to the Examples Package to demonstrate the "string" functions.

Thanks,
Friedrich

linder
06-25-2008, 04:21 AM
The downloadable hotfix KB0806251 puts "double-quotes" around Handle String Function parameters now.

Thanks,
Friedrich