|
|
#1 |
|
Junior Member
Join Date: Dec 2008
Posts: 2
|
Inserting line halfway down an INI
First post.
I've done searches here and in the wiki, and asked questions (to no avail) in the IRC. First off, NSIS rocks! I've been at it for a week now and I really like the scripting language, very simple yet powerful. My installer needs to open an existing INI file, search for a section, then add a new section immediately after that. That means that everything else that already existed after the section I search for should be shifted down to make room for this new section. By using WriteINIStr I can add my section, but it shows at the end of the INI file. By using FileWrite I can add it where I want the section to be, but it overwrites the existing text from that point on. Can anyone help me with this? Thanks, |
|
|
|
|
|
#2 |
|
Major Dude
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
|
An INI file doesn't have to be in any particular order since any INI file parser will find the proper section no matter where it lies in the file.
But, if you want to force it that way, here's a rough outline of what you might do:
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2008
Posts: 2
|
Comperio,
This worked like a charm! I first had to figure out how to copy a file, which I did with: code: Where aircraft.cfg is the file to be copied, the original residing in a variable $AircraftCFG, which holds a path. As you can see, I followed your recommendation of copying it to the $PLUGINSDIR. Then I read through the copy line by line, writing to the original as I went, until I found the place to add the new text. I added the new text, then resumed the writing of the original file. By the way, I agree with you, in an INI file the order or location of the sections does not matter. In my case, though, the file is commonly edited by end users, so it needed to look tidy. Here's the final function code, if anyone is interested. I am open to any suggestions on improving how I do this, as I am very far from being a good programmer. Oh, and for those doing about the same thing, don't forget to delete the copy of the INI file at the end! code: Thanks for NSIS, and for all the help!! Best regards, |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|