Public Member Functions | Protected Attributes

RegDirectory Struct Reference

Registry key entry. More...

#include <regfs.h>

Inheritance diagram for RegDirectory:
Inheritance graph
[legend]
Collaboration diagram for RegDirectory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RegDirectory (Entry *parent, LPCTSTR path, HKEY hKeyRoot)
 ~RegDirectory ()
virtual void read_directory (int scan_flags=0)
virtual const void * get_next_path_component (const void *) const
virtual Entryfind_entry (const void *)

Protected Attributes

HKEY _hKeyRoot

Detailed Description

Registry key entry.

Definition at line 43 of file regfs.h.


Constructor & Destructor Documentation

RegDirectory::RegDirectory ( Entry parent,
LPCTSTR  path,
HKEY  hKeyRoot 
)

Definition at line 238 of file regfs.cpp.

References Entry::_data, and Directory::_path.

Referenced by read_directory().

 :  RegEntry(parent),
    _hKeyRoot(hKeyRoot)
{
    _path = _tcsdup(path);

    memset(&_data, 0, sizeof(WIN32_FIND_DATA));
    _data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
}

Here is the caller graph for this function:

RegDirectory::~RegDirectory (  ) [inline]

Definition at line 47 of file regfs.h.

References Directory::_path.

    {
        free(_path);
        _path = NULL;
    }

Member Function Documentation

Entry * RegDirectory::find_entry ( const void *  p ) [virtual]

Reimplemented from Entry.

Definition at line 200 of file regfs.cpp.

References Entry::_data, Entry::_down, Entry::_next, and TEXT.

{
    LPCTSTR name = (LPCTSTR)p;

    for(Entry*entry=_down; entry; entry=entry->_next) {
        LPCTSTR p = name;
        LPCTSTR q = entry->_data.cFileName;

        do {
            if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
                return entry;
        } while(tolower(*p++) == tolower(*q++));

        p = name;
        q = entry->_data.cAlternateFileName;

        do {
            if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
                return entry;
        } while(tolower(*p++) == tolower(*q++));
    }

    return NULL;
}
const void * RegDirectory::get_next_path_component ( const void *  p ) const [virtual]

Reimplemented from Entry.

Definition at line 183 of file regfs.cpp.

References TEXT.

{
    LPCTSTR s = (LPCTSTR) p;

    while(*s && *s!=TEXT('\\'))
        ++s;

    while(*s==TEXT('\\'))
        ++s;

    if (!*s)
        return NULL;

    return s;
}
void RegDirectory::read_directory ( int  scan_flags = 0 ) [virtual]

Todo:
This can also be done in the RegEnumValue() call if we dynamically adjust the return buffer size.

Reimplemented from Entry.

Definition at line 34 of file regfs.cpp.

References Entry::_content, Entry::_data, Entry::_down, _hKeyRoot, Entry::_level, Entry::_next, Directory::_path, Entry::_scanned, _stprintf, _tcscpy_s, _tcslen, Entry::_type_name, CONTEXT, RegDirectory(), RegEntry::RegEntry(), and TEXT.

{
    CONTEXT("RegDirectory::read_directory()");

    Entry* first_entry = NULL;
    int level = _level + 1;

    TCHAR buffer[MAX_PATH];

    _tcscpy(buffer, (LPCTSTR)_path);
    LPTSTR pname = buffer + _tcslen(buffer);
    int plen = MAX_PATH - _tcslen(buffer);

    HKEY hkey;

    if (!RegOpenKeyEx(_hKeyRoot, *buffer=='\\'?buffer+1:buffer, 0, STANDARD_RIGHTS_READ|KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &hkey)) {
        if (pname[-1] != '\\')
            *pname++ = '\\', plen--;

        TCHAR name[MAX_PATH], class_name[MAX_PATH];
        WIN32_FIND_DATA w32fd;
        Entry* last = NULL;
        RegEntry* entry;

        for(int idx=0; ; ++idx) {
            memset(&w32fd, 0, sizeof(WIN32_FIND_DATA));

            DWORD name_len = MAX_PATH;
            DWORD class_len = MAX_PATH;

            if (RegEnumKeyEx(hkey, idx, name, &name_len, 0, class_name, &class_len, &w32fd.ftLastWriteTime))
                break;

            w32fd.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
            _tcsncpy(w32fd.cFileName, name, name_len);

            _tcscpy_s(pname, plen, name);
            entry = new RegDirectory(this, buffer, _hKeyRoot);

            memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));

            if (class_len)
                entry->_type_name = _tcsdup(String(class_name, class_len));

            if (!first_entry)
                first_entry = entry;

            if (last)
                last->_next = entry;

            entry->_level = level;

            last = entry;
        }
/*
        TCHAR value[MAX_PATH];
        LONG value_len = sizeof(value);

        if (!RegQueryValue(hkey, NULL, value, &value_len) && value_len>1) {
            memset(&w32fd, 0, sizeof(WIN32_FIND_DATA));

            lstrcpy(w32fd.cFileName, TEXT("(Default)"));

            entry = new RegEntry(this);

            memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));

            entry->_content = _tcsdup(value);

            if (!first_entry)
                first_entry = entry;

            if (last)
                last->_next = entry;

            entry->_level = level;

            last = entry;
        }
*/
        DWORD type;
        for(int idx=0; ; ++idx) {
            DWORD name_len = MAX_PATH;

            if (RegEnumValue(hkey, idx, name, &name_len, 0, &type, NULL, NULL))
                break;

            memset(&w32fd, 0, sizeof(WIN32_FIND_DATA));

            if (name[0])
                lstrcpy(w32fd.cFileName, name);
            else
                lstrcpy(w32fd.cFileName, TEXT("(Default)"));

            entry = new RegEntry(this);

            memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));

            switch(type) {
              case REG_NONE:                        entry->_type_name = _tcsdup(TEXT("REG_NONE"));                      break;
              case REG_SZ:                          entry->_type_name = _tcsdup(TEXT("REG_SZ"));                        break;
              case REG_EXPAND_SZ:                   entry->_type_name = _tcsdup(TEXT("REG_EXPAND_SZ"));                 break;
              case REG_BINARY:                      entry->_type_name = _tcsdup(TEXT("REG_BINARY"));                    break;
              case REG_DWORD:                       entry->_type_name = _tcsdup(TEXT("REG_DWORD"));                     break;
              case REG_DWORD_BIG_ENDIAN:            entry->_type_name = _tcsdup(TEXT("REG_DWORD_BIG_ENDIAN"));          break;
              case REG_LINK:                        entry->_type_name = _tcsdup(TEXT("REG_LINK"));                      break;
              case REG_MULTI_SZ:                    entry->_type_name = _tcsdup(TEXT("REG_MULTI_SZ"));                  break;
              case REG_RESOURCE_LIST:               entry->_type_name = _tcsdup(TEXT("REG_RESOURCE_LIST"));             break;
              case REG_FULL_RESOURCE_DESCRIPTOR:    entry->_type_name = _tcsdup(TEXT("REG_FULL_RESOURCE_DESCRIPTOR"));  break;
              case REG_RESOURCE_REQUIREMENTS_LIST:  entry->_type_name = _tcsdup(TEXT("REG_RESOURCE_REQUIREMENTS_LIST"));break;
              case REG_QWORD:                       entry->_type_name = _tcsdup(TEXT("REG_QWORD"));                     break;
            }

             ///@todo This can also be done in the RegEnumValue() call if we dynamically adjust the return buffer size.
            TCHAR value[MAX_PATH];
            DWORD value_len = sizeof(value);

            if (!RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)value, &value_len)) {
                if (type==REG_SZ || type==REG_EXPAND_SZ || type==REG_LINK)
                    entry->_content = _tcsdup(value);
                else if (type == REG_DWORD) {
                    TCHAR b[32];
                    _stprintf(b, TEXT("%ld"), *(DWORD*)&value);
                    entry->_content = _tcsdup(b);
                }
            }

            if (!first_entry)
                first_entry = entry;

            if (last)
                last->_next = entry;

            entry->_level = level;

            last = entry;
        }

        if (last)
            last->_next = NULL;

        RegCloseKey(hkey);
    }

    _down = first_entry;
    _scanned = true;
}

Here is the call graph for this function:


Member Data Documentation

HKEY RegDirectory::_hKeyRoot [protected]

Definition at line 58 of file regfs.h.

Referenced by read_directory().


The documentation for this struct was generated from the following files:

ROS Explorer Source Code Documentation
generated on 02.01.2013 by doxygen

ROS Explorer Homepage