Archive: Loops and Sections.


Loops and Sections.
I'm trying to make a code that checks the registry for information, such as the name and the location of files. How can I make the installer create a section for each key it finds, with the name ripped from the registry?

My code currectly:

Function .onInit
StrCpy $number 1
start:
ReadRegStr $0 HKLM "Software\MATY Auto Installer\Sec$number" "Name"
Pop $0
StrCmp $0 "success" ok
Goto end
ok:
StrCpy $number $number+1
Goto start
end:
FunctionEnd
How can I do this?

Thanks,

Database

You cannot create Sections dynamically.
You could instead, however, display a list with the EmbeddedLists plugin (on Wiki).

-Stu


Thanks, but this probably won't help. What I am trying to do as a whole, is set up an installer to detect new files on a server, and offer them for download.

Any ideas?
Thanks,

Database


You could create a pool of invisible sections that you'd use show for each registry key. The number of sections will be limited but you'll be able to dynamically "create" sections.


I've done this many a time. I wrote a number of programs in NSIS with dialogs for selecting files for download. The list of files was stored as plain text on a server and downloaded when the program was ran.
I always just used an InstallOptions list box control, but for future projects I can use EmbeddedLists either with a checked list box, or a tree view control with check boxes (almost identical to the one on the NSIS Components page).

-Stu


Wow, very useful. The problem is that I need the file with the file locations to be seperate from the installer, so it can be easily updated every time the installer is run.


Another thing: Can you elaborate on how you did the list of files, and how you got the installer to read them?


List of files:
http://hmd.hostileintent.org/swupdat...s/swupdata.txt

To read from the file, used FileOpen, FileRead and FileClose.
Files are downloaded with the InetLoad plugin.

Edit: this is called SwUpdata, which is at http://swupdata.sf.net

-Stu


Wow, very cool. I'm using an INI file again now... I'll probably do the same thing as you've done :)

-Data


OK, I'm trying to create a loop for this, so it loops through and propogates the sections with the names, descriptinos, and locations of the files.

This is the code so far for the whole program:

Var number
Var number2

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\MATY Auto Updater"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show

Function .onInit
ReadINIStr $0 $EXEDIR\settings.ini Sec$number Name
SectionSetText SEC$number2 $0
FunctionEnd

Section "" SEC01
ReadINIStr $1 $EXEDIR\settings.ini Sec00 Location
NSISdl::download $1 $exedir\temp\$0.zip
CreateDirectory $INSTDIR\abortbedmaking
SectionEnd

Section "" SEC02
ReadINIStr $1 $EXEDIR\settings.ini Sec01 Location
NSISdl::download $1 $exedir\temp\$0.zip
CreateDirectory $INSTDIR\abortbedmaking
SectionEnd

Section "" SEC03
ReadINIStr $1 $EXEDIR\settings.ini Sec02 Location
NSISdl::download $1 $exedir\temp\$0.zip
CreateDirectory $INSTDIR\abortbedmaking
SectionEnd

Section -Extract
IfFileExists $exedir\temp\abortbedmaking.zip a b
a:
nsisunz::UnzipToLog "$exedir\temp\abortbedmaking.zip" "$instdir\abortbedmaking"
Pop $0
StrCmp $0 "success" b
DetailPrint "$0" ;print error message to log
b:

SectionEnd

Section -Post
Sleep 5000
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe"
Delete $exedir\temp\*.*
SectionEnd

; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
ReadINIStr $2 $EXEDIR\settings.ini Sec00 Description
!insertmacro MUI_DESCRIPTION_TEXT ${SEC01} $2
!insertmacro MUI_FUNCTION_DESCRIPTION_END
-Data