NSISList plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
Line 41: Line 41:
Here is a simple example of how to use NSISList:
Here is a simple example of how to use NSISList:


<highlight-nsis> !include NSISList.nsh
<highlight-nsis>!include NSISList.nsh
  ReserveFile "${NSISDIR}\Plugins\NSISList.dll"
ReserveFile "${NSISDIR}\Plugins\NSISList.dll"


  Name "NSISList Example Installer"
Name "NSISList Example Installer"
  OutFile "NSISList_Example.exe"
OutFile "NSISList_Example.exe"
    
    
  Section
Section
    ${List.Create} MyList                        ; Create a listed named "MyList"
  ; Create a listed named "MyList"
    ${List.Add} MyList "Jimmy Pop Ali"          ; Add "Jimmy Pop Ali" to the list identified by "MyList", this will become item #0
  ${List.Create} MyList
    ${List.Add} MyList "Lüpüs Thünder"           ; Add "Lüpüs Thünder" to the list identified by "MyList", this will become item #1
  ; Add "Jimmy Pop Ali" to the list identified by "MyList", this will become item #0
    ${List.Add} MyList "Evil Jared Hasselhoff"  ; Add "Evil Jared Hasselhoff" to the list identified by "MyList", this will become item #2
  ${List.Add} MyList "Jimmy Pop Ali"
    ${List.Count} $0 MyList                     ; Calculate the number of items in the list identified by "MyList", $0 will be set to 3
  ; Add "Lüpüs Thünder" to the list identified by "MyList", this will become item #1
    ${List.Get} $1 MyList 1                     ; Get the item at index #1 from the list idedntified by "MyList", $1 will be set to "Lüpüs Thünder"
  ${List.Add} MyList "Lüpüs Thünder"
    DetialPrint "Count: $0"                     ; Some output for the user
   ; Add "Evil Jared Hasselhoff" to the list identified by "MyList", this will become item #2
    DetialPrint "Item at #1 is: $1"             ; And some more output for the user
  ${List.Add} MyList "Evil Jared Hasselhoff"
    ${List.Destroy} MyList                      ; We are done here, so destroy the list identified by "MyList"
  ; Calculate the number of items in the list identified by "MyList", $0 will be set to 3
    [...]                                        ; Put some more important stuff here ;-)
  ${List.Count} $0 MyList                       
    ${List.Unload}                              ; Don't forget to unload the NSISList plugin at the end !!!!!
  ; Get the item at index #1 from the list idedntified by "MyList", $1 will be set to "Lüpüs Thünder"
   Section</highlight-nsis>
  ${List.Get} $1 MyList 1
  ; Some output for the user
  DetialPrint "Count: $0"
  ; And some more output for the user
  DetialPrint "Item at #1 is: $1"
  ; We are done here, so destroy the list identified by "MyList"
  ${List.Destroy} MyList
 
  ; Put some more important stuff here ;-)
  [...]
 
  ; Don't forget to unload the NSISList plugin at the end !!!!!
   ${List.Unload}
Section</highlight-nsis>


Please see "Examples\NSISList\NSISList_Test.nsi" for a more detailed example!
'''Please see "Examples\NSISList\NSISList_Test.nsi" for a more detailed example!'''


== Download ==
== Download ==

Revision as of 18:07, 12 July 2008

Introduction

A list is a dynamic data storage. It can contain an arbitrary number of items (strings) and grows dynamically. Each list is identified by a unique name, so you can handle multiple lists at the same time. Nevertheless there is a default list identified by "", which can be used if you only need one list at a time. You can create a new named list using the "Create" instruction. Initially your list will be empty. Once you have created a list, you can append as many items to as you need by calling the "Add" instruction. Alternatively you can insert items at a specified index by calling the "Insert" instruction. Items at a specified index can be read or overwritten by calling the "Get" or "Set" instructions. You can also get the first or the last item of your list by calling the "First" or "Last" instructions. In case you need to obtain ALL items of your list at once, you can call the "All" or "AllRev" instructions. The number of items in your list can be calculated by calling the "Count" instruction. If you need to find a specified item in your list, you can call "Index" in order to obtain it's current index. Furthermore you can move an item within your list by calling the "Move" instruction. Additionally you can exchange two specified items in your list by calling the "Exch" instruction. Calling the "Sort" instruction will sort all items in your list in alphabetical order. If you need to remove a specified item from your list, you can call the "Delete" instruction. You can also call "Pop" in order to obtain the last item of your list and remove that item simultaneously. The "Clear" instruction will remove ALL items from your list, but the list itself will survive. Once you are done working with your list, call "Destroy" in order to free all memory used by that list. Last but not least you can load or save your list from/to a plain text file by calling "Load" or "save". The "Debug" instruction is intended for developers, it will display all existing lists and all of their items.

Usage

If you want to use NSISList, the header file "NSISList.nsh" must be located in your "NSIS\Includes" folder. Furthermore the plugin file "NSISList.dll" must be located in your "NSIS\Includes". Please make sure that your "NSISList.nsh" and "NSISList.dll" files are at the same release version!

In order to enable NSISList in your installer, please put these lines on the top of your script:

!include NSISList.nsh
ReserveFile "${NSISDIR}\Plugins\NSISList.dll"

After you are done working with NSISList, call the ${List.Unload} macro in order to undload the plugin !!! The ".onGUIEnd" callback-function might be a good place to do so...

Example

Here is a simple example of how to use NSISList:

!include NSISList.nsh
ReserveFile "${NSISDIR}\Plugins\NSISList.dll"
 
Name "NSISList Example Installer"
OutFile "NSISList_Example.exe"
 
Section
  ; Create a listed named "MyList"
  ${List.Create} MyList
  ; Add "Jimmy Pop Ali" to the list identified by "MyList", this will become item #0
  ${List.Add} MyList "Jimmy Pop Ali"
  ; Add "Lüpüs Thünder" to the list identified by "MyList", this will become item #1
  ${List.Add} MyList "Lüpüs Thünder"
  ; Add "Evil Jared Hasselhoff" to the list identified by "MyList", this will become item #2
  ${List.Add} MyList "Evil Jared Hasselhoff"
  ; Calculate the number of items in the list identified by "MyList", $0 will be set to 3
  ${List.Count} $0 MyList                      
  ; Get the item at index #1 from the list idedntified by "MyList", $1 will be set to "Lüpüs Thünder"
  ${List.Get} $1 MyList 1
  ; Some output for the user
  DetialPrint "Count: $0"
  ; And some more output for the user
  DetialPrint "Item at #1 is: $1"
  ; We are done here, so destroy the list identified by "MyList"
  ${List.Destroy} MyList
 
  ; Put some more important stuff here ;-)
  [...]
 
  ; Don't forget to unload the NSISList plugin at the end !!!!!
  ${List.Unload}
Section

Please see "Examples\NSISList\NSISList_Test.nsi" for a more detailed example!

Download