NSISArray Script Header Documentation1.0 Script header documentation contents
1.1 IntroductionThe NSISArray script header is a macro system for the NSISArray plug-in by Afrow UK. The NSISArray script header masks the plug-in calls with a more friendly scripting language syntax. Everything else is managed on the plug-in side. Information about the NSISArray plug-in is under the NSISArray Plug-in Documentation section. Before you write any code, you might want to read section 1.11 Jumping over NSISArray instructions. 1.1.1 What is an array?Arrays allow you to hold masses of data under a single 'object'. Arrays are very useful when we'd like to store an unknown amount of data. With NSISArray the arrays expand in size when more data is added. 1.1.2 NSISArray vs Afrow UK's Array.nsh script headerThe first array script header by Afrow UK uses INI files to store the data. It has many of the same functions, but all of the code is written in NSIS and reading and writing to text files makes it much much slower. The original array script header is still available here; http://nsis.sf.net/wiki/File:Array.zip, although development and support has discontinued. ^ Top
1.2 Include the script headerThe plugin DLL file (NSISArray.dll) should be placed in the NSIS plugins folder (usually C:\Program Files\NSIS\Plugins). The plugin NSH file (NSISArray.nsh) should be placed in the NSIS include folder (usually C:\Program Files\NSIS\Include). Place !include NSISArray.nsh at the top of your script to start using the script header. Any array instructions and special settings must be used afterwards and not before. 1.2.1 Special settingsSome optional special settings can be !defined before the first ${Array} instruction. These include: 1.2.1.1 !define ArrayPlugin [plugin_name]Specifies that the script header should use the [plugin_name] plug-in file name (do not include '.dll'). By default, the script header uses "NSISArray". 1.2.1.2 !define ArrayCallInstDLL [dll_path]Specifies that the script header should call the plug-in with CallInstDLL, and call a DLL file at [dll_path]. Note: [dll_path] is the full path to the NSISArray plug-in DLL file at run time. This could be for example, "$EXEDIR\dllcache\Arrays.dll". This setting overrides the ArrayPlugin special settings. 1.2.1.3 !define ArrayValVar $VarSpecifies the variable to use within the script header macros for certain purposes. If not defined, the variable $ArrayVal will be declared. 1.2.1.4 !define ArrayErrVar $VarSpecifies the variable to use for error reporting. If not defined, the variable $ArrayErr will be declared. The $ArrayErr variable will contain the error code when a array function fails. See section 1.9.1.2 Checking the $ArrayErr variable for more information. 1.2.1.5 !define ArraySetErrorsThis causes the NSISArray script header to set the NSIS error flag when a call to a plug-in function fails. For more information, see section 1.9.1.3 Checking for errors with the NSIS IfErrors function. ^ Top
1.3 Creating an arrayTo create an array, use: ${Array} myArray [x] [y] Where myArray is any custom name for an array object. The [x] and [y] parameters specify the initial array dimensions. [x] being the number of empty indices initially allocated to the array and [y] being the initial buffer length of all the array's items. Both the array's number of allocated indices and buffer lengths can be changed manually at run time with the ${myArray->ReDim} function. The minimum value of [x] can be 1 and the minimum value of [y] can be 2. Please note that the value for buffer lengths ([y]) must always allow for the NULL escaping character on the end of strings to prevent buffer overflows. For example, if you're only putting single characters in the array, the [y] value must be 2 and not 1. 1.3.1 Changing the object delimiterBy default, the array delimiter used for object functions is ->. This can be changed using: ${ArrayObj} [new_delimiter] The [new_delimiter] parameter specifies the delimiter to use, which could be any character or characters of your choice. Some of the script examples under the Examples folder use a dot (.). This function can only be used just after array creation with the ${Array} function and applies to that array object only. It also cannot be used after using the ${ArrayFunc} function. ^ Top
1.4 Initialising an array for run-time useEven after declaring an array with ${Array}, the array still needs to be initialised for use at run-time. This could be in Function .onInit or perhaps just before using the array in a Section. To initialise an array use: ${myArray->Init} You must always initialise an array before use. There are error messages specific to the NSISArray script header for this function which are listen under section 1.9.3 NSIS compiler errors. 1.4.1 Check if an array has already been initialisedTo check if an array has been initialised, use: ${myArray->Inited} [jump_if_initialised] [jump_if_not_initialised] Both [jump_if_initialised] and [jump_if_not_initialised] can be relative jumps, e.g. +2 or label jumps. Note: As the NSISArray script header is macro based, the two parameters are not optional. Use 0 or "" for either parameter for a non jump. For a compilable NSIS script example, see Examples\NSISArray\Inited.nsi. ^ Top
1.5 Declaring array functionsTo use any of the array functions available, you must declare them at the top of your script first with the ${ArrayFunc} function:
${Array} myArray1 etc... With the above example the Read, Write and Splice functions will be declared for myArray1; and the Cut and Debug functions will be declared for myArray2. Failure to declare a function for an individual array will result in the compile error: Please note that you do not need to declare the Init and Delete array functions as they are not optional. ^ Top
1.6 Array functionsNSISArray comes with plenty of functions for managing your arrays. Please note that much like in many programming languages, we refer to array items with an index number. This index number is also zero base, which means the first item in an array will be at index 0 and not 1. 1.6.1 ${myArray->Write} [index] "string"Writes "string" to [index] in myArray, overwriting any existing items or adding an item if the specified index is one greater than the current highest item index. ${myArray->Write} 0 "A string to save!" For a compilable NSIS script example, see Examples\NSISArray\Write.nsi. 1.6.2 ${myArray->WriteList} '"string 1" "string 2" "string 3" ... 'Writes a list of strings to myArray. Each separate string in quotes will become a separate array item. Any existing myArray array items that are inside the range of the item list will be overwritten. ${myArray->WriteList} '"One string" "Another string" "One more"' 1.6.2.1 ${myArray->WriteList} & ArrayCallInstDLLIf you're using the ArrayCallInstDLL special setting then you will find that you cannot use the standard ${myArray->WriteList} function. A new format is introduced to deal with passing multiple items to the plug-in. New format: For a compilable NSIS script example, see Examples\NSISArray\WriteList.nsi. 1.6.3 ${myArray->WriteListC} "string 1[char]string 2[char]..." "[char]"Writes a list of strings to myArray separated by single [char]'s. Each separate string will become a separate array item. Any existing myArray array items that are inside the range of the item list will be overwritten. ${myArray->WriteListC} "One string|Another string|One more" "|" This is ideal for working with InstallOptions ListBox controls. For a compilable NSIS script example, see Examples\NSISArray\WriteListC.nsi. 1.6.4 ${myArray->Put} [index] "string"Puts "string" into myArray at [index]. No existing items are overwritten, but moved up by one. For a compilable NSIS script example, see Examples\NSISArray\Put.nsi. 1.6.5 ${myArray->Read} $Var [index]Reads a string from [index] in myArray and places the string into $Var. For a compilable NSIS script example, see Examples\NSISArray\Read.nsi. 1.6.6 ${myArray->ReadToStack} [index_start] [index_end]Reads strings from item at [index_start] to [index_end] in myArray and places all strings onto the stack. The strings on the stack can then be looped through via Pop until a specific string is reached. Push "stop_popping" For a compilable NSIS script example, see Examples\NSISArray\ReadToStack.nsi. 1.6.7 ${myArray->Cut} $Var [index]Cuts a string from myArray at [index]. The string is placed into $Var. Any proceeding array items are moved down by one. For a compilable NSIS script example, see Examples\NSISArray\Cut.nsi. 1.6.8 ${myArray->Push} "string"Pushes "string" to the front of myArray. For a compilable NSIS script example, see Examples\NSISArray\Push.nsi. 1.6.9 ${myArray->Pop} $VarPops a string from the front of myArray into $Var. For a compilable NSIS script example, see Examples\NSISArray\Pop.nsi. 1.6.10 ${myArray->Shift} "string"Pushes a string to the end of myArray. For a compilable NSIS script example, see Examples\NSISArray\Shift.nsi. 1.6.11 ${myArray->Unshift} $VarPops a string from the end of myArray and places the string into $Var. For a compilable NSIS script example, see Examples\NSISArray\Unshift.nsi. 1.6.12 ${myArray->Reverse}Reverses the contents of myArray. For a compilable NSIS script example, see Examples\NSISArray\Reverse.nsi. 1.6.13 ${myArray->Sort} myArray2Sorts the contents of myArray alphabetically, also rearranging the contents of myArray2 into the same order. For a compilable NSIS script example, see Examples\NSISArray\Sort.nsi, Examples\NSISArray\Sort2Arrays.nsi and Examples\NSISArray\MakeFileList.nsi. 1.6.14 ${myArray->SortNumeric} myArray2Sorts the contents of myArray numerically, also rearranging the contents of myArray2 into the same order. For a compilable NSIS script example, see Examples\NSISArray\SortNumeric.nsi. 1.6.15 ${myArray->Clear}Clears the contents of myArray. All items are removed and the array size is reset to 0. For a compilable NSIS script example, see Examples\NSISArray\Clear.nsi. 1.6.16 ${myArray->Splice} [index_start] [index_end] '"string 1" "string 2" ... 'Places a list of strings at [index_start] replacing existing array items up to and including [index_end]. If [index_start] and [index_end] are equal, no existing array items are overwritten. Specifying no list of strings ('') will result in items from [index_start] up to [index_end] inclusive being deleted. If [index_end] is a negative number, the end range will be up to the end of the array minus [index_end] inclusive, and so -1 will be up to and including the last item in the array. For a compilable NSIS script example, see Examples\NSISArray\Splice.nsi. 1.6.17.1 ${myArray->Splice} & ArrayCallInstDLLIf you're using the ArrayCallInstDLL special setting then you will find that you cannot use the standard ${myArray->Splice} function. A new format is introduced to deal with passing multiple items to the plug-in. New format: The [index_start] and [index_end] parameters are explained under section 1.6.16 ${myArray->Splice} (above). 1.6.17 ${myArray->Swap} [index_1] [index_2]Swaps the strings in the two indices in myArray. For a compilable NSIS script example, see Examples\NSISArray\Swap.nsi. 1.6.18 ${myArray->Copy} myArray2Copies the contents of myArray to myArray2, overwriting any existing items. For a compilable NSIS script example, see Examples\NSISArray\Copy.nsi. 1.6.19 ${myArray->Join} myArray2Copies the contents of myArray onto the end of myArray2. For a compilable NSIS script example, see Examples\NSISArray\Join.nsi. 1.6.20 ${myArray->Concat} $Var [join_char(s)]Joins all strings in myArray together with [join_char(s)] and places the output in $Var. ${myArray->Join} $R0 " " For a compilable NSIS script example, see Examples\NSISArray\Concat.nsi. 1.6.21 ${myArray->Exists} $Var "string" [index]Finds the index of an item that is exactly equal to "string" case sensitively in myArray after [index]. Note: To search non case sensitively, use ${myArray->ExistsI} (that's a capital i) instead of ${myArray->Exists}. For a compilable NSIS script example, see Examples\NSISArray\Exists.nsi and Examples\NSISArray\ExistsI.nsi. 1.6.22 ${myArray->Search} $Var "string" [index]Searches through all items after [index] in myArray for "string" case insensitively. Note: To search non case sensitively, use ${myArray->SearchI} (that's a capital i) instead of ${myArray->Search}. For a compilable NSIS script example, see Examples\NSISArray\Search.nsi and Examples\NSISArray\SearchI.nsi. 1.6.23 ${myArray->SizeOf} $Var1 $Var2 $Var3For myArray, $Var1 will now contain the allocated buffer length for all items in the array. 1.6.24 ${myArray->SetSize} [size]Sets the new size of myArray to [size]. If the array is currently smaller than [size], new empty "" items are added. If the array is currently larger than [size], items are removed until it becomes that size. Note: This does not allocated more memory for more items to be added. To do so, use ${myArray->ReDim}. For a compilable NSIS script example, see Examples\NSISArray\SetSize.nsi. 1.6.25 ${myArray->ReadFirst} $Handle $OutVar
|
NSISArray Plug-in Documentation2.0 Plug-in documentation contents
^ Top
2.1 IntroductionThe NSISArray plug-in is a powerful extension for Nullsoft Scriptable Install System that adds support for dynamic arrays for use with the NSIS scripting language. It contains many functions that allows an NSIS programmer to dynamically create, delete and manipulate their arrays in many ways. The documentation covers all plug-in functions that the plug-in offers with general descriptions and information about their parameters. ^ Top
2.2 InstallationThe plugin DLL file (NSISArray.dll) should be placed in the NSIS plugins folder (usually C:\Program Files\NSIS\Plugins). The plugin NSH file (NSISArray.nsh) should be placed in the NSIS include folder (usually C:\Program Files\NSIS\Include). ^ Top
2.3 Plug-in DLL informationBelow is a list of general information regarding the standard NSISArray.dll plug-in:
If any of these do not fit your requirements, you will need to recompile the plug-in DLL. See section 3.0 Recompiling NSISArray. ^ Top
2.4 Creating an arrayTo create a new array, use: NSISArray::New myArray [x] [y] Where myArray is any custom name for an array object, [x] specifies the initial number of indices to allocate and [y] specifies the initial buffer lengths to use. The minimum value of [x] can be 1 and the minimum value of [y] can be 2. Please note that the value for buffer lengths ([y]) must always allow for the NULL escaping character on the end of strings to prevent buffer overflows. For example, if you're only putting single characters in the array, the [y] value must be 2 and not 1. 2.4.1 Checking if an array has been createdTo check if an array has been created, use: NSISArray::ArrayExists myArray The $Var variable will contain 1 if the array exists (has been created) or 0 if it does not exist. ^ Top
2.5 Array functionsThe NSISArray plug-in comes with plenty of functions for managing your arrays. Please note that much like in many programming languages, we refer to array items with an index number. This index number is also zero base, which means the first item in an array will be at index 0 and not 1. 2.5.1 NSISArray::Write myArray [index] "string"Writes "string" to [index] in myArray, overwriting any existing items or adding an item if the specified index is one greater than the current highest item index. NSISArray::Write 0 "A string to save!" 2.5.2 NSISArray::WriteList myArray "string 1" "string 2" ... /ENDWrites a list of strings to myArray. Each separate string in quotes will become a separate array item. Any existing myArray array items that are inside the range of the item list will be overwritten. NSISArray::WriteList myArray "String" "Another" "One more" /END 2.5.3 NSISArray::WriteListCmyArray "string 1[char]string 2[char] ... " "[char]" Writes a list of strings to myArray separated by single [char]'s. Each separate string will become a separate array item. Any existing myArray array items that are inside the range of the item list will be overwritten. NSISArray::WriteListC myArray "One string|Another|One more" "|" This is ideal for working with InstallOptions ListBox controls. 2.5.4 NSISArray::Put myArray [index] "string"Puts "string" into myArray at [index]. No existing items are overwritten, but moved up by one. 2.5.5 NSISArray::Read myArray [index]
|
Value | Feature |
---|---|
0 | No error reporting is used. |
1 | Error codes are placed on the NSIS stack before any return values associated with the function being called. |
2 | No stack errors are used but instead the plug-in will display an error message box with the function name, the error code and the message associated with that error code. |
3 | Both the stack and error message boxes are enabled. |
4 | Error messages are placed in the NSIS InstFiles Page log window. This only works inside a Section. |
5 | Both the stack and log window error messages are enabled. |
Note: Do not call this plug-in function if you also use the NSISArray script header as most macros will no longer function as expected as a result. Instead, use the ${ArrayErrorStyle} macro.
If [style] is empty ("") then the function will place the current error style number (from 0 to 5) on the NSIS stack.
Example:
; Get current ErrorStyle
NSISArray::ErrorStyle ""
Pop $R0 # Current ErrorStyle setting
NSISArray::ErrorStyle 4
; Do something
; Set ErrorStyle back
NSISArray::ErrorStyle $R0
This example demonstrates the use of ErrorStyle 1:
NSISArray::ErrorStyle 1
NSISArray::Read 3
Pop $R0 # Error code (if any)
Pop $R1 # Return value (or "" if error occured)
Below is a list of possible plug-in errors...
This will occur if you try to create two arrays of the same name with NSISArray::New (or ${myArray::Init}).
This occurs when the incorrect amount of parameters is passed to the NSISArray plug-in, or when an empty ("") value is used for a parameter that should not be empty.
Specifying an index that is either negative or greater than the number of items already existing in the array will cause this error message to occur.
You can find out the size of an array with NSISArray::SizeOf (or ${myArray->SizeOf}).
This occurs when trying to reference an array object that does not exist (has not been created).
This only occurs with NSISArray::New (or ${myArray->Init}) when you are trying to declare more than 8 arrays.
If memory allocation fails for any reason, then this error will be returned. Note that this should only happen when there is no more address space in the program's (NSIS's) default memory heap and each default. Fortunately, all programs are allocated 2GB of address space to work with, so running out of memory in which case is very unlikely.
There is a special NSIS build on the NSIS website which allows strings to be up to 8191 characters in length. This special build can be used with NSISArray for WriteListC or Concat, where a large amount of items may be added to an array or taken out of an array in one single string variable. NSISArray allocates NSIS_MAX_STRLEN bytes for array input and output. Therefore, using the NSIS 8192 characters string length special build will cause the plug-in to allocate 8192 bytes for all array input and output.
The source code includes a Visual C++ 6 .dsw file and as of v2.2 a Visual C++ 2008 .vcproj file.
Settings defines can be modified at the top of the main C++ script (NSISArray.cpp). There are individual defines for each individual function.
To perform the recompile, open up the NSISArray.dsw file in Microsoft Visual C++, go to Build > Set Active Configuration and select "NSISArray - Win32 Release". You can then do a Build > Build NSISArray.dll to build the DLL file (which will be placed in the NSIS 'Plugins' folder if you're compiling from NSIS\Contrib\NSISArray).
NSISArray Credits, Changelog & LicenseCredits
If you have an issue with NSISArray which you think could be a bug, or you need general help with using NSISArray, please post a topic in the NSISArray plug-in topic on the NSIS Forums at: Changelog
LicenseCopyright © 2010 Afrow UK This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any distribution. |