Archive: Rebuild a registry key list


Rebuild a registry key list
Hello guys,

I've wrote an instalation program (with NSIS Installer) for my application in AutoCAD.
Everything is OK at installation, but for uninstall function i need some help from you.
I'm a newbie with NSIS language, and i must finish asap my installation pack.
So, under a key i have a number of string values which follow the rule:

Value name: "index_number"Startup
Value data: a string which is the path to a specified file

For example:
1Startup "d:\Myapp\lisp1.lsp"
2Startup "d:\Myapp\lisp2.lsp"
3Startup "d:\Myapp\lisp3.lsp"
4Startup "d:\Myapp\lisp4.lsp"
5Startup "d:\Myapp\lisp5.lsp"
6Startup "d:\Myapp\lisp6.lsp"
NumStartup "6"

At the end exist a key, named "NumStartup" and its value is equal with a number which reppresent the number of files "loaded" under this key (like an index)

In the time of uninstall, i want to erase for example the fourth key (4Startup "d:\Myapp\lisp4.lsp") and to change value of NumStartup from 6 to 5.
This part i've done, but i need to rebuild the key's value name in ascending order.

The situation appear like follow (after erase of the fourth key):

1Startup "d:\Myapp\lisp1.lsp"
2Startup "d:\Myapp\lisp2.lsp"
3Startup "d:\Myapp\lisp3.lsp"
5Startup "d:\Myapp\lisp5.lsp"
6Startup "d:\Myapp\lisp6.lsp"
NumStartup "5"

What i'll need to obtain:

1Startup "d:\Myapp\lisp1.lsp"
2Startup "d:\Myapp\lisp2.lsp"
3Startup "d:\Myapp\lisp3.lsp"
4Startup "d:\Myapp\lisp5.lsp"
5Startup "d:\Myapp\lisp6.lsp"
NumStartup "5"

This job, at this moment, i can't handle it; and i'm asking you if anyone can help me (or guide me) to finish up my job.

And another question. I have a key which contain some paths linked with ";" character, like:
C:\ACADM2000\acadm;C:\ACADM2000\help;C:\ACADM2000\FONTS;D:\My work;
How can I search for a specified path inside this string, erase it, and rebuild the string without it.

I don't know if i was explicit by I try with an example.

I have this key:
Value name: ACAD
Value data: "C:\ACADM2000\acadm;C:\ACADM2000\help;C:\ACADM2000\FONTS;D:\My work;"

I want to search and erase the substring "C:\ACADM2000\help;C:\ACADM2000\FONTS;" from initial string to obtain
C:\ACADM2000\acadm;D:\My work;

That's all.
Thanks in forward,
Lucian :)


Hmm... let's see...

This code should fix the list order.

 Push $R0
Push $R1
Push $R2

; Change this to ReadRegDWORD if necessary
ReadRegStr $R0 HKCU "Software\Something" "NumStartup"

StrCpy $R1 0 ; "fix pointer"
StrCpy $R2 0 ; pointer

loop:
StrCmp $R2 $R0 end 0
IntOp $R1 $R1 + 1

notfound:
ClearErrors ; just to make sure
IntOp $R2 $R2 + 1
StrCmp $R2 $R0 end 0

ReadRegStr $R3 HKCU "Software\Something" "$R2Startup"
IfErrors notfound 0
DeleteRegValue HKCU "Software\Something" "$R2Startup"
WriteRegStr HKCU "Software\Something" "$R1Startup" $R3
Goto loop

end:
IntOp $R1 $R1 - 1
WriteRegStr HKCU "Software\Something" "NumStartup" $R1

Pop $R2
Pop $R1
Pop $R0

Probably There are easier way to do this, but my brain needs food. :)

You might want to check out AfrowUK's NSISArray plugin--it would make it easier to switch the order of elements and such without having to make your brain hurt so much! ;)

and for this:

C:\ACADM2000\acadm;C:\ACADM2000\help;C:\ACADM2000\FONTS;D:\My work;
How can I search for a specified path inside this string, erase it, and rebuild the string without it.
You should have a look at Instructor's Word/String/File functions. (BTW: Most of Instructor's functions are included with the latest builds of NSIS--have a look at the help files for for info.)