Old 7th January 2016, 23:26   #1
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
Question Iterate List of Strings

I'm sure this must be a super simple thing, but I could not figure out how to iterate through a list of strings in NSIS. Any suggestions?
zewari is offline   Reply With Quote
Old 8th January 2016, 00:54   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,927
It would be helpful if you provided some more information. Where do the strings come from? Their format? Separators?

All you need is just StrCpy and StrCmp in a loop...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th January 2016, 22:40   #3
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
I am creating an installer for a plugin that copies different dlls based on the version of the requisite application that is installed. To do this, I have a section for each supported version of the requisite application that provides the appropriate DLLs and required steps in order to make the plugin work for the main app. All of the sections are disabled by default, and do the following in .onInit:
  1. Read the registry to determine if the required app is present.
  2. Determine if a supported version of the required app is present
  3. Enable the section that corresponds to the supported version

I'm using a bunch of "If" statements to check each version supported by my plugin and would like to reduce the redundant code by using a for loop to check for each version. I take this approach because the registry hive for the required app is a little funky. For the sake of argument, let's say the supported versions are:
  • 1.2.1
  • 1.2.2
  • 1.3.0
  • 1.3.1

Versions 1.2.1 and 1.2.2 would be under a hive named 'Software1.2', whereas versions 1.3.0, 1.3.1 would be under 1.3.

Instead of having a bunch of If statements where I have the same redundant code that checks the registry value like I do now, I would like to have a list of strings and a for statement that steps through each value.

If this were Python, what I want to do would look something like this:
code:

supported_versions = ['1.2.1', '1.2.2', '1.3.0', '1.3.1']
for value in [1.2, 1.3]:
if ReadRegistry(<hive>, <key>) in supported_versions:
break

zewari is offline   Reply With Quote
Old 9th January 2016, 00:37   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,927
I don't speak python but here is how you can split a string into substrings:

PHP Code:
Function StrSplitOne
Exch 
$Separator
Exch 
Exch 
$String
Push 
$2
Push 
$3
StrCpy 
$2 0
loop
:
    
StrCpy $$1 1 $2
    IntOp 
$$1
    StrCmp 
$"" +3
    StrCmp 
$$0 0 loop
    IntOp 
$$1
    StrCpy 
$$$2
    IntOp 
$$1
    StrCpy 
$$"" $2
    
done
:
Pop $3
Pop 
$2
Exch 
$Remaining
Exch
Exch 
$Item
FunctionEnd

Section 
StrCpy 
$"1.2.1|1.2.2|1.3.0|1.3.1"
loop:
    
StrCmp $"" done
    Push 
$0
    Push 
'|'
    
Call StrSplitOne
    Pop 
$1
    StrCmp 
$"" next Skip empty
    
DetailPrint "Item:$1!"
next:
    
Pop $0
    
Goto loop
done
:
SectionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th January 2016, 08:51   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
http://nsis.sourceforge.net/Arrays_in_NSIS

Stu
Afrow UK 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