- NSIS Discussion
- How set the value of the attributes
Archive: How set the value of the attributes
LingoSag
25th March 2009 00:21 UTC
How set the value of the attributes
First,excuse my english, my native language is french
I try to set a SYMBOL with !define inside a macro.
The final target is: set the value of attribute at compile-time.
I take Caption for this exemple.
Later, if it work, I use ${If} ${Else}... for decide which value for each attributes...
I don't understand why is so difficult to set the value of this attributes
at compile-time for differents circumstances ???
-inside section...........No permit
-inside function..........No permit
-With variable............No permit
How set the value of this attributes in a flexible way ?
###############################
!macro test
!define TITLE_TEXT "SimpleTest"
!macroend
outFile "Output.exe"
Caption "${TITLE_TEXT}"
section
!insertmacro test
sectionEnd
;Don't work ???
demiller9
25th March 2009 02:04 UTC
The final target is: set the value of attribute at compile-time. I take Caption for this exemple. Later, if it work, I use ${If} ${Else}... for decide which value for each attributes
That's not going to work because
${If} ${Else} are runtime instructions and cannot modify the compile time (!define) values.
You can modify the !define values with compile time statements
!if !else !endif !ifdef and all their cousins.
Don
LingoSag
25th March 2009 03:22 UTC
Tanks Don,
I note that.
But, in my Exemple i dont use ${If} or ${Else} and the !define inside the macro
Don't work
If we can't set a value of attributes(*) with a:
macro
section
function
variable
Then How ?
(*)
AddBrandingImage
AllowRootDirInstall
AutoCloseWindow
BGFont
BGGradient
BrandingText
Caption
ChangeUI
CheckBitmap
CompletedText
ComponentText
CRCCheck
DetailsButtonText
DirText
DirVar
DirVerify
FileErrorText
Icon
InstallButtonText
InstallColors
InstallDir
InstallDirRegKey
InstProgressFlags
InstType
LicenseBkColor
LicenseData
LicenseForceSelection
LicenseText
MiscButtonText
Name
OutFile
RequestExecutionLevel
SetFont
ShowInstDetails
ShowUninstDetails
SilentInstall
SilentUnInstall
SpaceTexts
SubCaption
UninstallButtonText
UninstallCaption
UninstallIcon
UninstallSubCaption
UninstallText
WindowIcon
XPStyle
SylBou
demiller9
25th March 2009 03:58 UTC
You can use !define inside a !macro, and you can use !insertmacro in a Section or Function.
You cannot use a defined name ( ${TITLE_TEXT} ) before the !define is compiled. Because you put the !define in a macro, the name does not get its value until or unless the macro is inserted.
The error occurred in your script because the macro was inserted after (below the line where) the defined name ${TITLE_TEXT} was used.
Don
LingoSag
25th March 2009 04:34 UTC
Ok, Merci Beaucoup !
My error is very stupid...
But for the moment is not very useful.
If i want my Caption = "YesYes" if ${GoodTest} = "yes"
and "NoNo" if ${GoodTest} <> "yes"
How do that !
###########################
!define GoodTest "yes"
!macro test
!define TITLE_LABEL "WorkWithCaptionInMacro"
!macroend
section
!insertmacro test
sectionEnd
OutFile "OutPut.exe"
Caption ${TITLE_LABEL}
;??????????????????????????
demiller9
25th March 2009 04:50 UTC
!define GoodTest "yes"
!macro test
!ifndef TITLE_LABEL
!define TITLE_LABEL "WorkWithCaptionInMacro"
!endif
!macroend
!if ${GoodTest} = "yes"
!define TITLE_LABEL "yesyes"
!else
!define TITLE_LABEL "nono"
!endif
OutFile "OutPut.exe"
Caption ${TITLE_LABEL}
section
!insertmacro test
sectionEnd
LingoSag
25th March 2009 05:26 UTC
!!! WONDERFUL !!!
WithOut LogicLib
!!! FANTASTIK !!!
Tanks,Tanks,Tanks
I need time for test that with ReadINIStr and comeback with news.
Why ?
Because i want config the NSIS script with a external .ini file.
exactly like another software...
I am a Lingo programmer (Adobe Director) and i want "automatized" the process
of the my screensavers SetUp build.
Tanks a another time...
SylBou
PS: The programmation language of NSIS is very crazy.
Lingo
ActionScript
Javascript
is for the baby...
LingoSag
25th March 2009 07:46 UTC
;Don, Try this (For the Moment: Full path name for the ini file)
outfile "OutPut.exe"
Caption '$0'
BrandingText '$1'
CompletedText '$2'
ShowInstDetails show
function .onInit
ReadINIStr '$0' "F:\Data\040-WinXp-Bureau\MyConfig.ini" Main Cap
ReadINIStr '$1' "F:\Data\040-WinXp-Bureau\MyConfig.ini" Main Brand
ReadINIStr '$2' "F:\Data\040-WinXp-Bureau\MyConfig.ini" Main CompTxt
functionend
section
DetailPrint "Hello World"
sectionend
############
;Don't work with outfile. I dont know because
Hooups ini file
ini file...
[Main]
Cap=MyCaption
Brand=MyBrand
CompTxt=MyCompletedTxt
demiller9
25th March 2009 08:02 UTC
You can't change the Outfile parameter because the .onInit Function is called during runtime and contains runtime statements but Outfile needs a file name during compile time.
You can pass defined values into the NSIS compiler from the command line with the /D switch. Maybe that will allow you the configuration changes you are looking for.
makensis.exe /DOutFileName=Output.exe myscript.nsi
In the script you will use this define like this:
...
Outfile ${OutFileName}
...
(Edit: script name should be after the /D switches)
Don
LingoSag
25th March 2009 17:18 UTC
Ok,Three things,
After excitement, I finaly dont trust the usage of the '$0','$1','$2'...
for set the attributes values.
NSIS Crash many times and i loose confidence. (he do, but he dont like it...)
NSIS Official Doc:
"Note that these attributes can be set anywhere in the file except in a Section or Function"
--
Tanks for command line usage for set OutFile,
But the script must work also in standard way (context menu) (I dont test if overwrite)
The real basic question is:
Simple exemple, for ??? Very simple thing ???
How set (!define) the value of the PRODUCT_NAME with a external ini file (ReadINIStr) ?
###############################################
!define PRODUCT_NAME "MyApplicationName"
OutFile "${PRODUCT_NAME}.exe"
section
;
sectionEnd
###############################################
ini file
[Main]
PRODUCT_NAME=MyApplicationName
:(
demiller9
25th March 2009 18:03 UTC
You cannot use ReadIniStr during the compile time because it is a runtime command.
I think you should consider using the !SYSTEM and !EXECUTE commands to read your ini file and create a nsh header file that contains !defines for the ini values. The nsh header file can then be !included before the defined names are needed.
You will have to create a batch file, script file (pl or vbs, perhaps), or separate exe to convert the ini values for the nsh file.
I do something like that to define a build version number and the year (for the copyright data).
...
!execute "wscript.exe BuildNum.vbs"
!include "BuildNum.nsh" # create date/serial build number
...
!define COPYRIGHT "Copyright © ${YEAR} ${COMP_NAME}"
VIProductVersion "${VERSION}.${BUILDNUM}"
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
BuildNum.nsh :
!define BuildNum 9051.1
!define YEAR 2009
Don
LingoSag
25th March 2009 18:29 UTC
Is not simple, but also very interesting.
Thank you
I work on that, and come back with news...
SylBou
LingoSag
25th March 2009 20:16 UTC
Ok Don, use nsh file is a good strategy.
Edit this file with Lingo is very very easy. Directly or via an ini file, no problem.
But, please one more step with your pass answer/exemple.
If ${GoodTest} = "yes" I want set ${TITLE_LABEL} with the value of ${GoodTestDataOne}
And If ${GoodTest} <> "yes" I want set ${TITLE_LABEL} with the value of ${GoodTestDataTwo}
Possible ?
!define GoodTest "yes"
!define GoodTestDataOne "Dog"
!define GoodTestDataTwo "Cat"
!macro test
!ifndef TITLE_LABEL
!define TITLE_LABEL ""
!endif
!macroend
!if ${GoodTest} = "yes"
!define TITLE_LABEL "yesyes"
!else
!define TITLE_LABEL "nono"
!endif
OutFile "OutPut.exe"
Caption ${TITLE_LABEL}
section
!insertmacro test
sectionEnd
SylBou
demiller9
25th March 2009 21:03 UTC
!define GoodTest "yes"
!define GoodTestDataOne "Dog"
!define GoodTestDataTwo "Cat"
!if ${GoodTest} = "yes"
!define TITLE_LABEL ${GoodTestDataOne}
!else
!define TITLE_LABEL ${GoodTestDataTwo}
!endif
Outfile outfile.exe
Caption ${TITLE_LABEL}
section
sectionend
You may be making it overly complicated with TITLE_LABEL derived from GoodTestDataOne or GoodTestDataTwo. Unless you are using GoodTestDataOne and GoodTestDataTwo other places, you can eliminate them and write
!define GoodTest "yes"
!define GoodTestDataOne "Dog"
!define GoodTestDataTwo "Cat"
!if ${GoodTest} = "yes"
Caption ${GoodTestDataOne}
!else
Caption ${GoodTestDataTwo}
!endif
Outfile outfile.exe
section
sectionend
LingoSag
25th March 2009 22:08 UTC
Ok Don,
Its simple and work well, Thank you !
My Last Question (Sorry)
What's wrong with this script:
I Know is not logic, Because !insertmacro test is after
the Conditional but how do Otherwise ?
######################################
Outfile "outfile.exe"
!define FRENCH_CAPTION "MyFrenchCaption"
!define ENGLISH_CAPTION "MyEnglishCaption"
!define LOCALE_SNATIVELANGNAME '0x4'
!macro test
System::Call 'kernel32::GetLocaleInfoA(i 1024, i ${LOCALE_SNATIVELANGNAME}, t .r1, i ${NSIS_MAX_STRLEN}) i r0'
;MessageBox MB_OK $1
!macroend
!if $1 = "français"
Caption ${FRENCH_CAPTION}
!else
Caption ${ENGLISH_CAPTION}
!endif
section
!insertmacro test
sectionend
######################################
demiller9
25th March 2009 23:15 UTC
What's wrong with this script:
!if $1 = "français"
The registers don't exist or have a value during compile time (when the
!if is trying to determine true or false). The macro 'test' won't be run until the compiled code is executed by the user.
LingoSag
26th March 2009 00:16 UTC
Is not the only problem with this Stategy
Even if work, at compile time is set the value of
my system language and not the user system language.
Then, the true question now is:
How set the values of attributes(*) at run time ?
Forget the solution with '$0','$1','$2'...is not BugProof
I take one day for write the script of my screensaver installer.
And i have no idea for set a simples variables in a conditional environnement.
I musk think
Tank you, Don, for your Great Help.
SylBou
(*)
Caption
MiscButtonText
InstallButtonText
BrandingText
CompletedText
For automatic language GUI
PS:I like my lingo, is simple and very powerfull
LingoSag
26th March 2009 04:12 UTC
That is the true limitation of the NSIS
NSIS Official Doc:
"Note that these attributes can be set anywhere in the file except in a Section or Function"
They forget:
...or macro...or...variables
NSIS can run, but he can't walk...
######################################################
!include LogicLib.nsh
outFile "installer.exe"
!define LANGUAGE_DETECT_SIMULATION "français"
!define FRENCH_CAPTION "MyFrenchCaption"
!define ENGLISH_CAPTION "MyEnglishCaption"
Caption "TEMP"
!macro test
${If} ${LANGUAGE_DETECT_SIMULATION} == "français"
Caption ${FRENCH_CAPTION}
${Else}
Caption ${ENGLISH_CAPTION}
${EndIf}
!macroend
section
;
sectionEnd
Function .onInit
!insertmacro test
FunctionEnd
######################################################
Obviously Don't Work
Bye My GUI with a automatic language detect :(
PS: At .onInit event the dialog windows is not draw, this
limitation have no sens for me...
The other solution,
Dynamically change the contents of the GUI
with GetDlgItem,SendMessage,ect...it not easy beause
the .onGUIInit event
overwrite our settings,
Ok with a little timer for the first page
but we have no events for the next pages
SylBou
Comperio
26th March 2009 06:02 UTC
LingoSag,
I think before you go too much further, you should take some time to read the documentation and look at the numerous sample scripts to get a good feel for NSIS before going full bore trying to create your own scripts.
Also, posting several posts back to back usually just annoys people. :(
There are several resources available to help you--this forum, the wiki, and even your NSIS installation directory. There's also a French support site that might be of some help.
For your issues below, here's one article that might be of help:http://nsis.sourceforge.net/Language...ws_UI_Language. There's also a sample file named 'languages.nsi' in ${NSISDIR}\examples that you might want to look it.