Archive: Remembering Components using loops


Remembering Components using loops
I have around 80 components in my installer and it wouldn't be very practical to store each section's flags in the registry manually especially since they are changed very frequently. So I was wondering if it's possible to store/retreive flags using a short loop that applies to all sections in general... I tried using
GetDlgItem $0 $HWND_PARENT 120x (with x increasing upon each loop but no luck... and it wouldn't work for retreiving). I would appreciate any help offered. Thank you.


wops... now I see that I can't use GetDlgItem as stated above for the components page. That explains it. Ideas anyone ?


Is Function .onSelChange enough to get the components flags using SectionGetFlags? It requires the components checkmarks selection to change. I think it may be not what you are looking for. That's because you said "short loops" so maybe it's time related.


ah good idea... but is there a way to get the id of the section that has been altered ? If so then I can use the following .onSelChange

SectionGetFlags ${SECID} $R0
WriteRegStr HKCU "blablabla" ${SECID} $R0

Yet this doesn't solve the problem of loading the remembered flags .onInit


You need to use a variable or an array to store the previous flags of all component items. Then, you can compare them all later to see which was or not changed.
There is a plug-in called "NSIS Array" that store array items. You can download it from here.

To change the selection of a component item (section or section group), you can use "SectionSetFlags" instruction. For the initialization of the flags to the implemented correctly, you should use the "PreFunction" of the "components" page. I'm not sure if that instruction works when used with the function ".onInit".


I'm not familiar with the NSISArray plugin and I read it can store a maximum limit of using 8 arrays at any one time... I would rather try something else (if available)

I am aware that I need to use SectionSetFlags in the PreComponents function, yet I don't want to have to manually add it for each section because sections change much too often.


No, you just need 1 array. You can store there up to 128 items in there (if you choose to use the line: !define ArrayPlugin 128), and this is more than enough for you. Then you could make a loop to process all the items inside and, at the same time, compare with the results of SectionGetFlags.

I'm not familiar with NSIS Array either, so we're tied :(...

I am aware that I need to use SectionSetFlags in the PreComponents function, yet I don't want to have to manually add it for each section because sections change much too often.
That's why I told you the solution above, you don't need to use an instruction for every single section. Just make a loop incrementing the section index.

EDIT:

If you don't like the plug-in, there are alternatives:
- "Array" header example for UseFunc (look at my signature) which is a little slower than using a plug-in directly, but can support an unlimited amount of items until the variable gets to the NSIS string length maximum (1024, or 8192 with special builds). Uses Math plug-in.
- Afrow UK's "Array" header using INI files (here). This is very slow, but can have an unlimited number of items. So unlimited, the only limitation is the hard drive free space.

I see, cheers for that :) I'm gonna check out the NSISArray examples and give it a go, however, if anyone can supply the proper code for this then please do.


I can't seem to get this... am I supposed to be storing the section names in the array or their flags ? :S


Well, you need to store the flags of every section because you need to compare them later so to discover which section changed...


Sorry for asking a bit too much, but won't arrays be cleared the next time the installer is executed ? Either way, I tried using your UseFunc header and got confused at what code to use .onSelChange... Sorry I'm a n00b :/


After further trails, I found out it can't be done how you said. To compare the flags of the altered section .onSelChange you need to know which section has been altered .onSelChange and that I wasn't able to achieve unless I add each section's flags to the array and that isn't what I'm after. Perhaps I'm way off, but if you think it can be done please tell me how. Thanks.


Sorry, you wanted to store the flags in the registry. WriteRegDWORD and ReadRegDWORD are used for writing to and reading from registry, respectively, with numbers. Just treat the items in the registry like in an array: value names should be consecutive or it will be difficult to make a loop.


hi everybody i'm been doing this header for very long time, this is modification of LogicLib, it sound it like "Give Me Section Flags I modify for you"... something like that, my Eng no good so i can't talk much, i needed more suggests form you guys...

example:
${IfSection} 1 "1,0,17,1"
Delete "Program_1.exe
${EndIfSection}

Strcpy $R0 "1,0,17,1" ;Section Old Flags
Strcpy $R1 "0,1,17,1" ;Section New or Current Flags
;$0 -> $4 being used

${IfSection} ${FlagIsSelected} 2 $R0
Delete "temp.tmp"
${UnlessSection} ${FlagIsSelected} 2 $R1
Delete "Program_2.exe"
${EndUnlessSection}
${EndIfSection}

same with exam above

${Section} 2 $R0 $R1
${Repair}
Delete "temp.tmp"
${Remove}
Delete "Program_2.exe"
${SectionEnd}

Can you give me example using Array to get Flags.
If you can't don't worry i firgure that out


I don't have an opinion, but you should put contributions also in the NSIS Wiki, or your contrib might be lost here in the forums, along with other contrib...


RememberComponents -script for remembering installed and uninstalled components.


I know how to get Sections Flag, what i need to know is how store section flag into Array's variable...


http://nsis.sourceforge.net/wiki/Arrays_in_NSIS

-Stu


thanks Afrow UK