Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Custom pages and registry settings (http://forums.winamp.com/showthread.php?t=210008)

Dragon_Z 10th March 2005 06:53

Custom pages and registry settings
 
I have a custom page that I made and i would like whatever is put in the TEXT fields to be saved to the registry in windows.
Thx for any help you can provide.

code:
[Settings]
NumFields=4

[Field 1]
Type=Label
Text=Name
Left=0
Right=-1
Top=0
Bottom=10

[Field 2]
Type=Text
Left=0
Right=-1
Top=10
Bottom=20


[Field 3]
Type=Label
Text=Serial Number
Left=0
Right=-1
Top=40
Bottom=50

[Field 4]
Type=Text
Left=0
Right=-1
Top=50
Bottom=60


Afrow UK 10th March 2005 07:37

In the page's Leave function, use ReadINIStr to retrieve the Text string, and then write it to the registry using WriteRegStr.

-Stu

Dragon_Z 10th March 2005 07:54

sry, don't know where the documentation for that is, can you put it in one fo the example scripts so that I can figure out where it goes, Thx alot

Afrow UK 10th March 2005 11:21

ReadINIStr and WriteINIStr are in the NSIS documentation.
For example:
code:
Page Custom customPage customPageLeave

Function customPageLeave
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\ioFile.ini" "Field 1" "Text"
WriteRegStr HKCU "Software\MyApp" "Blah" "$R0"
Pop $R0
FunctionEnd



-Stu

Dragon_Z 10th March 2005 15:22

It is creating the registry entryis now but it isn't putting anything in them. Thx for the help but I must be missing something.

code:
Function customPageA
!insertmacro MUI_HEADER_TEXT "Registration" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "registry.ini"
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
Pop $R0
Push $R1
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R1"
Pop $R1
FunctionEnd



Same INI as above

Afrow UK 10th March 2005 17:01

You are reading from INI file into $R0, but writing variable $R1 to registry.

-Stu

Dragon_Z 10th March 2005 18:39

OK, Thx but still there is nothing in the data field of the registry key

code:

Function customPageA
!insertmacro MUI_HEADER_TEXT "Registration" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "registry.ini"
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
Pop $R0
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R0"
Pop $R0
FunctionEnd




code:

[Settings]
NumFields=4

[Field 1]
Type=Label
Text=Name
Left=0
Right=-1
Top=0
Bottom=10

[Field 2]
Type=Text
Text=
Left=0
Right=-1
Top=10
Bottom=20


[Field 3]
Type=Label
Text=Serial Number
Left=0
Right=-1
Top=40
Bottom=50

[Field 4]
Type=Text
Text=
Left=0
Right=-1
Top=50
Bottom=60


Afrow UK 10th March 2005 19:15

This code needs to go in the page's Leave function:
code:

Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R0"
Pop $R0



User input from the InstallOptions dialog are not saved to the INI file until after the user leaves the page. That's why you aren't getting any data.

Declare the Leave function like so:
Page Custom customPageA customPageALeave

-Stu

Dragon_Z 11th March 2005 05:02

can you show me what it should look like, please? Thx

Installer 11th March 2005 06:04

Custom pages and registry
 
hello Installers,

I have the same problem that you are faceing .
this is a small piece of script

Function SetContentServer
Push $R0
InstallOptions::dialog $PLUGINSDIR\ContentServer_Name.ini
Pop $R0
ReadINIStr $1 "$PLUGINSDIR\ContentServer_Name.ini" "Field 2" "Text"
FunctionEnd

Function SetContentServerLeave
; Push $1
WriteRegStr HKLM "Software\Legato\ContentServer" "ServerName" "$1"

FunctionEnd


If i put the text from the Page properties before compilation it writes into the registry. but If i take it from the user at runtime it does not.

Wht could be the issue?
why does "Var varname" variable decleration not work ?

Your help will be appreciated.

Regards

Parag

kichik 11th March 2005 10:42

The leave function is called when the user clicks the next button, before the InstallOptions::dialog call returns. Simply write the value to the registry right after you read it in SetContentServer.

RDaneel 11th March 2005 18:39

While not vastly experienced in custom pages, I do have *one* and use a slightly different model... :)

I use an .onInit to check the registry for an existing value for my field - if it is present, I directly update the corresponding field in the [now expanded] INI file.

BTW, since it makes sense for my case, I use the install options length-validating feature to enforce the length restrictions for my data entry field. This blocks the user from proceeding past that page until the restrictions are satisfied.

Then, in the body of the installer section - actually, just before it completes - I do a MUI_INSTALLOPTIONS_READ to get the value of the field, and save it to the registry with a WriteRegStr.

I am posting this both to make sure that my approach is sound (it does seem to work), and to mention that using the Leave function can have the side-effect of making a registry change (in the case described above) even if the user chooses to back out of (abort) the install...

Dragon_Z 11th March 2005 23:21

this is all wonderful info and I hope to put it in my next installer, however, where should I place "Page Custom customPageA customPageALeave ", Thx

RDaneel 11th March 2005 23:35

The "page custom..." would go in the midst of your "!insertmacro MUI_PAGE*" statements.

It is just saying that you have a custom page and that it has both Enter and Leave functions defined. The precise placement determines where in the sequence of pages making up your installer it appears.

Dragon_Z 12th March 2005 03:12

tried it and got this error and it won't create any .exe now

code:
Error: resolving leave-page function "customPageALeave" in install pages
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process



Any Ideas? Thx

Afrow UK 12th March 2005 14:40

It means you haven't declared the customPageALeave Function :D

You need to do it like:
Function customPageALeave
# ... code here ...
FunctionEnd

-Stu

Dragon_Z 12th March 2005 16:15

1 Attachment(s)
ok it actually made the Installer but now it still isn't writing the registry keys. See included zip with all the code and .ini's, thx for any help you can provide

Afrow UK 12th March 2005 20:58

Put "MessageBox MB_OK $R0" under the first ReadINIStr in your Leave function to see what the value of $R0 is.

Also you don't need the Pop and Push in the middle.

-Stu

Dragon_Z 12th March 2005 23:35

it isn't capturing the text put in the boxes, nothing is diplayed in the popup

Afrow UK 12th March 2005 23:36

Oh wait, if you're reading from a Text field, then you ReadINIStr from "State" not "Text"

-Stu

Dragon_Z 12th March 2005 23:40

OK, thx now it works, thx for your patience, it is my first project


All times are GMT. The time now is 18:09.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.