[REGEDIT]

Add support of sorting by value.
Patch by Katayama Hirofumi.

CORE-4885 #resolve #comment Committed in r57949. Thanks!

svn path=/trunk/; revision=57949
This commit is contained in:
Hermès Bélusca-Maïto 2012-12-18 23:52:08 +00:00
parent e61a4d3fcb
commit 2327831f4b
2 changed files with 97 additions and 10 deletions

View file

@ -288,20 +288,21 @@ static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME* pofn)
return TRUE;
}
#define LOADHIVE_KEYNAMELENGTH 128
static INT_PTR CALLBACK LoadHive_KeyNameInHookProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static LPWSTR sKey = NULL;
static INT sLength = 0;
switch(uMsg)
{
case WM_INITDIALOG:
sKey = (LPWSTR)lParam;
sLength = 128; /* FIXME: Ugly hack! */
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, sLength))
if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, LOADHIVE_KEYNAMELENGTH))
return EndDialog(hWndDlg, -1);
else
return EndDialog(hWndDlg, 0);
@ -348,7 +349,7 @@ static BOOL LoadHive(HWND hWnd)
OPENFILENAME ofn;
WCHAR Caption[128];
LPCWSTR pszKeyPath;
WCHAR xPath[128];
WCHAR xPath[LOADHIVE_KEYNAMELENGTH];
HKEY hRootKey;
WCHAR Filter[1024];
FILTERPAIR filter;
@ -369,7 +370,8 @@ static BOOL LoadHive(HWND hWnd)
/* now load the hive */
if (GetOpenFileName(&ofn))
{
if(DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd, &LoadHive_KeyNameInHookProc, (LPARAM)xPath))
if (DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd,
&LoadHive_KeyNameInHookProc, (LPARAM)xPath))
{
LONG regLoadResult;

View file

@ -127,9 +127,10 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
linfo = (PLINE_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount);
linfo->dwValType = dwValType;
linfo->val_len = dwCount;
if(dwCount > 0)
if (dwCount > 0)
{
memcpy(&linfo[1], ValBuf, dwCount);
linfo->val = &linfo[1];
}
linfo->name = _wcsdup(Name);
@ -373,7 +374,9 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi)
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
LINE_INFO*l, *r;
LINE_INFO *l, *r;
DWORD dw1, dw2;
DWORDLONG qw1, qw2;
UNREFERENCED_PARAMETER(lParamSort);
l = (LINE_INFO*)lParam1;
@ -383,12 +386,94 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor
g_columnToSort = 0;
if (g_columnToSort == 1 && l->dwValType != r->dwValType)
return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType;
{
/* Sort by type */
if (g_invertSort)
return ((int)r->dwValType - (int)l->dwValType);
else
return ((int)l->dwValType - (int)r->dwValType);
}
if (g_columnToSort == 2)
{
/* FIXME: Sort on value */
/* Sort by value */
if (l->dwValType != r->dwValType)
{
if (g_invertSort)
return ((int)r->dwValType - (int)l->dwValType);
else
return ((int)l->dwValType - (int)r->dwValType);
}
if (r->val == NULL && l->val == NULL)
return 0;
if (g_invertSort)
{
if (r->val == NULL)
return -1;
if (l->val == NULL)
return 1;
}
else
{
if (r->val == NULL)
return 1;
if (l->val == NULL)
return -1;
}
switch(l->dwValType)
{
case REG_DWORD:
{
dw1 = *(DWORD*)l->val;
dw2 = *(DWORD*)r->val;
if (g_invertSort)
// return (dw1 > dw2 ? -1 : 1);
return ((int)dw2 - (int)dw1);
else
// return (dw1 > dw2 ? 1 : -1);
return ((int)dw1 - (int)dw2);
}
case REG_QWORD:
{
qw1 = *(DWORDLONG*)l->val;
qw2 = *(DWORDLONG*)r->val;
if (g_invertSort)
// return (qw1 > qw2 ? -1 : 1);
return ((int)qw2 - (int)qw1);
else
// return (qw1 > qw2 ? 1 : -1);
return ((int)qw1 - (int)qw2);
}
default:
{
INT nCompare = 0;
if (g_invertSort)
{
nCompare = memcmp(r->val, l->val, min(r->val_len, l->val_len));
if (nCompare == 0)
nCompare = r->val_len - l->val_len;
}
else
{
nCompare = memcmp(l->val, r->val, min(l->val_len, r->val_len));
if (nCompare == 0)
nCompare = l->val_len - r->val_len;
}
return nCompare;
}
}
}
return g_invertSort ? wcsicmp(r->name, l->name) : wcsicmp(l->name, r->name);
/* Sort by name */
return (g_invertSort ? wcsicmp(r->name, l->name) : wcsicmp(l->name, r->name));
}
BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)