Archive: What's wrong with my string?


What's wrong with my string?
I'm using the ReplaceInFile script from the Archive. It works fine, except when I insert the string I actually want to use... i.e. the tests I run work fine... but as soon as I insert the actual string I want to replace, it dies.

I don't think my syntax is wrong, since I am able, earlier in my installer script, to insert my string (the same one!) into that file.

Here is the text I want inserted:
user_pref("network.protocol-handler.external.deusex", true);
this is what I am entering into my installer:
!insertmacro ReplaceInFile "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js" "$\r$\nuser_pref($\"network.protocol-handler.external.deusex$\", true);" "replacement_text"

(yes that's all one line)
...and this is the error I get when I compile:



!insertmacro: ReplaceInFile
Push: $PROFILE\Application Data\Mozilla\Firefox\$1\user.js
Push expects 1 parameters, got 3.
Usage: Push string
Error in macro ReplaceInFile on macroline 2
Error in script "moop.nsi" on line 300 -- aborting creation process


So... it appears to think that my string is OKAY when I use the same exact string earlier in the file... but somehow now, through this ReplaceInFile script, it gets misinterpreted?

I have re-tested it without using the !insertmacro command, instead inserting the parameters line-by-line using Push and Call (as ReplaceInFile does)... still nothing.

Help?:igor:


Dump the macro and use:

Push "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js"
Push "$\r$\nuser_pref($\"network.protocol-handler.external.deusex$\", true);"
Push "replacement_text"
Call RIF


-Stu

Originally posted by Afrow UK
Dump the macro and use:

Push "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js"
Push "$\r$\nuser_pref($\"network.protocol-handler.external.deusex$\", true);"
Push "replacement_text"
Call RIF


-Stu
My last paragraph. Did that. ;) Nothing.

I think your macro is failing because you have quotes inside of quotes..this == another string.You can also use strcpy and copy that whole string to a variable,then call that variable in the macro.

strcpy $2 "path"
strcpy $3 "string to search"
strcpy $4 "replacement text"

!insertmacro ReplaceInFile "$2" "$3" "$4"


Originally posted by razor_x
I think your macro is failing because you have quotes inside of quotes..this == another string.You can also use strcpy and copy that whole string to a variable,then call that variable in the macro.

strcpy $2 "path"
strcpy $3 "string to search"
strcpy $4 "replacement text"

!insertmacro ReplaceInFile "$2" "$3" "$4"
Okay, I just tested that, and it doesn't seem to work. Here is what I included:

strcpy $7 "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js"
strcpy $8 "$\r$\nuser_pref($\"network.protocol-handler.external.deusex$\", true);"
strcpy $9 "fwargh"
!insertmacro ReplaceInFile "$7" "$8" "$9"


And although it compiled without errors, my file (user.js) was left unchanged. I included a DetailPrint in my script so I could see what was assigned to each variable, and this is what it said:

$7 is C:\Documents and Settings\Moop\Application Data\Mozilla\Firefox\Profiles\e8x86j94.default\user.js
$8 is
user_pref("network.protocol-handler.external.deusex", true);
$9 is fwargh
$R0 is Profiles\e8x86j94.default


Any thoughts? Is this a limitation of the engine? Is it a bug?

This part of my script is just "clean-up" code - meaning I'm erasing the line from the user's user.js file if they have already run the installer previously. I'm guessing that's relatively amateurish, but this is my first installer, and that's okay. ;)

!insertmacro ReplaceInFile "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js" '$\r$\nuser_pref($\"network.protocol-handler.external.deusex$\", true);' "replacement_text"


does this work?

The macro is fine.I think your folder may be "Read Only"....


Yathosho:
I get
!insertmacro: ReplaceInFile
Push: $PROFILE\Application Data\Mozilla\Firefox\$1\user.js
Push expects 1 parameters, got 3.
Usage: Push string
Error in macro ReplaceInFile on macroline 2
Error in script "moop.nsi" on line 300 -- aborting creation process
during compilation.

razor_x:
I had SetFileAttributes on user.js to NORMAL - and as I mentioned in the top post, I am able to add that text to the file if the text doesn't exist... but I can't subtract/replace it. I am using the exact same string, too... cut & paste, looked it over, read the documents on quotes and symbols... this all seems very odd to me. Odd enough that I might consider it a bug if I didn't first think it was my inexperience.

:(


The macro is the problem - it uses "" and the search string includes "".

One way to solve this is to use

Push "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js"
Push '$\r$\nuser_pref("network.protocol-handler.external.deusex", true);'
Push "fwargh"
Call RIF

I solved it like this...my example

strcpy $0 "D:\Documents and Settings\mysettings\Application Data\Mozilla\Firefox\Profiles\default.cvn\prefs.js"
strcpy $1 '"network.protocol-handler.external.deusex"' ;we add the string inside a string to a variable(note the extra single quotes)
strcpy $2 "user_pref($1, true);" ;add that variable to the string to search
strcpy $3 "" ;delete the string

!insertmacro ReplaceInFile "$0" "$2" "$3"

macro works fine...guess yours would look something like this..with the correct variable for the path of course


Originally posted by pengyou
The macro is the problem - it uses "" and the search string includes "".

One way to solve this is to use
Push "$PROFILE\Application Data\Mozilla\Firefox\$1\user.js"
Push '$\r$\nuser_pref("network.protocol-handler.external.deusex", true);'
Push "fwargh"
Call RIF
No dice... even without the macro, and the single-quote syntax, it just doesn't work. Should I post the whole script as a file here, or maybe just that section?

The mystery of the stubborn string grows. :p

Edit: Ohh ty razor, I'll test that now.

Edit2: Oh just noticed - do NOT edit your prefs.js file, razor_x... bad things. The user.js file will be read into Firefox just like prefs.js, but without messing up your whole Firefox setup (I eventually backed up my bookmarks, history, and extensions, and un/re-installed Firefox... man what a pain, until I found out editing user.js works just the same without the chaos).

Edit2: Oh just noticed - do NOT edit your prefs.js file, razor_x... bad things. The user.js file will be read into Firefox just like prefs.js, but without messing up your whole Firefox setup (I eventually backed up my bookmarks, history, and extensions, and un/re-installed Firefox... man what a pain, until I found out editing user.js works just the same without the chaos).
this cant hurt as long as the browser is open while editing..closing the browser will overwrite the file with the previous settings.