X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=apps%2Ftests%2Fregdump%2Fregdump.c;h=d13395893c3188f4c86e02a6caf662b5f8d69f8d;hb=e3ed2d773259cc445c7ff8181ebd934931365328;hp=93ac16216622c42a5457154c69a9da5aed0a37ff;hpb=d378c68f5a9bb25c9e671dacd482d2e25d211df3;p=reactos.git diff --git a/apps/tests/regdump/regdump.c b/apps/tests/regdump/regdump.c index 93ac162..d133958 100644 --- a/apps/tests/regdump/regdump.c +++ b/apps/tests/regdump/regdump.c @@ -1,234 +1,167 @@ -#include -#include -#include +/* $Id$ + * + * ReactOS regedit + * + * regdump.c + * + * Copyright (C) 2002 Robert Dickenson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #include #include -#include - -HANDLE OutputHandle; -HANDLE InputHandle; - -void dprintf(char* fmt, ...) -{ - va_list args; - char buffer[255]; - - va_start(args,fmt); - vsprintf(buffer,fmt,args); - WriteConsoleA(OutputHandle, buffer, strlen(buffer), NULL, NULL); - va_end(args); -} - - -#define MAX_NAME_LEN 500 -/* -BOOL DumpRegKey(TCHAR* KeyPath, HKEY hKey) -{ - TCHAR keyPath[1000]; - int keyPathLen = 0; - - keyPath[0] = _T('\0'); +#include +#include "regdump.h" - dprintf("\n[%s]\n", KeyPath); - if (hKey != NULL) { - HKEY hNewKey; - LONG errCode = RegOpenKeyEx(hKey, keyPath, 0, KEY_READ, &hNewKey); - if (errCode == ERROR_SUCCESS) { - TCHAR Name[MAX_NAME_LEN]; - DWORD cName = MAX_NAME_LEN; - FILETIME LastWriteTime; - DWORD dwIndex = 0L; - while (RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) { - HKEY hSubKey; - DWORD dwCount = 0L; +#ifdef UNICODE +//#define dprintf _tprintf +#define dprintf printf +#else +#define dprintf printf +#endif - dprintf("\n[%s\\%s]\n", KeyPath, Name); +void RegKeyPrint(int which); - errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_READ, &hSubKey); - if (errCode == ERROR_SUCCESS) { - TCHAR SubName[MAX_NAME_LEN]; - DWORD cSubName = MAX_NAME_LEN; -// if (RegEnumKeyEx(hSubKey, 0, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - while (RegEnumKeyEx(hSubKey, dwCount, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - dprintf("\t%s (%d)\n", SubName, dwCount); - cSubName = MAX_NAME_LEN; - ++dwCount; - } - } - RegCloseKey(hSubKey); - //AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwCount); - cName = MAX_NAME_LEN; - ++dwIndex; - } - RegCloseKey(hNewKey); - } - } else { - } - dprintf("\n"); - return TRUE; -} - */ -BOOL _DumpRegKey(TCHAR* KeyPath, HKEY hKey) -{ - if (hKey != NULL) { - HKEY hNewKey; - LONG errCode = RegOpenKeyEx(hKey, NULL, 0, KEY_READ, &hNewKey); - if (errCode == ERROR_SUCCESS) { - TCHAR Name[MAX_NAME_LEN]; - DWORD cName = MAX_NAME_LEN; - FILETIME LastWriteTime; - DWORD dwIndex = 0L; - TCHAR* pKeyName = &KeyPath[_tcslen(KeyPath)]; - while (RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, NULL, NULL, NULL, &LastWriteTime) == ERROR_SUCCESS) { - HKEY hSubKey; - DWORD dwCount = 0L; - _tcscat(KeyPath, _T("\\")); - _tcscat(KeyPath, Name); - dprintf("\n[%s]\n", KeyPath); - errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_READ, &hSubKey); - if (errCode == ERROR_SUCCESS) { -#if 1 - _DumpRegKey(KeyPath, hSubKey); -#else - TCHAR SubName[MAX_NAME_LEN]; - DWORD cSubName = MAX_NAME_LEN; -// if (RegEnumKeyEx(hSubKey, 0, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - while (RegEnumKeyEx(hSubKey, dwCount, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - dprintf("\t%s (%d)\n", SubName, dwCount); - cSubName = MAX_NAME_LEN; - ++dwCount; - } -#endif - } - RegCloseKey(hSubKey); - cName = MAX_NAME_LEN; - *pKeyName = _T('\0'); - ++dwIndex; - } - RegCloseKey(hNewKey); - } - } else { - } - return TRUE; -} +const char* default_cmd_line1 = "/E HKLM_EXPORT.TXT HKEY_LOCAL_MACHINE"; +const char* default_cmd_line2 = "TEST_IMPORT.TXT"; +const char* default_cmd_line3 = "/P HKEY_LOCAL_MACHINE\\SYSTEM"; +const char* default_cmd_line4 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE"; +const char* default_cmd_line5 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes"; +const char* default_cmd_line6 = "/E HKCR_EXPORT.TXT HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes"; +const char* default_cmd_line7 = "/D HKEY_LOCAL_MACHINE\\SYSTEM"; +const char* default_cmd_line8 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE"; +const char* default_cmd_line9 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes"; -BOOL DumpRegKey(TCHAR* KeyPath, HKEY hKey) -{ - dprintf("\n[%s]\n", KeyPath); - return _DumpRegKey(KeyPath, hKey); +/* Show usage */ +void usage(const char* appName) +{ + fprintf(stderr, "%s: Dump registry key to console\n", appName); + fprintf(stderr, "%s HKCR | HKCU | HKLM | HKU | HKCC | HKRR\n", appName); } -void RegKeyPrint(int which) +void show_menu(void) { - TCHAR szKeyPath[1000]; - - switch (which) { - case '1': - strcpy(szKeyPath, _T("HKEY_CLASSES_ROOT")); - DumpRegKey(szKeyPath, HKEY_CLASSES_ROOT); - break; - case '2': - strcpy(szKeyPath, _T("HKEY_CURRENT_USER")); - DumpRegKey(szKeyPath, HKEY_CURRENT_USER); - break; - case '3': - strcpy(szKeyPath, _T("HKEY_LOCAL_MACHINE")); - DumpRegKey(szKeyPath, HKEY_LOCAL_MACHINE); - break; - case '4': - strcpy(szKeyPath, _T("HKEY_USERS")); - DumpRegKey(szKeyPath, HKEY_USERS); - break; - case '5': - strcpy(szKeyPath, _T("HKEY_CURRENT_CONFIG")); - DumpRegKey(szKeyPath, HKEY_CURRENT_CONFIG); - break; - case '6': -// DumpRegKey(szKeyPath, HKEY_CLASSES_ROOT); -// DumpRegKey(szKeyPath, HKEY_CURRENT_USER); -// DumpRegKey(szKeyPath, HKEY_LOCAL_MACHINE); -// DumpRegKey(szKeyPath, HKEY_USERS); -// DumpRegKey(szKeyPath, HKEY_CURRENT_CONFIG); - dprintf("unimplemented...\n"); - break; - } - + _tprintf(_T("\nchoose test :\n")); + _tprintf(_T(" 0 = Exit\n")); + printf(" 1 = %s\n", default_cmd_line1); + printf(" 2 = %s\n", default_cmd_line2); + printf(" 3 = %s\n", default_cmd_line3); + printf(" 4 = %s\n", default_cmd_line4); + printf(" 5 = %s\n", default_cmd_line5); + printf(" 6 = %s\n", default_cmd_line6); + printf(" 7 = %s\n", default_cmd_line7); + printf(" 8 = %s\n", default_cmd_line8); + printf(" 9 = %s\n", default_cmd_line9); +/* + _tprintf(_T(" 1 = %s\n"), default_cmd_line1); + _tprintf(_T(" 2 = %s\n"), default_cmd_line2); + _tprintf(_T(" 3 = %s\n"), default_cmd_line3); + _tprintf(_T(" 4 = %s\n"), default_cmd_line4); + _tprintf(_T(" 5 = %s\n"), default_cmd_line5); + _tprintf(_T(" 6 = %s\n"), default_cmd_line6); + _tprintf(_T(" 7 = %s\n"), default_cmd_line7); + _tprintf(_T(" 8 = %s\n"), default_cmd_line8); + _tprintf(_T(" 9 = %s\n"), default_cmd_line9); + */ +// _tprintf(_T(" A = HKEY_CLASSES_ROOT\n")); +// _tprintf(_T(" B = HKEY_CURRENT_USER\n")); +// _tprintf(_T(" C = HKEY_LOCAL_MACHINE\n")); +// _tprintf(_T(" D = HKEY_USERS\n")); +// _tprintf(_T(" E = HKEY_CURRENT_CONFIG\n")); +// _tprintf(_T(" F = REGISTRY ROOT\n")); } -int main(int argc, char* argv[]) +int regdump(int argc, char* argv[]) { - char Buffer[10]; - TCHAR szKeyPath[1000]; - DWORD Result; - - AllocConsole(); - InputHandle = GetStdHandle(STD_INPUT_HANDLE); - OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); - - if (argc > 1) { - -// if (0 == _tcsstr(argv[1], _T("HKLM"))) { - - if (strstr(argv[1], _T("help"))) { - - } else if (strstr(argv[1], _T("HKCR"))) { - RegKeyPrint('1'); - } else if (strstr(argv[1], _T("HKCU"))) { - RegKeyPrint('2'); - } else if (strstr(argv[1], _T("HKLM"))) { - RegKeyPrint('3'); - } else if (strstr(argv[1], _T("HKU"))) { - RegKeyPrint('4'); - } else if (strstr(argv[1], _T("HKCC"))) { - RegKeyPrint('5'); - } else if (strstr(argv[1], _T("HKRR"))) { - RegKeyPrint('6'); - } else { + char Buffer[500]; + + if (argc > 1) { +// if (0 == _tcsstr(argv[1], _T("HKLM"))) { + if (strstr(argv[1], "help")) { + usage(argv[0]); + } else if (strstr(argv[1], "HKCR")) { + RegKeyPrint('1'); + } else if (strstr(argv[1], "HKCU")) { + RegKeyPrint('2'); + } else if (strstr(argv[1], "HKLM")) { + RegKeyPrint('3'); + } else if (strstr(argv[1], "HKU")) { + RegKeyPrint('4'); + } else if (strstr(argv[1], "HKCC")) { + RegKeyPrint('5'); + } else if (strstr(argv[1], "HKRR")) { + RegKeyPrint('6'); + } else { dprintf("started with argc = %d, argv[1] = %s (unknown?)\n", argc, argv[1]); - } - - } else while (1) { - dprintf("choose test :\n"); - dprintf(" 0 = Exit\n"); - dprintf(" 1 = HKEY_CLASSES_ROOT\n"); - dprintf(" 2 = HKEY_CURRENT_USER\n"); - dprintf(" 3 = HKEY_LOCAL_MACHINE\n"); - dprintf(" 4 = HKEY_USERS\n"); - dprintf(" 5 = HKEY_CURRENT_CONFIG\n"); - dprintf(" 6 = REGISTRY ROOT\n"); - ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ; - switch (Buffer[0]) { + } + return 0; + } + show_menu(); + while (1) { + GetInput(Buffer, sizeof(Buffer)); + switch (toupper(Buffer[0])) { case '0': return(0); case '1': + strcpy(Buffer, default_cmd_line1); + goto doit; case '2': + strcpy(Buffer, default_cmd_line2); + goto doit; case '3': + strcpy(Buffer, default_cmd_line3); + goto doit; case '4': + strcpy(Buffer, default_cmd_line4); + goto doit; case '5': + strcpy(Buffer, default_cmd_line5); + goto doit; case '6': - RegKeyPrint(Buffer[0]/* - '0'*/); + strcpy(Buffer, default_cmd_line6); + goto doit; + case '7': + strcpy(Buffer, default_cmd_line7); + goto doit; + case '8': + strcpy(Buffer, default_cmd_line8); + goto doit; + case '9': + strcpy(Buffer, default_cmd_line9); + goto doit; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + RegKeyPrint(toupper(Buffer[0]) - 'A' + 1); break; - default: - dprintf("invalid input.\n"); - break; - } - } + default: doit: + if (!ProcessCmdLine(Buffer)) { + dprintf("invalid input.\n"); + show_menu(); + } else { + dprintf("done.\n"); + } + break; + } + } return 0; } -/* -[HKEY_LOCAL_MACHINE] - -[HKEY_LOCAL_MACHINE\HARDWARE] - -[HKEY_LOCAL_MACHINE\HARDWARE\ACPI] - -[HKEY_LOCAL_MACHINE\HARDWARE\ACPI\DSDT] - -[HKEY_LOCAL_MACHINE\HARDWARE\ACPI\DSDT\VIA694] - -[HKEY_LOCAL_MACHINE\HARDWARE\ACPI\DSDT\VIA694\AWRDACPI] - - */ \ No newline at end of file