-
Notifications
You must be signed in to change notification settings - Fork 77
/
Page08Ea.cpp
208 lines (176 loc) · 6.77 KB
/
Page08Ea.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*****************************************************************************/
/* Page08Ea.cpp Copyright (c) Ladislav Zezula 2005 */
/*---------------------------------------------------------------------------*/
/* Description : */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 15.08.05 1.00 Lad The first version of Page08Ea.cpp */
/*****************************************************************************/
#include "FileTest.h"
#include "resource.h"
//-----------------------------------------------------------------------------
// Message handlers
static TAnchors * pAnchors = NULL;
static int OnInitDialog(HWND hDlg, LPARAM lParam)
{
PROPSHEETPAGE * pPage = (PROPSHEETPAGE *)lParam;
TFileTestData * pData = (TFileTestData *)pPage->lParam;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(hDlg);
// Done by shared code
SetDialogData(hDlg, pPage->lParam);
// Configure dialog resizing
if(pData->bEnableResizing)
{
pAnchors = new TAnchors();
pAnchors->AddAnchor(hDlg, IDC_EA_TITLE, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_EA_LIST, akAll);
pAnchors->AddAnchor(hDlg, IDC_MOVE_UP, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_MOVE_DOWN, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_QUERY_EA, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_INSERT, akLeftCenter | akBottom);
pAnchors->AddAnchor(hDlg, IDC_EDIT, akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_DELETE, akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_SET_EA, akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_RESULT_FRAME, akLeft | akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_ERROR_CODE_TITLE, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_ERROR_CODE, akLeft | akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_INFORMATION_TITLE, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_INFORMATION, akLeft | akRight | akBottom);
}
return TRUE;
}
static int OnSetActive(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
BOOL bEnable = FALSE;
if(IsHandleValid(pData->hFile))
bEnable = TRUE;
EnableDlgItems(hDlg, bEnable, IDC_QUERY_EA, IDC_SET_EA, 0);
return TRUE;
}
static int OnQueryEa(HWND hDlg)
{
PFILE_FULL_EA_INFORMATION NewEaBuffer = NULL;
PFILE_FULL_EA_INFORMATION EaBuffer = NULL;
TFileTestData * pData = GetDialogData(hDlg);
IO_STATUS_BLOCK IoStatus = {0};
NTSTATUS Status = STATUS_SUCCESS;
ULONG EaBufferSize = 0x400;
// Allocate the buffer for extended attributes
EaBuffer = (PFILE_FULL_EA_INFORMATION)HeapAlloc(g_hHeap, 0, EaBufferSize);
if(EaBuffer != NULL)
{
__TryQueryEA:
// Try to query the extended attributes
memset(EaBuffer, 0, EaBufferSize);
Status = NtQueryEaFile(pData->hFile, &IoStatus, EaBuffer, EaBufferSize, FALSE, NULL, 0, NULL, TRUE);
switch(Status)
{
// If not enough memory, then reallocate buffer
case STATUS_BUFFER_OVERFLOW:
case STATUS_BUFFER_TOO_SMALL:
// Allocate new buffer. If succeeded, we try to query again
EaBufferSize = EaBufferSize << 1;
NewEaBuffer = (PFILE_FULL_EA_INFORMATION)HeapReAlloc(g_hHeap, 0, EaBuffer, EaBufferSize);
if(NewEaBuffer != NULL)
{
EaBuffer = NewEaBuffer;
goto __TryQueryEA;
}
// Failed to reallocate - free the buffer and stop
Status = STATUS_INSUFFICIENT_RESOURCES;
break;
// If OK, format the list view with extended attributes
case STATUS_SUCCESS:
ExtendedAttributesToListView(hDlg, EaBuffer);
break;
}
// Free the buffer for extended attributes
HeapFree(g_hHeap, 0, EaBuffer);
}
else
{
Status = STATUS_INSUFFICIENT_RESOURCES;
}
// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
return TRUE;
}
static int OnSetEa(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
IO_STATUS_BLOCK IoStatus = {0};
TOpenPacket OpenFile;
NTSTATUS Status = STATUS_SUCCESS;
// Get the EA buffer and size
if(ListViewToExtendedAttributes(hDlg, OpenFile) == ERROR_SUCCESS)
{
// Set the extended attributes to the file
Status = NtSetEaFile(pData->hFile,
&IoStatus,
OpenFile.pvFileEa,
OpenFile.cbFileEa);
// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
OpenFile.Free();
}
return TRUE;
}
static int OnCommand(HWND hDlg, UINT nNotify, UINT nIDCtrl)
{
if(nNotify == BN_CLICKED)
{
switch(nIDCtrl)
{
case IDC_QUERY_EA:
return OnQueryEa(hDlg);
case IDC_SET_EA:
return OnSetEa(hDlg);
}
}
return FALSE;
}
static int OnNotify(HWND hDlg, NMHDR * pNMHDR)
{
switch(pNMHDR->code)
{
case PSN_SETACTIVE:
return OnSetActive(hDlg);
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Public functions
INT_PTR CALLBACK PageProc08(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// WM_INITDIALOG is special case, we need to call both init routines
if(uMsg == WM_INITDIALOG)
{
ExtendedAttributesEditorProc(hDlg, uMsg, wParam, 0);
OnInitDialog(hDlg, lParam);
return TRUE;
}
// Call the shared part of EA editor
if(ExtendedAttributesEditorProc(hDlg, uMsg, wParam, lParam))
return TRUE;
// Handlers specific to our dialog
switch(uMsg)
{
case WM_SIZE:
if(pAnchors != NULL)
pAnchors->OnSize();
return FALSE;
case WM_COMMAND:
return OnCommand(hDlg, HIWORD(wParam), LOWORD(wParam));
case WM_NOTIFY:
return OnNotify(hDlg, (NMHDR *)lParam);
case WM_DESTROY:
if(pAnchors != NULL)
delete pAnchors;
pAnchors = NULL;
return FALSE;
}
return FALSE;
}