Archive: WriteINIStr -> without [section] possible?


WriteINIStr -> without [section] possible?
Hello,

is there any way to write to INI files which have NO sections in it?

Of course I could do it with FileSeek etc, but is there some kind of "default" value that I can use in WriteINIStr for the "section" parameter? Just an empty string won't work, sadly...

Thanks in advance!


Yes,it's possible.
May be it can help you.

http://nsis.sourceforge.net/Write_to...ction_headings


Cool! Thank you!

I modified the function a bit, because my "ini" file is in fact NOT a real ini file, so I want every line to be preserved (except the one with the = that I want to change).

Therefore I changed the following part a bit, perhaps it's useful for someone:


LoopRead:
ClearErrors
FileRead $R3 $R6
IfErrors End

StrCpy $R7 -1
LoopGetVal:
IntOp $R7 $R7 + 1
StrCpy $R8 $R6 1 $R7
StrCmp $R8 "" WriteAnyway # here
StrCmp $R8 = 0 LoopGetVal

StrCpy $R8 $R6 $R7
StrCmp $R8 $R1 0 +4

FileWrite $R5 "$R1=$R0$\r$\n"
StrCpy $R9 1
Goto LoopRead

WriteAnyway: # and here
FileWrite $R5 $R6
Goto LoopRead


Now every line gets into the resulting file, even if it hasn't got a "=" in it!

Note: Now it's useful for ".properties" files, which can include comments and no sections.

Perhaps the original author could add this extra modification somewhere in the Wiki?


Not understand clearly.

Sorry, I am not agreeing with you. This function is really cool and smooth. I use this function so many times in different purpose. Find no problem.
;)


http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.11


@ shouman:

You're right, the function is perfect for what it's designed - INI files without sections.

However, I didn't want to edit a "real" INI file, I had a properties file which doesn't only contain things like property = value, but also comments and other stuff that doesn't contain a "=" in its lines. Now the problem is, the WriteINIStrNS function ignores those lines and in your resulting INI file you'll only have those lines which are such "ini settings" - but all comments are left out.

So I edited the function and now it's also able to handle EVERY file, no matter what its content may be.

---

@ Instructor:

Thank you, that seems to be the right function for my purposes! I just didn't find it ;)