Jump to content

_regFind() proposition


 Share

Recommended Posts

Hi guys,

I'm sitting down planning how best to tackle a function like _regFind() (since doing so standing up is just silly) and this is what I am thinking at the moment.

_regFind($key, $term, $flags, $partial, $recursive, $dataType)

(where a lot of these parameters will be optional)

$key signifies the base key in which to search, where leaving blank would search the whole registry. $term is naturally the term for which to search.

$flags allows searching of key name and/or value name and/or value data, similar to the Registry Editor's Find box.

$partial is easier to explain by example at 1AM: if it evaluates to false then when searching key names for the term 'Smart' will only return subkeys whose name is 'Smart'. If $partial evaluates to true then it would return subkeys such as 'Smart', 'SmartFTP', 'GetSmart', etc. Obviously if doing a non-partial term search then you would want a recursive search as well.

$recursive if true means that all subkeys would be searched in addition to the specified key.

$dataType would limit results to [a?] specific datatype[s?] -- e.g. you may want to search for 'beef' but not have REG_BINARY values containing 0xBEEF returned.

busysignal mentioned undo functionality being handy but this would not form part of the _regFind() function itself -- a _regFindUndo() function would call the other function and presumably a _regExport() function to do this.

I'd love to hear what everyone thinks regarding this. What of these would you find useful/useless? Is there anything else to consider?

Before I forget, I was thinking that returning the results could potentially be troublesome. Let's say we wanted to search value names and value data for 'smtp.oldisp.com.au' -- you would need to obviously return each key in which the term resides, and then any value names within those keys (there could be none, one or more than one).

Having thrown that out into the open, I'm thinking of returning a one-dimensional array when searching just key names. That's simple.

But returning results for a search of value names and/or data? That's where it gets interesting. The best I can come up with is an array where each element contains another array, one element for the key location and the other element containing yet another array containing the names of subkeys.

1AM = words hard, example good:

; search for registry entries with my old ISP settings
_regFind("HKCU\Software", "smtp.oldisp.com.au", $REG_FIND_ALL, 0, 1)

func _regFind($the, $par, $a, $me, $ters)

    ; Pretend this works, silly!
    $result[0][0] = "HKCU\Software\Bobco\Thingware\Mail"
    $result[0][1][0] = "SMTP Server"
    ; etc.

    return $result

endFunc

If you have kept interest this far then I commend you and please discuss! :)

Edited by LxP
Link to comment
Share on other sites

The syntax you proposed sounds good. :)

_regFind($key, $term, $flags, $partial, $recursive, $dataType)

P.S. will you be able to search for a key with a specific string or just data.

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

But returning results for a search of value names and/or data? That's where it gets interesting. The best I can come up with is an array where each element contains another array, one element for the key location and the other element containing yet another array containing the names of subkeys.

<{POST_SNAPBACK}>

Trust me to overcomplicate things.

Of course, for any case I could just return a one-dimensional array, where each element would contain the location of the key.

When searching values (name and/or data) and they should be returned, they could just be returned within the corresponding element prepended by a @LF:

$result[0] = "HKRU\Software\Matching Key" & @LF & "Matching value name 1" & @LF & "Matching value name 2"
$result[1] = "HKRU\Software\Another" & @LF & "Matching value name"
Link to comment
Share on other sites

P.S. will you be able to search for a key with a specific string or just data.

<{POST_SNAPBACK}>

Without being too sure of what you mean... yes? :)

You can search the names of keys, the names of their values and the data of their values with this proposal.

Link to comment
Share on other sites

I think that this would be a great function to have, but I don't see why you have so many parameters:

_regFind($key, $term, $flags, $partial, $recursive, $dataType)

If $partial and $recursive evaluate to true/flase, why not just make them a part of $flags?

Also to be consistent with othe functions (like the INI*() functions) can you make the output array 1-based?

And here's an idea for your $dataType - make it a flag also, so that when its set and you give it a string like 'BEEF' it searchs for 2 bytes 0xBE and 0xEF instead of the actual string 'BEEF'

You also might want to add a flag for case-sensative search

And how about a flag to indicate that $term is a regular expression?

Just some ideas...

Link to comment
Share on other sites

If $partial and $recursive evaluate to true/flase, why not just make them a part of $flags?

ยทยทยท

You also might want to add a flag for case-sensative search

And how about a flag to indicate that $term is a regular expression?

Thanks for those ideas -- you're completely right about incorporating all true/false pairs into the $flags parameter. I think it was just too late in the night!

I'll read over the methods adopted by the INI...() functions regarding output and do my best to replicate them.

Link to comment
Share on other sites

I agree with blindwig on case-sensitive / insensitive searching. Does _regFind find the first occurence or all occurences? If the former, would you need a _regFindAll() that returned an array of keys that matched the criteria?

-John

Edited by jftuga
Link to comment
Share on other sites

_regFind() would always return an array of all occurrences found. I considered something like _regFindFirst() and _regFindNext() but it wouldn't be pretty.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...