Archive: Custom data within a file to be installed?


Custom data within a file to be installed?
I have a file called "Userinfo.txt", and at a certain position, I want to insert some of the user's information. For example, I want their "Full Name" go be inserted at byte 43. Then, depending on how long their "Full Name" was, I want their "Street Address" to be inserted at position 75+Length(Full Name).

This information, such as Full Name and Street Address, is information I wish to ask the user for at the start of the installation process.

This could be done one of two ways:


Which of these, if any, are possible with NSIS?

The easier and more efficient option is to move the entire file into the NSIS script with multiple FileWrite instructions (with $\r$\n on the end of each line).

Stu


So you're saying, I should just ask NSIS to write out the first part of the file byte-for-byte, until I get to where I want to write user input, then write that user input, then continue writing the file?

Is this a good method, even when the file is around 1MB?


Whether the file is 1MB or 100MB if you need to replace any text in a file using an NSIS function it will be using FileRead and FileWrite on each line with some string manipulations in between. Therefore it would be best to store the file in an NSIS script (could be separate from your main script and included with !include) unless you use some external function (such as a plugin or exe) which will do it.

Maybe like so:


!macro WriteLine Line
FileWrite $R0 `${Line}$\r$\n`
!macroend
!define WriteLine `!insertmacro WriteLine`

Push $R0
FileOpen $R0 `$INSTDIR\some file.txt` w
${WriteLine} `line 1`
${WriteLine} `$some_data hi!`
${WriteLine} `blah blah`
FileClose $R0
Pop $R0

Stu