Kichik, that last line of code takes care of the .old files as requested. Thank you so much for everything. Sorry for breaking earlier 🙁
Is it possible to do a search and replace on certain files?
42 posts
I know in my last post I said I have just one more question *but* I have just one more and I promise once this is solved my search and replace mission is over and I will move on.
I have many markers in my files in which require to be replaced with an absolute path (e.g. @@AbsolutePath@@). I was hoping I could take the absolute path from the "Destination Folder" field at the install location screen.
The trick though is not just getting the path from the "Destination Folder" but also reverting its "\" with "/"... I can get the user to enter this information manually but was hoping I could do it for them automatically.
So the Destination Folder looks like this...
C:\Program Files\My Application
But, when the user clicks install all markers in my files will then look like this...
C:/Program Files/My Application
I am really hoping this is not too hard. Please help me with just this last bit of code and I will be out of everyones hair in regards to search and replace.
Thank you so much as this is so important to me to get this last task out of the way.
Thank you
I have many markers in my files in which require to be replaced with an absolute path (e.g. @@AbsolutePath@@). I was hoping I could take the absolute path from the "Destination Folder" field at the install location screen.
The trick though is not just getting the path from the "Destination Folder" but also reverting its "\" with "/"... I can get the user to enter this information manually but was hoping I could do it for them automatically.
So the Destination Folder looks like this...
C:\Program Files\My Application
But, when the user clicks install all markers in my files will then look like this...
C:/Program Files/My Application
I am really hoping this is not too hard. Please help me with just this last bit of code and I will be out of everyones hair in regards to search and replace.
Thank you so much as this is so important to me to get this last task out of the way.
Thank you
Thank you Joost,
I insert this piece into my NSIS project script?
I really am no geek but would very much like to use the NSIS installer as it allows me the freedom to customize the installation for end users. I believe it is very powerful...
Just how do I get the Directory Folder installation value, change all the "\" with "/" and then apply that value to markers through out the installation?
Please help me on this last task... I could ask the end user for the value but I trust NSIS to do it better.
Thank you for your help
I insert this piece into my NSIS project script?
And it is the below function I will save as an NSI script in my projects directory?Push String to do replacement in (haystack)
Push String to replace (needle)
Push Replacement
Call StrRep
Pop $R0 result
Can you please explain besides doing the above how I tie this into getting the value of the install directory and then applying that value to markers located through out various files?; Push $filenamestring (e.g. 'c:\this\and\that\filename.htm')
; Push "\"
; Call StrSlash
; Pop $0
; $0 == 'c:/this/and/that/filename.htm'
Function StrSlash
Exch $R3 ; $R3 = needle ("\" or "/")
Exch
Exch $R1 ; $R1 = String to replacement in (haystack)
Push $R2 ; Replaced haystack
Push $R4 ; $R4 = not $R3 ("/" or "\")
Push $R6
Push $R7 ; Scratch reg
StrCpy $R2 ""
StrLen $R6 $R1
StrCpy $R4 "\"
StrCmp $R3 "/" loop
StrCpy $R4 "/"
loop:
StrCpy $R7 $R1 1
StrCpy $R1 $R1 $R6 1
StrCmp $R7 $R3 found
StrCpy $R2 "$R2$R7"
StrCmp $R1 "" done loop
found:
StrCpy $R2 "$R2$R4"
StrCmp $R1 "" done loop
done:
StrCpy $R3 $R2
Pop $R7
Pop $R6
Pop $R4
Pop $R2
Pop $R1
Exch $R3
FunctionEnd
I really am no geek but would very much like to use the NSIS installer as it allows me the freedom to customize the installation for end users. I believe it is very powerful...
Just how do I get the Directory Folder installation value, change all the "\" with "/" and then apply that value to markers through out the installation?
Please help me on this last task... I could ask the end user for the value but I trust NSIS to do it better.
Thank you for your help
Example:
Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
;Now $R0 contains the $INSTDIR with forward slashes
Thank you so much Joost,
Before I run into error I just wish to confirm before moving ahead. Do I apply both codes...
The original snippet
Also do I save the function to an NSH and use it the same way I use the other files "StrReplace.nsh" and "ReplaceInFile.nsh"?
Thank you so much for your patience with me.
Before I run into error I just wish to confirm before moving ahead. Do I apply both codes...
The original snippet
Your SnippetPush String to do replacement in (haystack)
Push String to replace (needle)
Push Replacement
Call StrRep
Pop $R0 result
or just your snippet instead?Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
;Now $R0 contains the $INSTDIR with forward slashes
Also do I save the function to an NSH and use it the same way I use the other files "StrReplace.nsh" and "ReplaceInFile.nsh"?
Thank you so much for your patience with me.
There other ones are macro's. You don't have to use a macro for this one.
Use my snippet. Your snippet is for the generic replacer (read the page again).
Use my snippet. Your snippet is for the generic replacer (read the page again).
OK, I just need to confirm this before I find myself doing loops.
I use your snippet, not the other one. I save the function to a StrRep.nsh file in my project folder...
OK, once this is all done, how do I say replace this marker @@AbsolutePath@@ with $INSTDIR and your "SNIPPET", provided I've got the above mentioned solution correct so far?
Once I know a little more about the last step, I feel I can move ahead with experiment, otherwise I know I will simply be asking the same question in just a few moments.
I really am no geek and need to take it just a little slow. I hope you understand. I absolutely appreciate all the help you're giving me, I just need to know the best last step...
How to replace @@AbsolutePath@@ with $INSTDIR and your "SNIPPET"?
Thank you so much for your time I undoubtedly appreciate it all very much.
I use your snippet, not the other one. I save the function to a StrRep.nsh file in my project folder...
OK, once this is all done, how do I say replace this marker @@AbsolutePath@@ with $INSTDIR and your "SNIPPET", provided I've got the above mentioned solution correct so far?
Once I know a little more about the last step, I feel I can move ahead with experiment, otherwise I know I will simply be asking the same question in just a few moments.
I really am no geek and need to take it just a little slow. I hope you understand. I absolutely appreciate all the help you're giving me, I just need to know the best last step...
How to replace @@AbsolutePath@@ with $INSTDIR and your "SNIPPET"?
Thank you so much for your time I undoubtedly appreciate it all very much.
Just use the variable ($0 in my example). Like kichik said:
!insertmacro ReplaceInFile "$INSTDIR\myotherfile.ini" "@marker@" "$0"
So you have to put the last snippet above this code.
!insertmacro ReplaceInFile "$INSTDIR\myotherfile.ini" "@marker@" "$0"
So you have to put the last snippet above this code.
I just tried the following code...
But it keeps stopping at "Push $INSTDIR" with the following error "Error: Can't add entry, no section or function is open!"; This snippet should help in replacing the Absolute system paths by replacing "\" with "/".
Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
;Now $R0 contains the $INSTDIR with forward slashes
!insertmacro ReplaceInFile "$INSTDIR\crash.txt" "@AbsolutePath@" "$0"
I've also tried the following
But I end up with the following error...Section "Replace @AbsolutePath@"
; This snippet should help in replacing the Absolute system paths by replacing "\" with "/".
Push $INSTDIR
Push "\"
Call StrSlash
Pop $0
;Now $R0 contains the $INSTDIR with forward slashes
!insertmacro ReplaceInFile "$INSTDIR\crash.txt" "@AbsolutePath@" "$0"
SectionEnd
Adding plug-ins initializing function... Done!
Error: resolving install function "StrSlash" in section "Replace @AbsolutePath@" (5)
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process
I solved it Joost! I forgot to insert the !include... Excellent, Thank you so much for your time 🙂 Everyone will get a thank you in my credits 🙂
Thank you for putting up with me with so far
Thanks again
Thank you for putting up with me with so far
Thanks again