Archive: Writing/Changing a config file


Writing/Changing a config file
  Hi

i want to write (if not existing) or change (if already exists) a config file for a program from within a NSIS installer. The installer should replace a string with

UploadLimit=<SettingMadeInTheInstaller>
MaxUpload=<SettingMadeInTheInstaller>

or write those two line into a new config file if the file isnt there.

My problem is now:

Is it easier to make that with WriteINIStr or by opening a file like a text file (FileOpen,FileWrite,...) and replace it then ?
Because if the config file already exists and the user made his settings in the program it is not a constant like MaxUpload=true for example....its user defined...

Is there already an example of modifying/writing a new setting into a config file, which would fit my needs?


Hi :)

Err, not sure to have understood exactly that:

The installer should replace a string with

UploadLimit=<SettingMadeInTheInstaller>
MaxUpload=<SettingMadeInTheInstaller>
and
it is not a constant like MaxUpload=true for example....its user defined...
1) To write values in a config file, it's easier to use the WriteIniStr instruction: one instruction instead of FileOpen, FileWrite, FileClose...

WriteIniStr "MyFile.ini" "SectionName" "UploadLimit" "$UploadLimitSetIntheInstaller"



>WriteIniStr "MyFile.ini" "SectionName" "MaxUpload" "$MaxUploadSetIntheInstaller"
2) If your want to replace a string you could use this function:

http://nsis.sourceforge.net/archive/...b.php?page=318



evilO/Olive

I have no sections in my config, can i leave it at "" then ?


I think Windows INI files always have sections, otherwise you'll have to read it manually.


hehe its not an ini file...we store program config in a seperate .config file located in the program dir.

So it isnt possible to add strings (by using WriteINIStr) to files without sections.

Would it be possible to add such an instruction,which makes that possible, to the NSIS development version ? That would be a nice feature and makes it easier to edit existing configs for programs or new, cause a lot of programs store their settings like <entryname>=<value>

...just a thought...


WriteINIStr can only create INI file strings, which do have sections.

Because most application use INI files or registry keys, it is most likely that this feature won't be added to NSIS.

You can however write a NSIS function that can read/write such strings. Exampls can be found in the NSIS Archive at http://nsis.sf.net/archive


It is especially interesting for programs which work on multiple platforms (win, linux, mac,...) like our program (a java one)...because they dont use ini files or reg entries and consist of just plain <name>=<value>.

However i guess its not that hard to write a function replacing the value, so its time to get to work :)

Thanks for your help!