Archive: Compile-time/Run-time defines


Compile-time/Run-time defines
Hello,

I've read all related topics and documentation , but still
confused and dont know if it's possible to do what i need with NSIS installer.

I'm building setup packages for different affiliates.
Set of setup files is the same , but what changes is
packages name and installation folder.

Before running the setup , there is some small pre-setup
utility that can write values to registry.

The question is : is it possible "to tell" nsis to take
these values from registry and not to "hardcode" them in the script ?


Here's my current installation script:
---------------------------------

!define MUI_PRODUCT "AAASoft" ;Define your own software name here
!define MUI_PRODUCT_LINK "AAA Soft" ;Define your own software short cut here
!define MUI_VERSION "2.1" ;Define your own software version here

!define MUI_ICON "C:\SoftProjectV2\IconBig.ico"
!define MUI_UNICON "C:\SoftProjectV2\IconBig.ico"

SetCompress Off
!include "MUI.nsh"

;--------------------------------
;Configuration
AutoCloseWindow true ;

;General
OutFile "C:\SoftProjectV2\SoftSetup.exe"

;Folder selection page
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"

!define MUI_UNINSTALLER
;--------------------------------
;Language

!insertmacro MUI_LANGUAGE "English"
;--------------------------------
BrandingText "Installing soft"
;--------------------------------
;Installer Sections

Section "CopyingFiles"
SetOutPath "$INSTDIR"
FILE "C:\SoftProjectV2\SoftDLLS\file1.dll"
FILE "C:\SoftProjectV2\SoftDLLS\file2.dll"
FILE "C:\SoftProjectV2\SoftDLLS\file.exe"
SectionEnd

;Add Shortcuts

Section "SettingEnvironment"
SetOutPath $INSTDIR
;Create Desktop Icon
CreateShortCut "$DESKTOP\${MUI_PRODUCT_LINK}.lnk" "$INSTDIR\soft.exe"
CreateShortCut "$SMPROGRAMS\${MUI_PRODUCT_LINK}.lnk" "$INSTDIR\soft.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT_LINK}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" "$INSTDIR\Uninst.exe"
WriteUninstaller "$INSTDIR\Uninst.exe"
SectionEnd

;--------------------------------

;Uninstaller Section

Section "Uninstall"

;Delete Files
Delete "$INSTDIR\*.*"

;Delete Desktop Icon
Delete "$DESKTOP\${MUI_PRODUCT_LINK}.lnk"

;Delete Start Menu Shortcuts
Delete "$SMPROGRAMS\${MUI_PRODUCT_LINK}.lnk"

Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR\"

;Delete Uninstaller And Unistall Registry Entries
DeleteRegKey HKEY_CURRENT_USER "SOFTWARE\${MUI_PRODUCT}"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
DeleteRegKey /ifempty HKCU "Software\${MUI_PRODUCT}"

SectionEnd


Function .onInstSuccess
ExecShell open "$INSTDIR\Soft.exe"
FunctionEnd
;eof

--------------------------------------------------------

What i need is small modification , so if there's some specific known location in registry defining product name - script will take it from there.

Thanks a lot!




P.S. I found out that "InstallDirRegKey" command might help,
is it correct direction ?


The easiest solution is to let the utility write a NSIS include file or to create an application that reads a few registry settings and writes an include file.


Do you want to be able to read the registry entries at compile-time, when the script is made on your machine, or at run-time from the users machine?

For compile-time mods you will have to create another little program which will read these entries and write them into a NSIS compatible include file which then can be included into the main script. To execute the program you will have to use the '!system' command.

If you want to chage these at runtime simply read them using the registry functions available in NSIS. To modify the name it-self you might need to define it with a variable and then set the variable at run-time.

I hope this helps you!

Vytautas ;)

[edit]Oops joost was just a bit quicker :D[/edit]

BTW: In future could you attach long scripts.


I want these variables at run-time (on user machine).

I would appreciate if you show me specific code i need to insert.

Joost Verburg: "The easiest solution is to let the utility write a NSIS include file or to create an application that reads a few registry settings and writes an include file."

It sounds like what i need. Can you please point me to some
example using this approach ?

Vytautas : What do you mean by "In future could you attach long scripts." ? Is it a problem to paste code here ?
I deleteted unneeded strings before posting it to make it
shorter.


I think that joost's idea will only work at compile-time. You were right about the "InstallDirRegKey" command, you can see how its supposed to be used from examples available with NSIS. The thoery behind my other suggestion is that if you define the name of the installer with a variable like $1 and then change $1 at run-time the name should then also change, although I could be wrong as it depends on how NSIS Installers have their names defined internally.

As for my comment about attaching scripts it would just make the thread load quicker for us with dail-up internet :p

Vytautas