Old 10th March 2005, 06:53   #1
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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

Dragon_Z is offline   Reply With Quote
Old 10th March 2005, 07:37   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
In the page's Leave function, use ReadINIStr to retrieve the Text string, and then write it to the registry using WriteRegStr.

-Stu
Afrow UK is offline   Reply With Quote
Old 10th March 2005, 07:54   #3
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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
Dragon_Z is offline   Reply With Quote
Old 10th March 2005, 11:21   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 10th March 2005, 15:22   #5
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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
Dragon_Z is offline   Reply With Quote
Old 10th March 2005, 17:01   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You are reading from INI file into $R0, but writing variable $R1 to registry.

-Stu
Afrow UK is offline   Reply With Quote
Old 10th March 2005, 18:39   #7
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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

Dragon_Z is offline   Reply With Quote
Old 10th March 2005, 19:15   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 11th March 2005, 05:02   #9
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
can you show me what it should look like, please? Thx
Dragon_Z is offline   Reply With Quote
Old 11th March 2005, 06:04   #10
Installer
Guest
 
Posts: n/a
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
  Reply With Quote
Old 11th March 2005, 10:42   #11
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 11th March 2005, 18:39   #12
RDaneel
Member
 
Join Date: Nov 2001
Location: Seattle, Washington
Posts: 78
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...
RDaneel is offline   Reply With Quote
Old 11th March 2005, 23:21   #13
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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
Dragon_Z is offline   Reply With Quote
Old 11th March 2005, 23:35   #14
RDaneel
Member
 
Join Date: Nov 2001
Location: Seattle, Washington
Posts: 78
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.
RDaneel is offline   Reply With Quote
Old 12th March 2005, 03:12   #15
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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
Dragon_Z is offline   Reply With Quote
Old 12th March 2005, 14:40   #16
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
It means you haven't declared the customPageALeave Function

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

-Stu
Afrow UK is offline   Reply With Quote
Old 12th March 2005, 16:15   #17
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
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
Attached Files
File Type: zip full version.zip (3.0 KB, 192 views)
Dragon_Z is offline   Reply With Quote
Old 12th March 2005, 20:58   #18
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 12th March 2005, 23:35   #19
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
it isn't capturing the text put in the boxes, nothing is diplayed in the popup
Dragon_Z is offline   Reply With Quote
Old 12th March 2005, 23:36   #20
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Oh wait, if you're reading from a Text field, then you ReadINIStr from "State" not "Text"

-Stu
Afrow UK is offline   Reply With Quote
Old 12th March 2005, 23:40   #21
Dragon_Z
Junior Member
 
Join Date: Mar 2005
Posts: 16
OK, thx now it works, thx for your patience, it is my first project
Dragon_Z is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump