Archive: Read an ini file during installation


Read an ini file during installation
I am new to nsis

I want the installer read an ini file before starting the installation.
Ini file that will have the following information Name of the installation folder, name for shortcuts among other things.
With this I can have four variations of my applications eg software1.1, software1.2, software1.3, software1.4
And it will not need to have an installer for each application for the changes to the installer will be the destination folder and different shortcuts.
Does anyone have idea how I can do this?

best regards
Wagner.


Start by reading the documentation:
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2


I believe that right did not explain what I do.
This is how I have a product installer, the installer will with an ini file. When running the installer will read the ini file and picked up some information, such as the installation folder and more.
reading the documentation I saw the property ReadINIStr
eg ReadINIStr $ 0 $ INSTDIR \ winamp winamp.ini outname
But my problem is I'm not keeping a fixed place, where is the ini file.
I have to make the installer look for an ini file when it runs and if he does not have the ini file to install a default installation of the product?

I remember that my product has many Ex versions: Standard, Professional

I know I'm not sure I could explain what I do.
But thanks to which I responded


1) You can use FindFirst/FindNext to find all .ini files in a certain directory. http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.5.12
2) You can use ReadIniStr to read from an ini file.
3) To set the default installation directory, simply do the following in the .onInit function: StrCpy $INSTDIR "C:\Your\Path"

With this information, you should be able to figure out how to do it.


Does it really have to be that complicated?

Why not put the INI file into the same folder as the "Setup.exe", e.g. as "Setup.ini".

You could then simply read from the "$EXEDIR\Setup.ini" file...


Though I would think about a different option:

Instead of using an INI file to read the info at install-time, you can use Macros and set the info a compile-time!

This way you still had to compile a different installer EXE for each product, but it could be done in a 100% automated way.

The info that differs between different products could simply be passed to MaskeNSIS.exe via CLI parameters...

(Not more work than creating an INI file for each product and no runtime dependency on the INI file)


that was what I was looking for, you think your place in the ini file "$EXEDIR" will be possible for me to copy the imformation I need.
The matter of this macro I do not quite understand, I have little knowledge of nsis.
Well, I'll try to use the "$EXEDIR" with ReadIniStr. If I have problems I'll post here.
Thank you friends


Normally you would use something like this to create shortcuts:

CreateDirectory "$SMPROGRAMS\My Company"
CreateShortCut "$SMPROGRAMS\My Company\My Program.lnk" "$INSTDIR\My Program.exe"



With Macros you could replace the hardcoded strings like this:

CreateDirectory "$SMPROGRAMS\${CompanyName}"
CreateShortCut "$SMPROGRAMS\${CompanyName}\${ProgramName}.lnk" "$INSTDIR\My Program.exe"



These would then be defined at the top of your NSI file like:

!define CompanyName "My Company"
!define ProgramName "My Program"



Either that, or you pass them directly to the NSIS compiler as arguments:

makensis.exe "/DCompanyName=My Company" "/DProgramName=My Program" Installer.nsi


In the latter case, it would be advisable to add checks like this to your NSI file:

!ifndef CompanyName
!error "CompanyName is undefined!"
!endif


my friends
Can you make more or less what it wanted.
Using $EXEDIR with ReadINIStr.

But I'm not happy because my idea was to generate a single installer and when it is executed with an ini file the installer would get the information MenuGroup shortcut name and then I would just burn a CD with an installer and an ini file. if no ini file it installs the product with the settings that are already defined in the installer.
Now so I could do with using $EXEDIR ReadINIStr I'll have to change the installer to insert five ini files:
are: Standard, Professional, Professional Plus, Advanced, Special

How could I fix it?

Thank you!


Fix what? :confused:


How about you create one installer and 5 zip files that contain the right .ini file?
Standard.zip Professional.zip etc.

They download the right installer however you do that they unzip and you read the right .ini file. Alternatively, you create one installer that requires the .ini and you mail them the .ini or have some other way to get it.
Same idea they have to have the setup.exe and the .ini in the same directory.

None of these methods is foolproof. The .ini can be easily traded for sure.


the installer can read a file, where I do not have to specify the file path or put the file in EXEDIR.
The installer could read at the level where it is? the local directory?, so I could check if the file exists then read ini settings and picks.
If there is no ini file then installs with pre-existing settings.
Thanks for the help everyone.


What do you mean with 'the local directory'?


Originally posted by wagner1308
the installer can read a file, where I do not have to specify the file path or put the file in EXEDIR.
The installer could read at the level where it is? the local directory?, so I could check if the file exists then read ini settings and picks.
If there is no ini file then installs with pre-existing settings.
$EXEDIR refers to the directory where the installer executable (e.g. Setup.exe) is located. This is determined at run-time. Read "$EXEDIR\Setup.ini" and you will be reading the "Setup.ini" that is located in the very same directory where the "Setup.exe" is located, regardless of what directory that is. You can of course check for the existence of "$EXEDIR\Setup.ini" before you do that.

Was that your question? :confused:

this explanation was that I lacked it worked, did not understand.
Thank you friends