Commit 58c185ec authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Reformat regedit in a consistent manner.

parent 8aef340c
......@@ -56,25 +56,25 @@ static void MakeFullRegPath(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* p
static void draw_splitbar(HWND hWnd, int x)
{
RECT rt;
HDC hdc = GetDC(hWnd);
RECT rt;
HDC hdc = GetDC(hWnd);
GetClientRect(hWnd, &rt);
rt.left = x - SPLIT_WIDTH/2;
rt.right = x + SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc);
GetClientRect(hWnd, &rt);
rt.left = x - SPLIT_WIDTH/2;
rt.right = x + SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc);
}
static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy)
{
HDWP hdwp = BeginDeferWindowPos(2);
RECT rt = {0, 0, cx, cy};
HDWP hdwp = BeginDeferWindowPos(2);
RECT rt = {0, 0, cx, cy};
cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2;
DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
EndDeferWindowPos(hdwp);
EndDeferWindowPos(hdwp);
}
static void OnPaint(HWND hWnd)
......@@ -99,8 +99,8 @@ static void OnPaint(HWND hWnd)
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam)) {
/* Parse the menu selections: */
switch (LOWORD(wParam)) {
/* Parse the menu selections: */
case ID_REGISTRY_EXIT:
DestroyWindow(hWnd);
break;
......@@ -110,7 +110,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
default:
return FALSE;
}
return TRUE;
return TRUE;
}
/*******************************************************************************
......@@ -127,12 +127,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int last_split;
/* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */
/* ChildWnd* pChildWnd = (ChildWnd*)GetWindowLong(hWnd, GWL_USERDATA); */
switch (message) {
case WM_CREATE:
pChildWnd = (ChildWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
if (!pChildWnd) return 0;
if (!pChildWnd) return 0;
pChildWnd->nSplitPos = 250;
pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, TREE_WINDOW);
pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, pChildWnd->szPath*/);
......@@ -141,99 +141,99 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
goto def;
}
break;
break;
case WM_PAINT:
OnPaint(hWnd);
return 0;
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT) {
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
SetCursor(LoadCursor(0, IDC_SIZEWE));
return TRUE;
}
}
goto def;
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT) {
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
SetCursor(LoadCursor(0, IDC_SIZEWE));
return TRUE;
}
}
goto def;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN: {
RECT rt;
int x = LOWORD(lParam);
GetClientRect(hWnd, &rt);
if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
last_split = pChildWnd->nSplitPos;
draw_splitbar(hWnd, last_split);
SetCapture(hWnd);
}
break;}
case WM_LBUTTONDOWN: {
RECT rt;
int x = LOWORD(lParam);
GetClientRect(hWnd, &rt);
if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
last_split = pChildWnd->nSplitPos;
draw_splitbar(hWnd, last_split);
SetCapture(hWnd);
}
break;
}
case WM_LBUTTONUP:
if (GetCapture() == hWnd) {
RECT rt;
int x = LOWORD(lParam);
draw_splitbar(hWnd, last_split);
last_split = -1;
GetClientRect(hWnd, &rt);
pChildWnd->nSplitPos = x;
ResizeWnd(pChildWnd, rt.right, rt.bottom);
ReleaseCapture();
}
break;
case WM_LBUTTONUP:
if (GetCapture() == hWnd) {
RECT rt;
int x = LOWORD(lParam);
draw_splitbar(hWnd, last_split);
last_split = -1;
GetClientRect(hWnd, &rt);
pChildWnd->nSplitPos = x;
ResizeWnd(pChildWnd, rt.right, rt.bottom);
ReleaseCapture();
}
break;
case WM_CAPTURECHANGED:
if (GetCapture()==hWnd && last_split>=0)
draw_splitbar(hWnd, last_split);
break;
case WM_CAPTURECHANGED:
if (GetCapture()==hWnd && last_split>=0)
draw_splitbar(hWnd, last_split);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
if (GetCapture() == hWnd) {
RECT rt;
draw_splitbar(hWnd, last_split);
GetClientRect(hWnd, &rt);
if (wParam == VK_ESCAPE)
if (GetCapture() == hWnd) {
RECT rt;
draw_splitbar(hWnd, last_split);
GetClientRect(hWnd, &rt);
ResizeWnd(pChildWnd, rt.right, rt.bottom);
last_split = -1;
ReleaseCapture();
SetCursor(LoadCursor(0, IDC_ARROW));
}
break;
last_split = -1;
ReleaseCapture();
SetCursor(LoadCursor(0, IDC_ARROW));
}
break;
case WM_MOUSEMOVE:
if (GetCapture() == hWnd) {
RECT rt;
int x = LOWORD(lParam);
HDC hdc = GetDC(hWnd);
GetClientRect(hWnd, &rt);
rt.left = last_split-SPLIT_WIDTH/2;
rt.right = last_split+SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
last_split = x;
rt.left = x-SPLIT_WIDTH/2;
rt.right = x+SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc);
}
break;
case WM_MOUSEMOVE:
if (GetCapture() == hWnd) {
RECT rt;
int x = LOWORD(lParam);
HDC hdc = GetDC(hWnd);
GetClientRect(hWnd, &rt);
rt.left = last_split-SPLIT_WIDTH/2;
rt.right = last_split+SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
last_split = x;
rt.left = x-SPLIT_WIDTH/2;
rt.right = x+SPLIT_WIDTH/2+1;
InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc);
}
break;
case WM_SETFOCUS:
case WM_SETFOCUS:
if (pChildWnd != NULL) {
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd);
}
break;
break;
case WM_TIMER:
break;
case WM_NOTIFY:
case WM_NOTIFY:
if ((int)wParam == TREE_WINDOW) {
switch (((LPNMHDR)lParam)->code) {
case TVN_ITEMEXPANDING:
return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
case TVN_SELCHANGED:
{
case TVN_SELCHANGED: {
HKEY hKey;
TCHAR keyPath[1000];
int keyPathLen = 0;
......@@ -251,20 +251,20 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
goto def;
}
} else
if ((int)wParam == LIST_WINDOW) {
if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
goto def;
if ((int)wParam == LIST_WINDOW) {
if (!SendMessage(pChildWnd->hListWnd, message, wParam, lParam)) {
goto def;
}
}
}
break;
case WM_SIZE:
case WM_SIZE:
if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) {
ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam));
}
/* fall through */
default: def:
default: def:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
return 0;
}
......@@ -47,10 +47,10 @@ void error(HWND hwnd, INT resId, ...)
hInstance = GetModuleHandle(0);
if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title)))
lstrcpy(title, "Error");
lstrcpy(title, "Error");
if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt)))
lstrcpy(errfmt, "Unknown error string!");
lstrcpy(errfmt, "Unknown error string!");
va_start(ap, resId);
_vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap);
......@@ -66,27 +66,27 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
int len;
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
if ((len = GetWindowTextLength(hwndValue))) {
if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) {
stringValueData = valueData;
if (!GetWindowText(hwndValue, stringValueData, len + 1))
*stringValueData = 0;
}
}
}
/* Fall through */
case IDCANCEL:
EndDialog(hwndDlg, wParam);
return TRUE;
}
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
if ((len = GetWindowTextLength(hwndValue))) {
if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) {
stringValueData = valueData;
if (!GetWindowText(hwndValue, stringValueData, len + 1))
*stringValueData = 0;
}
}
}
/* Fall through */
case IDCANCEL:
EndDialog(hwndDlg, wParam);
return TRUE;
}
}
return FALSE;
}
......@@ -104,28 +104,28 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPTSTR valueName)
lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
goto done;
}
if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
goto done;
}
lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
if (lRet == ERROR_SUCCESS) result = TRUE;
}
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
if (lRet == ERROR_SUCCESS) result = TRUE;
}
} else if ( type == REG_DWORD ) {
MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR);
MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR);
} else {
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
}
done:
......
......@@ -67,42 +67,42 @@ TCHAR szChildClass[MAX_LOADSTRING];
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wcFrame = {
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW/*style*/,
FrameWndProc,
0/*cbClsExtra*/,
0/*cbWndExtra*/,
hInstance,
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
LoadCursor(0, IDC_ARROW),
0/*hbrBackground*/,
0/*lpszMenuName*/,
szFrameClass,
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
};
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW/*style*/,
FrameWndProc,
0/*cbClsExtra*/,
0/*cbWndExtra*/,
hInstance,
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
LoadCursor(0, IDC_ARROW),
0/*hbrBackground*/,
0/*lpszMenuName*/,
szFrameClass,
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
};
ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
WNDCLASSEX wcChild = {
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW/*style*/,
ChildWndProc,
0/*cbClsExtra*/,
sizeof(HANDLE)/*cbWndExtra*/,
hInstance,
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
LoadCursor(0, IDC_ARROW),
0/*hbrBackground*/,
0/*lpszMenuName*/,
szChildClass,
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
};
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW/*style*/,
ChildWndProc,
0/*cbClsExtra*/,
sizeof(HANDLE)/*cbWndExtra*/,
hInstance,
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
LoadCursor(0, IDC_ARROW),
0/*hbrBackground*/,
0/*lpszMenuName*/,
szChildClass,
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
};
ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
hChildWndClass = hChildWndClass; /* warning eater */
hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
/* Initialize the Windows Common Controls DLL */
InitCommonControls();
......@@ -113,9 +113,9 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
} */
hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
if (!hFrameWnd) {
return FALSE;
......@@ -148,20 +148,20 @@ int APIENTRY WinMain(HINSTANCE hInstance,
{
MSG msg;
HACCEL hAccel;
/*
int hCrt;
FILE *hf;
AllocConsole();
hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
hf = _fdopen(hCrt, "w");
*stdout = *hf;
setvbuf(stdout, NULL, _IONBF, 0);
wprintf(L"command line exit, hInstance = %d\n", hInstance);
getch();
FreeConsole();
return 0;
*/
/*
int hCrt;
FILE *hf;
AllocConsole();
hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
hf = _fdopen(hCrt, "w");
*stdout = *hf;
setvbuf(stdout, NULL, _IONBF, 0);
wprintf(L"command line exit, hInstance = %d\n", hInstance);
getch();
FreeConsole();
return 0;
*/
if (ProcessCmdLine(lpCmdLine)) {
return 0;
......
......@@ -29,7 +29,7 @@
#define LIST_WINDOW 2003
#define MAX_LOADSTRING 100
#define SPLIT_WIDTH 5
#define SPLIT_WIDTH 5
#define MAX_NAME_LEN 500
#define COUNT_OF(a) (sizeof(a)/sizeof(a[0]))
......@@ -37,23 +37,23 @@
/******************************************************************************/
enum OPTION_FLAGS {
OPTIONS_AUTO_REFRESH = 0x01,
OPTIONS_READ_ONLY_MODE = 0x02,
OPTIONS_CONFIRM_ON_DELETE = 0x04,
OPTIONS_SAVE_ON_EXIT = 0x08,
OPTIONS_AUTO_REFRESH = 0x01,
OPTIONS_READ_ONLY_MODE = 0x02,
OPTIONS_CONFIRM_ON_DELETE = 0x04,
OPTIONS_SAVE_ON_EXIT = 0x08,
OPTIONS_DISPLAY_BINARY_DATA = 0x10,
OPTIONS_VIEW_TREE_ONLY = 0x20,
OPTIONS_VIEW_DATA_ONLY = 0x40,
};
typedef struct {
HWND hWnd;
HWND hWnd;
HWND hTreeWnd;
HWND hListWnd;
int nFocusPanel; /* 0: left 1: right */
int nSplitPos;
WINDOWPLACEMENT pos;
TCHAR szPath[MAX_PATH];
int nSplitPos;
WINDOWPLACEMENT pos;
TCHAR szPath[MAX_PATH];
} ChildWnd;
extern ChildWnd* pChildWnd;
......
......@@ -24,36 +24,36 @@
#include "regproc.h"
static char *usage =
"Usage:\n"
" regedit filename\n"
" regedit /E filename [regpath]\n"
" regedit /D regpath\n"
"\n"
"filename - registry file name\n"
"regpath - name of the registry key\n"
"\n"
"When is called without any switches adds contents of the specified\n"
"registry file to the registry\n"
"\n"
"Switches:\n"
" /E - exports contents of the specified registry key to the specified\n"
" file. Exports the whole registry if no key is specified.\n"
" /D - deletes specified registry key\n"
" /S - silent execution, can be used with any other switch.\n"
" The only existing mode, exists for compatibility with Windows regedit.\n"
" /V - advanced mode, can be used with any other switch.\n"
" Ignored, exists for compatibility with Windows regedit.\n"
" /L - location of system.dat file. Can be used with any other switch.\n"
" Ignored. Exists for compatibility with Windows regedit.\n"
" /R - location of user.dat file. Can be used with any other switch.\n"
" Ignored. Exists for compatibility with Windows regedit.\n"
" /? - print this help. Any other switches are ignored.\n"
" /C - create registry from. Not implemented.\n"
"\n"
"The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
"This program is command-line compatible with Microsoft Windows\n"
"regedit. The difference with Windows regedit - this application has\n"
"command-line interface only.\n";
"Usage:\n"
" regedit filename\n"
" regedit /E filename [regpath]\n"
" regedit /D regpath\n"
"\n"
"filename - registry file name\n"
"regpath - name of the registry key\n"
"\n"
"When is called without any switches adds contents of the specified\n"
"registry file to the registry\n"
"\n"
"Switches:\n"
" /E - exports contents of the specified registry key to the specified\n"
" file. Exports the whole registry if no key is specified.\n"
" /D - deletes specified registry key\n"
" /S - silent execution, can be used with any other switch.\n"
" The only existing mode, exists for compatibility with Windows regedit.\n"
" /V - advanced mode, can be used with any other switch.\n"
" Ignored, exists for compatibility with Windows regedit.\n"
" /L - location of system.dat file. Can be used with any other switch.\n"
" Ignored. Exists for compatibility with Windows regedit.\n"
" /R - location of user.dat file. Can be used with any other switch.\n"
" Ignored. Exists for compatibility with Windows regedit.\n"
" /? - print this help. Any other switches are ignored.\n"
" /C - create registry from. Not implemented.\n"
"\n"
"The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
"This program is command-line compatible with Microsoft Windows\n"
"regedit. The difference with Windows regedit - this application has\n"
"command-line interface only.\n";
typedef enum {
ACTION_UNDEF, ACTION_ADD, ACTION_EXPORT, ACTION_DELETE
......@@ -70,8 +70,7 @@ BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s);
*/
void error_unknown_switch(char chu, char *s)
{
if (isalpha(chu))
{
if (isalpha(chu)) {
fprintf(stderr,"%s: Undefined switch /%c!\n", getAppName(), chu);
} else {
fprintf(stderr,"%s: Alphabetic character is expected after '%c' "
......@@ -87,8 +86,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
CHAR ch = *s; /* current character */
setAppName("regedit");
while (ch && ((ch == '-') || (ch == '/')))
{
while (ch && ((ch == '-') || (ch == '/'))) {
char chu;
char ch2;
......@@ -96,14 +94,11 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
ch = *s;
ch2 = *(s+1);
chu = toupper(ch);
if (!ch2 || isspace(ch2))
{
if (chu == 'S' || chu == 'V')
{
if (!ch2 || isspace(ch2)) {
if (chu == 'S' || chu == 'V') {
/* ignore these switches */
} else {
switch (chu)
{
switch (chu) {
case 'D':
action = ACTION_DELETE;
break;
......@@ -121,16 +116,13 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
}
s++;
} else {
if (ch2 == ':')
{
switch (chu)
{
if (ch2 == ':') {
switch (chu) {
case 'L':
/* fall through */
case 'R':
s += 2;
while (*s && !isspace(*s))
{
while (*s && !isspace(*s)) {
s++;
}
break;
......@@ -146,8 +138,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
}
/* skip spaces to the next parameter */
ch = *s;
while (ch && isspace(ch))
{
while (ch && isspace(ch)) {
s++;
ch = *s;
}
......@@ -164,75 +155,65 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
{
switch (action)
{
case ACTION_ADD:
{
CHAR filename[MAX_PATH];
FILE *reg_file;
get_file_name(&s, filename);
if (!filename[0])
{
fprintf(stderr,"%s: No file name is specified\n", getAppName());
fprintf(stderr,usage);
exit(1);
}
switch (action) {
case ACTION_ADD: {
CHAR filename[MAX_PATH];
FILE *reg_file;
while(filename[0])
{
reg_file = fopen(filename, "r");
if (reg_file)
{
processRegLines(reg_file, doSetValue);
} else {
perror("");
fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), filename);
get_file_name(&s, filename);
if (!filename[0]) {
fprintf(stderr,"%s: No file name is specified\n", getAppName());
fprintf(stderr,usage);
exit(1);
}
get_file_name(&s, filename);
}
break;
}
case ACTION_DELETE:
{
CHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name);
if (!reg_key_name[0])
{
fprintf(stderr,"%s: No registry key is specified for removal\n",
getAppName());
fprintf(stderr,usage);
exit(1);
}
delete_registry_key(reg_key_name);
break;
}
case ACTION_EXPORT:
{
CHAR filename[MAX_PATH];
filename[0] = '\0';
get_file_name(&s, filename);
if (!filename[0])
{
fprintf(stderr,"%s: No file name is specified\n", getAppName());
fprintf(stderr,usage);
exit(1);
}
if (s[0])
{
while(filename[0]) {
reg_file = fopen(filename, "r");
if (reg_file) {
processRegLines(reg_file, doSetValue);
} else {
perror("");
fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), filename);
exit(1);
}
get_file_name(&s, filename);
}
break;
}
case ACTION_DELETE: {
CHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name);
export_registry_key(filename, reg_key_name);
} else {
export_registry_key(filename, NULL);
if (!reg_key_name[0]) {
fprintf(stderr,"%s: No registry key is specified for removal\n",
getAppName());
fprintf(stderr,usage);
exit(1);
}
delete_registry_key(reg_key_name);
break;
}
case ACTION_EXPORT: {
CHAR filename[MAX_PATH];
filename[0] = '\0';
get_file_name(&s, filename);
if (!filename[0]) {
fprintf(stderr,"%s: No file name is specified\n", getAppName());
fprintf(stderr,usage);
exit(1);
}
if (s[0]) {
CHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name);
export_registry_key(filename, reg_key_name);
} else {
export_registry_key(filename, NULL);
}
break;
}
break;
}
default:
fprintf(stderr,"%s: Unhandled action!\n", getAppName());
exit(1);
......
......@@ -49,7 +49,7 @@ void processRegLines(FILE *in, CommandAPI command);
* Generic prototypes
*/
char* getToken(char** str, const char* delims);
void get_file_name(CHAR **command_line, CHAR *filename);
void get_file_name(CHAR **command_line, CHAR *filename);
DWORD convertHexToDWord(char *str, BYTE *buf);
DWORD convertHexCSVToHex(char *str, BYTE *buf, ULONG bufLen);
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
......
......@@ -72,7 +72,7 @@ HKEY FindRegRoot(HWND hwndTV, HTREEITEM hItem, LPTSTR keyPath, int* pPathLen, in
hKey = (HKEY)item.lParam;
item.mask = TVIF_TEXT;
item.hItem = hItem;
/* item.pszText = &keyPath[*pPathLen]; */
/* item.pszText = &keyPath[*pPathLen]; */
item.pszText = keyPath;
item.cchTextMax = max;
if (TreeView_GetItem(hwndTV, &item)) {
......@@ -150,7 +150,7 @@ static BOOL InitTreeViewImageLists(HWND hwndTV)
/* Create the image list. */
if ((himl = ImageList_Create(CX_BITMAP, CY_BITMAP,
FALSE, NUM_BITMAPS, 0)) == NULL)
FALSE, NUM_BITMAPS, 0)) == NULL)
return FALSE;
/* Add the open file, closed file, and document bitmaps. */
......@@ -213,7 +213,7 @@ BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
if (errCode == ERROR_SUCCESS) {
TCHAR SubName[MAX_NAME_LEN];
DWORD cSubName = MAX_NAME_LEN;
/* if (RegEnumKeyEx(hKey, 0, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { */
/* if (RegEnumKeyEx(hKey, 0, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { */
while (RegEnumKeyEx(hKey, dwCount, SubName, &cSubName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
++dwCount;
}
......@@ -223,10 +223,9 @@ BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
cName = MAX_NAME_LEN;
++dwIndex;
}
/*ShowWindow(hwndTV, SW_SHOWNOACTIVATE); */
/*ShowWindow(hwndTV, SW_SHOWNOACTIVATE); */
RegCloseKey(hNewKey);
}
} else {
}
expanding = FALSE;
return TRUE;
......@@ -246,9 +245,9 @@ HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id)
/* Get the dimensions of the parent window's client area, and create the tree view control. */
GetClientRect(hwndParent, &rcClient);
hwndTV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, _T("Tree View"),
WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL);
WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, (HMENU)id, hInst, NULL);
/* Initialize the image list, and add items to the control. */
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) {
DestroyWindow(hwndTV);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment