- NSIS Discussion
- Help on CustomPage(s) in general
Archive: Help on CustomPage(s) in general
Mosestycoon
21st March 2003 16:14 UTC
Help on CustomPage(s) in general
Moin, moin
I have a simple request:
would it be possible to integrate somemore CustomPage examples within on of the next releases?
I tried the one packed in examples-dir, but really I am a '@§%6$#*'-user and I can't get it together to fit my needs.
What I want is a CustomPage which takes the input from a defined field. The input should than be taken to search and replace in a text file. Also to start the application as service or not (e.g. a listbox) is one of the features I need.
Would be very, very "geil" if sombody could screw some more examples.
Chris
Joost Verburg
21st March 2003 19:18 UTC
Are you using the Modern UI?
The Modern UI InstallOptions example (InstallOptions is the plugin for custom pages) shows how to get the input, it displays a messagebox when a checkbox has been checked.
The test.nsi script in Contrib\InstallOptions is an example of InstallOptions and the Classic UI, it also gets input from the page.
Mosestycoon
22nd March 2003 14:06 UTC
Thx for reply Joost.
I am using MUI. I already compiled the InstallOptions.nsi, but it's not really that big example. I thought it might be useful, if a more representative example would be integrated. (Really I could need it ;-) )
Chris
Joost Verburg
23rd March 2003 11:17 UTC
Can you please tell exactly what your problem is? The example reads a value from the file, you only have to change the field number and you can use the value.
Mosestycoon
23rd March 2003 12:03 UTC
Ok Joost,
here we go. In the attached PNG you can see a custompage as it should be displayed . I integrated three radioButtons and everyting works fine (if one is checked, the other goes unchecked)
The (wanted) mechanism:
+ Possibility number 1:
By checking the RadioButton, a different file is installed and this file is dynamically modified with 'search and replace function' later on. So the user decides which service to be installed. This value needs to be passed to some FILE option.
(think I am bad in explaining :-))
e.g.:
mysqld-opt.exe is checked my.1.cfg is installed and modified later on
mysqld-nt-max.exe is checked my.2.cfg is installed and modified later on.
(blablabla)
+ Possibility number 2:
There is only one my.cfg-file. There is a directive in it:
Server=Path/to/MySQL4/bin/mysqld-***.exe
>
This mysql-***.exe is replaced by the value checked with that RadioButton
e.g.:
if 'mysqld-opt.exe' is checked, than mysqld-***.exe is replaced with the string mysqld-opt.exe
if mysqld-nt-max.exe is checked, mysqld-***.exe is replaced with the string mysqld-nt-max.exe
(blablabla)
OK, and in this case I'm down and out. I am not a programmer as you can suppose :cry:
Please be patient
Chris
Joost Verburg
23rd March 2003 13:35 UTC
Use the MUI_INSTALLOPTIONS_READ macro to get the state of an option button.
Example:
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "io.ini" "Field #" "State"
StrCmp $R0 1 "" noOption1 ;check whether the option is selected
...copy the files for option 1...
noOption1:
Mosestycoon
23rd March 2003 14:51 UTC
Originally posted by Joost Verburg
Example:
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "io.ini" "Field #" "State"
StrCmp $R0 1 "" noOption1 ;check whether the option is selected
...copy the files for option 1...
noOption1:
-------------->
So correct me, to get the different states of different RadioButtons, I need some more lines:
"StrCmp $R0 1 "" noOption2 ;check whether the option is selected
...copy the files for option 2...
noOption2:
What is the meaning of the 1 after $R0 and the empty quote?
Again, please be patient
Thx
Chris
Joel
23rd March 2003 15:19 UTC
To disable the RadioButtons use the "Flag=Disable"
For example, like Joost Verburg wrote:
Function "XXX"
;read the first RadioButton
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "io.ini" "Field #" "State"
StrCmp $R0 "1" +1 NoCheck ;What's the state of the Radio 1=Check 0=NoCheck
;Put the code that you need to run with this
...
;Disable the others RadioButtons
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Flags" "DISABLED"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Flags" "DISABLED"
Goto End
NoCheck:
;We repeat the above the code for the others RadioButtons
End:
FunctionEnd
I didn't try the code ... :( But I think that use it with "Sections"
will get your task very well,
did you read the $NSISDIR\NSIS\Examples\one-section.nsi
Mosestycoon
23rd March 2003 15:29 UTC
No, I haven't tried the one-section.nsi example, but I have the following solution now, and it seems to work...
Section "mysql" SecMySQL
SetOutPath "$INSTDIR"
File "Path\to\mysqld.exe"
;; if mysqld-nt.exe is installed, than copy my.nt.ini to WINDIR
;; -----------------
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioA.ini" "Field 3" "State"
StrCmp $R0 1 "" noOption1 ;check whether the option is selected
SetOutPath "$WINDIR"
File "Path\to\my.nt.ini"
...function to search and replace...
noOption1:
;; if mysqld-opt.exe is installed, than install my.opt.ini
;; -----------------
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioA.ini" "Field 4" "State"
StrCmp $R0 1 "" noOption2 ;check whether the option is selected
SetOutPath "$WINDIR"
File "Path\to\my.opt.ini"
...function to search and replace...
noOption2:
;; if mysqld-max-nt.exe is installed, than install my.max-nt.ini
;; -----------------
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioA.ini" "Field 5" "State"
StrCmp $R0 1 "" noOption3 ;check whether the option is selected
SetOutPath "$WINDIR"
File "Path\to\my.max-nt.ini"
...function to search and replace...
noOption3:
SectionEnd
Could you please verify that?
Thx in advance UR GR8 !
Chris aka MosesTycoon
if mosestycoon is '*§$%#&'
then ask @ FORUM
fi
;)
Joel
23rd March 2003 15:39 UTC
Seems to be :up:
If it worked than :)
Mosestycoon
23rd March 2003 15:43 UTC
Dark Boy -
;Disable the others RadioButtons
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Flags" "DISABLED"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Flags" "DISABLED"
Goto End
Why do I need that part?
Chris
Joel
23rd March 2003 15:48 UTC
Didn't you want to disable the other radio buttons if
one is check? :p
Well is for that, why? I doesn't work?
kichik
23rd March 2003 16:00 UTC
StrCmp $R0 1 "" noOption2
means compare $R0 to 1, if equal jump to "" (which is the same as 0 or +1, which just means next line), if not jump to the noOption2 label.
Mosestycoon
23rd March 2003 16:17 UTC
Welcome on discussion KichiK,
as you joined, perhaps you can answer a corresponding question?
As you already read the thread I have posted this "Section" which works double-:-)
So as far as that is not enough, I work on a more complicated version of this, here a snippet:
SetOutPath "$INSTDIR"
File "\Path\to\bin\mysqld-nt.exe"
;; if mysqld-nt.exe is installed, than...
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioA.ini" "Field 3" "State"
StrCmp $R0 1 "" noOption1 ;check whether the option is selected
SetOutPath "$WINDIR"
File "\Path\to\my.nt.ini"
;;--------------------------------
;; here we try to edit some lines in that copied file with search and replace
ClearErrors
FileOpen $0 "$WINDIR\my.nt.ini" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "++basedir++$\r$\n" 0 +3
FileWrite $1 "basedir=$INSTDIR$\r$\n"
Goto loop
StrCmp $2 "++datadir++$\r$\n" 0 +3
FileWrite $1 "datadir=$INSTDIR\data$\r$\n"
Goto loop
StrCmp $2 "++language++$\r$\n" 0 +3
FileWrite $1 "language=$INSTDIR/share/german$\r$\n"
Goto loop
StrCmp $2 "++Server++$\r$\n" 0 +3
FileWrite $1 "Server=$INSTDIR/bin/mysqld-nt.exe$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "$WINDIR\my.nt.ini"
Rename $R0 "$WINDIR\my.ini"
;Disable the others RadioButtons
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioA.ini" "Field 4" "Flags" "DISABLED"
!insertmacro MUI_INSTALLOPTIONS_WRITE "ioA.ini" "Field 5" "Flags" "DISABLED"
noOption1:
...
; code for Option2 (if RadioButton2 is checked)
...
; code for Option3 (if RadioButton3 is checked)
So this works fine, but when I use the same again (for the other two RadioButtons) the compiler quits with:
Error: label "loop:" already declared in section/function
Error in script "C:\NSIS\INSTALL_OPTIONS\InstallOptions.nsi" on line 205 -- aborting creation process
I think I understand this, but what can I do against.
The way it should work:
Section:
RadioButton 1 checked: copy FileA to $WINDIR and modify it...
RadioButton 2 checked: copy FileB to $WINDIR and modify it...
FileA and FileB are almost the same, except in one line:
mysqld-opt.exe (e.g. FileA) and mysqld-nt.exe (FileB)
(And there will be a third one...)
Thx Chris
Mosestycoon
23rd March 2003 16:20 UTC
Originally posted by Dark Boy
Didn't you want to disable the other radio buttons if
one is check? :p
Well is for that, why? I doesn't work?
I think this is done by default if the io.ini contains the several "State" values and FLAGS=Group ?
Chris
---[Added]---
Ahhh, sorry! I haven't answered your question: it works :D
kichik
23rd March 2003 16:23 UTC
Three things before we get to the real problem:
1) Please attach large scripts next time.
2) If you disable the radio buttons the user won't be able to change his selection when he returns to the page.
3) I suggest you move all of the extraction and file changing code into a section so the user will get a chance to change his selection.
Now for the problem, you have two options:
1) Change loop to something else in each block.
2) Create a function out of this code that takes the file name to change off the top of the stack or just out a variable.
Mosestycoon
23rd March 2003 16:27 UTC
Originally posted by kichik
Three things before we get to the real problem:
1) Please attach large scripts next
I will, sorry
;)
Mosestycoon
23rd March 2003 16:39 UTC
OK
I attached the snippet. I just renamed loop to loop1 or loop2 (the same for done)
and it works
Really cool support, guys
Again and again and again
I love NSIS and all of you supporters (not for real :D)
Chris
P.S.:
By the way, when everything is finished with that CustomPage-bla, I try to write some comments on the snippet and post it at archive. I think this could help many non-programmers like me
But be sure I need some more help, because this was the smaller part of the script...