Old 8th April 2009, 05:15   #1
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
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?
qwertymodo is offline   Reply With Quote
Old 8th April 2009, 13:54   #2
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
http://nsis.sourceforge.net/TextReplace_plugin

Sorry, I was too quick...
This will not work at compile time.
jpderuiter is offline   Reply With Quote
Old 9th April 2009, 01:35   #3
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
Hmm... well in the mean time I'll try the other way...
qwertymodo is offline   Reply With Quote
Old 12th April 2009, 09:56   #4
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
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...
Attached Files
File Type: nsi buildu3p.nsi (14.6 KB, 246 views)
qwertymodo is offline   Reply With Quote
Old 12th April 2009, 11:04   #5
{_trueparuex^}
Senior Member
 
{_trueparuex^}'s Avatar
 
Join Date: Dec 2005
Location: Glow
Posts: 285
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^} is offline   Reply With Quote
Old 12th April 2009, 17:51   #6
{_trueparuex^}
Senior Member
 
{_trueparuex^}'s Avatar
 
Join Date: Dec 2005
Location: Glow
Posts: 285
I just realized that code probably won't work with script files or with any other files that breaks the parameter quoting.

PaR
{_trueparuex^} is offline   Reply With Quote
Old 14th April 2009, 05:12   #7
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
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 $\"
qwertymodo is offline   Reply With Quote
Old 10th May 2009, 12:19   #8
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 10th May 2009, 20:28   #9
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
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...
qwertymodo is offline   Reply With Quote
Old 10th May 2009, 23:38   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
NSIS can build on other platforms other than Windows (but only build installers that run on Windows).

Stu
Afrow UK is offline   Reply With Quote
Old 11th May 2009, 03:57   #11
qwertymodo
Junior Member
 
Join Date: Sep 2008
Posts: 26
Send a message via Yahoo to qwertymodo
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
qwertymodo is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump