- NSIS Discussion
- Need some advice on slashconverting
Archive: Need some advice on slashconverting
Mosestycoon
19th October 2003 15:53 UTC
Need some advice on slashconverting
Dear Guys -
Can somebody help me on slashconverting? I have to open a file parse it through the slash-converting function (convert backslashes to normal slashes) and close it under the same name!
I found this slash-converter here @ the archive but didn't understood how to get it work...
Thx in advance
Mo
kichik
19th October 2003 16:23 UTC
Open the file, read a line, pass it to the function, write the output to another file, repeat until you've read the entire file, close both files and replace the old one with the new one.
Mosestycoon
19th October 2003 16:56 UTC
So I can use this function? What I don't understood are the comments above:
; Push $filenamestring (e.g. 'c:\this\and\that\filename.htm')
; Push "\"
; Call StrSlash
; Pop $0
; $0 == 'c:/this/and/that/filename.htm'
Mo
Joost Verburg
19th October 2003 17:08 UTC
It's an example of usage.
Push "line that contains a \"
Push "\" ;Char to convert
Call StrSplash
Pop $R0 ;Or another variable
;Now $R0 will contain the same string with \ converted to /
You will have to use this function for the lines you read from the file.
kichik
19th October 2003 17:08 UTC
That file name is just an example of a string conatining backslashes. You should push the line you read from the file instead of that.
Mosestycoon
19th October 2003 17:12 UTC
Uuuhh,
could please give me an example? I tried some things, but with no luck!
kichik
19th October 2003 17:13 UTC
What's wrong with Joost's example?
Mosestycoon
19th October 2003 17:18 UTC
I don't know the lines which have to be converted. This can vary from and I don't know the exact content to be converted, because these lines (with an $INSTDIR) are set with the installation process, so this depends on the path set by the user...
kichik
19th October 2003 17:26 UTC
You're not supposed to push constant strings to that function, you're supposed to push it strings that you read from the file.
If it's $INSTDIR that you're trying to convert, why not preconvert it? Just push $INSTDIR to that function and have your file replacement functions replace your file constants with the converted $INSTDIR instead of the original one.
Mosestycoon
19th October 2003 17:38 UTC
Because I don't know how!
I have one function for editing the file. This replaces some place holder with an installation path:
Function ModibWebAdmin
ClearErrors
FileOpen $0 "$INSTDIR\test.tmp.php" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "@@BINPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'BINPATH$\', $\'$INSTDIR\DB\FireBird\bin\$\');$\r$\n"
Goto loop
StrCmp $2 "@@TMPPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'TMPPATH$\', $\'$INSTDIR\DB\FireBird\tmp\$\');$\r$\n"
Goto loop
StrCmp $2 "@@DEFAULTPATH@@$\r$\n" 0 +3
FileWrite $1 "define($\'DEFAULT_PATH$\', $\'$INSTDIR\DB\FireBird\$\');$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "$INSTDIR\test.tmp.php"
Rename $R0 "$INSTDIR\test.tmp1.php"
FunctionEnd
But these replaced lines show the path with backslashes. Don't know why but these file (php-script) doesn't work with backslashes. So these lines should be converted. I would have prepared the file with '/' instead of '\', but I have no influence on the front part set through $INSTDIR ...
So what was your idea on Push $INSTDIR? How can this be achieved?
kichik
19th October 2003 17:53 UTC
Use this:
Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
$0 will contain the string you should use instead of $INSTDIR in the file replacement function.
Mosestycoon
19th October 2003 17:56 UTC
Okay I think I almost got it kichik :-D
One last question:
Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
Can this be used in a section (at any place), or do I have to make a seperate function out of it which has to be called with
Call FunctionName
Mo!
kichik
19th October 2003 17:59 UTC
It can be used anywhere you want as long as you know $INSTDIR will be set to the right value (after directory selection page) and that $0 will not change until the file replacement function is called.
Mosestycoon
19th October 2003 18:45 UTC
I can't get it work...
Could somebody review and correct it, pleeaaase
Mo
kichik
19th October 2003 19:17 UTC
You are still using $INSTDIR in the Replace function. Use $R0 instead.
Mosestycoon
19th October 2003 19:22 UTC
YEEEEAAAAAAHHHHHH !!!! :up:
Got it!
Thx Kichik (you rock!) great help!
Mo
:D
P.S.: can the used variables be cleared at the end or do they have no effect on following functions and sections?
kichik
19th October 2003 19:25 UTC
As long as you don't call that function again you can clear it. If you're worried you might need it sometime you can use Var to create a special variable just for it (assuming you're using the latest CVS version).
Mosestycoon
19th October 2003 19:49 UTC
So best/safest would be
Var NAME_OF_VAR
(in the beginning of the script)
and than call it at the line
Pop $NAME_OF_VAR
Is that right?
kichik
19th October 2003 19:56 UTC
Yes, and in the replacement function too. Replace $R0 with $NAME_OF_VAR.
Mosestycoon
19th October 2003 20:06 UTC
So thx kichik: Your my man! :D