Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Replace string in text file at compile time (http://forums.winamp.com/showthread.php?t=305102)

qwertymodo 8th April 2009 05:15

Replace string in text file at compile time
 
I need to replace a string inside of a text file at compile time, in the same way that the ReplaceInFile header does. I know that I COULD write a separate script that does it via the command-line, then call

code:

!system '"${NSISDIR}\makensis.exe" "textreplacescript.nsi"' = 0
!system '"textreplace.exe" "commandlineargs"' = 0
!delfile "textreplace.exe"



Is there an easier way?

jpderuiter 8th April 2009 13:54

http://nsis.sourceforge.net/TextReplace_plugin

Sorry, I was too quick...
This will not work at compile time.

qwertymodo 9th April 2009 01:35

Hmm... well in the mean time I'll try the other way...

qwertymodo 12th April 2009 09:56

1 Attachment(s)
So, the whole point of this question was that I have portable-ized a few programs for the U3 platform, and anyone who has ever perused PortableApps.com knows how useful NSIS is for creating portable application launchers. Unfortunately, I did have to go the route I had indicated, but it ended up not being so bad. I actually added a few more functions in this manner as well. My one gripe was having to use separate helper scripts, which just made the source folder all ugly.

Then I discovered the wonders of !system 'echo ... >> mytempfile'

Well, one thing led to another, and it was just too cool using runtime commands at compile time, and then I was like "hey I'll bet I could take all of these helper scripts I'm writing and merge them all into one!"

Yes, I did actually managed to write a very useful script whose output file does NOTHING.

...I get the feeling that no one else has done this before...

...perhaps with good reason...




...I scare myself sometimes...

{_trueparuex^} 12th April 2009 11:04

Try this.

code:
!define /file BUNCHASTUFF somefile.txt

!searchreplace NEWSTUFF "${BUNCHASTUFF}" "foo" "bar"
...

!delfile somefile.txt
!appendfile somefile.txt "${NEWSTUFF}"



Also you could use the NSIS !echo command instead of using !system command to call echo in your script.

PaR

{_trueparuex^} 12th April 2009 17:51

I just realized that code probably won't work with script files or with any other files that breaks the parameter quoting. :(

PaR

qwertymodo 14th April 2009 05:12

Hmm... I'll have to try that. Can !echo be used with >> the same as the system echo can? I mean, what is the actual difference? And as for breaking parameter quoting, I can usually get around that with $\"

kichik 10th May 2009 12:19

There's no !echo, only !appendfile and it works on all platforms and doesn't depend on the existence of echo or platform dependent command line parsing.

qwertymodo 10th May 2009 20:28

Well, there is an !echo command, I guess it just outputs only to the compiler, but thanks for pointing me at !appendfile, it's exactly what I needed.

...also, I'm not sure what you mean by platform-independent, as I'm pretty sure NSIS is Windows only anyways...

Afrow UK 10th May 2009 23:38

NSIS can build on other platforms other than Windows (but only build installers that run on Windows).

Stu

qwertymodo 11th May 2009 03:57

Oh, right, I knew that... just for some reason I wasn't thinking about the fact that it's a compile-time command, which would depend on the compiling system :P Anyway, problem solved, so thanks for the input :)


All times are GMT. The time now is 17:27.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.