You are here

Saving REG_MULTI_SZ values via custom code.

19 posts / 0 new
Last post
scriptdaemon
Offline
Last seen: 3 years 2 months ago
Developer
Joined: 2008-10-10 17:40
Saving REG_MULTI_SZ values via custom code.

CppCheck saves application paths in the registry as a REG_MULTI_SZ, which is saved to the .reg file in hex.

Example line from CppCheck.reg file (saved from launcher):

"Application paths"=hex(7):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,\
  00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,\
  36,00,29,00,5c,00,4e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,2b,00,5c,\
  00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,2b,00,2e,00,65,00,78,00,\
  65,00,22,00,00,00,00,00

NSIS isn't a language I use often, so I'm wondering if anyone's able to help me write some custom code to save this as an array of strings, traverse through the strings and update path letters and so on, then save back to hex to the .reg file.

I tested some things from the registry plugin, but I'm obviously doing it wrong because even the basic parts aren't working for me. >.>

${SegmentFile}

${SegmentPrePrimary}
    ${registry::Read} "HKEY_CURRENT_USER\Software\Cppcheck\Cppcheck-GUI" "Application paths" $0 $1

    ${registry::Write} "HKEY_CURRENT_USER\Software\Cppcheck\Cppcheck-GUI" "Application paths" "Test" $1 $2
!macroend
Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
I'm interested in the results

I'm interested in the results of this as well, as I'm having issues doing the same thing with kchmviewer.

Here's my custom.nsh: http://pastebin.com/faJGSt3w

It includes message boxes for debugging.

[EDIT]
I found this: http://nsis.sourceforge.net/REG_MULTI_SZ_Reader
but can't figure it out.

Bart.S
Offline
Last seen: 2 days 18 hours ago
Developer
Joined: 2008-07-23 07:56
Custom

My FreeMat Portable launcher adjusts paths stored as REG_MULTI_SZ and *.reg file in hex. Be warned, it's custom and not PAL. 8)

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
This section

Hi Bart.S,

Is this the portion of your launcher that does it? http://pastebin.com/uJdaTs3F

If so, it should be pretty simple to implement as custom code with PAL.

Bart.S
Offline
Last seen: 2 days 18 hours ago
Developer
Joined: 2008-07-23 07:56
Sure,

that's why it's called AdjustKeys. Blum

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Wanted to make sure

Thanks, I just wanted to make sure I was looking at the right thing. It's not working quite right for me yet, but that's because I'm trying to use a PAL variable for changing the drive letters, rather than duplicating code. Hopefully I can figure out how to do it soon. fun times Smile

scriptdaemon: I've pushed the changes I'm using to my repo for kchmviewer if you want to copy/paste.

scriptdaemon
Offline
Last seen: 3 years 2 months ago
Developer
Joined: 2008-10-10 17:40
Awesome.

I'll take a look at it later when I get home.

EDIT: Rather odd, but when it saves to the registry, it puts a space between every character.

${SegmentFile}

${SegmentPreExec}

    # Code courtesy of Bart.S
    ${registry::Read} "HKEY_CURRENT_USER\Software\Cppcheck\Cppcheck-GUI" "Application paths" $R0 $R1
    ${If} $R0 != ""
        ${WordReplace} $R0 "%PAL:LastDrive%%PAL:LastPackagePartialDir%" "%PAL:Drive%%PAL:PackagePartialDir%" "+" $R2
        ${WordReplace} $R2 "%PAL:LastDrive%" "%PAL:Drive%" "+" $R2
        ${registry::Write} "HKEY_CURRENT_USER\Software\Cppcheck\Cppcheck-GUI" "Application paths" $R2 $R1 $R3
    ${EndIf}
!macroend
Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Same here

That's the same issue I'm having.

scriptdaemon
Offline
Last seen: 3 years 2 months ago
Developer
Joined: 2008-10-10 17:40
I can't really see anything

I can't really see anything obvious, so I'll stick in a few messageboxes after I go shopping to debug (if you don't figure it out already by then).

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
my preliminary debugging

I've updated my custom.nsh with some WordReplace error debugging, and this is what I've found so far:

As it stands right now, I get an error level of 1, or "word to replace not found".

Obviously, I need to adjust my WordReplace syntax. I'm just not sure what the issue is at the moment. I'll look into it some more.

Chris Morgan
Chris Morgan's picture
Offline
Last seen: 7 years 7 months ago
Joined: 2007-04-15 21:08
Code style

Just a bit on code style: http://pastebin.com/rbDBde6Y

I am a Christian and a developer and moderator here.

“A soft answer turns away wrath, but a harsh word stirs up anger.” – Proverbs 15:1

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 3 days 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Thanks

Thanks for the heads-up. I was the using the code shown on the NSIS wiki page for WordReplace.

I added some more message boxes to the code, and cleaned up read/writing a bit, and have determined that the issue lies with $Registry::Read adding a space in between characters in the string. On a second run, it adds another space in between characters. Just noticed this was pointed out above. Still not sure what is causing it, other than that it IS a $Registry::Read error.

I am determining this based on the $R0 message boxes.

[EDIT] OOPS, forgot to link to my updated one: http://pastebin.com/GRzySE2D

3D1T0R
3D1T0R's picture
Offline
Last seen: 1 year 6 months ago
Developer
Joined: 2006-12-29 23:48
Yes; No; & More:

Yes:
The addition of something between each character of the string being read is caused by some error in {$Registry::Read}

No:
Those "space"s are actually hex 0x00's, which the Registry (and apparently NSIS) treats as new lines ($\n in NSIS)

More:

  • Custom.nsh apparently doesn't handle Environment Variables in the %VAR% format, so you need to read them to NSIS style Variables ($VAR format) before they'll do what you want.
  • I wrote a Custom.nsh for CppCheck Portable today which I think works (it only changes the Drive letter, ScriptDaemon's updates the PackagePartialDir too, but [in my quick test setup at least] that wasn't doing anything, so I dropped it), and I'd like to have you guys look at it (if it works for you, you can have it).
  • In my Custom.nsh for CppCheck Portable I moved the work into a macro, and used that macro thrice so as to update "Check path", and "Global include paths" as well.
  • In my Custom.nsh for CppCheck Portable I Added some "DebugMsg"s but I couldn't get PAL to do anything with them, maybe someone could help me with that?
  • I used OpenPlatform's Custom.nsh for Lazarus Portable as the basis for some of mine for CppCheck Portable, so I've added him (and me) to the Code courtesy of… section, I hope that's all OK.
  • I would have tried to do something with KchmViewer Portable too, but I didn't see a DevTest to download & play with, sorry.
    (Maybe I'll grab it from your BitBucket repository and see what I can do with it, but that'll have to wait a day or two [or more])
  • Here's a link to my Custom.nsh for CppCheck Portable, Hopefully it helps you guys, and if it works for you, you can have it.

Edit: Changed my line regarding new line characters to reflect what Mark Sikkema brought out, as well as what I had discovered on my own; though I didn't check whether the new plugin makes a difference.

~3D1T0R

Bart.S
Offline
Last seen: 2 days 18 hours ago
Developer
Joined: 2008-07-23 07:56
Hmm,

maybe a NSIS Unicode / registry plugin issue.

scriptdaemon
Offline
Last seen: 3 years 2 months ago
Developer
Joined: 2008-10-10 17:40
What version of NSIS do you

What version of NSIS do you use? The latest on PA.c? Because that's what I use.

Bart.S
Offline
Last seen: 2 days 18 hours ago
Developer
Joined: 2008-07-23 07:56
ANSI

The latest not portable NSIS (ANSI).

Mark Sikkema
Offline
Last seen: 11 years 4 months ago
Developer
Joined: 2009-07-20 14:55
Bug in the registry plug-in

it's not adding a space, but it's adding a 0x00 between the characters. Some ansi to unicode mix-up.

If you try the new official Registry plug-in v4.1 from Instructor, all is fine. (the one dll is made both for ansi and unicode nsis, as I understand)
http://nsis.sourceforge.net/Registry_plug-in

reminder: with the official plug-in you will run into troubles with ${registry::restore} on Wine !

Formerly Gringoloco
Windows XP Pro sp3 x32

Mark Sikkema
Offline
Last seen: 11 years 4 months ago
Developer
Joined: 2009-07-20 14:55
A few options
  • Fix the bug in the plug-in, but I did not forget about the 'Does not work in XP sp2' nightmare, also it was one of my first C projects and I have to say the whole code is not that optimal.
  • Start using the official registry plug-in, and I could make a separate one just for ${Registry::Restore}
  • Or the easy way, stick in SOMETHING LIKE the following in the custom-code or the registry.nsh : http://pastebin.com/XNh9Ar9r

Formerly Gringoloco
Windows XP Pro sp3 x32

Bart.S
Offline
Last seen: 2 days 18 hours ago
Developer
Joined: 2008-07-23 07:56
One more
  • Discontinue development (the easiest way) Biggrin
Log in or register to post comments