forked from ladislav-zezula/FileTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page08Ea.cpp
241 lines (204 loc) · 7.85 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*****************************************************************************/
/* 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 EaBuffer = NULL;
FILE_EA_INFORMATION FileEaInfo;
TFileTestData * pData = GetDialogData(hDlg);
IO_STATUS_BLOCK IoStatus = {0};
NTSTATUS Status = STATUS_SUCCESS;
ULONG EaBufferSize = 0;
//
// Although it is possible to get the size of the extended attributes,
// I've tried and the size is usually not enough for receiving EAs.
// I don't know what the QueryFileInfo for FileEaInformation is good for then :-(
//
Status = NtQueryInformationFile(pData->hFile,
&IoStatus,
&FileEaInfo,
sizeof(FILE_EA_INFORMATION),
FileEaInformation);
// Allocate the buffer large enough to hold the EAs.
if(Status == STATUS_SUCCESS && FileEaInfo.EaSize > 0)
{
EaBufferSize = FileEaInfo.EaSize;
EaBuffer = (PFILE_FULL_EA_INFORMATION)HeapAlloc(g_hHeap, 0, EaBufferSize);
if(EaBuffer == NULL)
Status = STATUS_INSUFFICIENT_RESOURCES;
}
// Query the EAs, if any. If the buffer is not large enough,
// double its size and try again
if(Status == STATUS_SUCCESS && EaBufferSize > 0)
{
BOOL bEndLoop = FALSE;
while(bEndLoop == FALSE)
{
Status = NtQueryEaFile(pData->hFile,
&IoStatus,
EaBuffer,
EaBufferSize,
FALSE,
NULL,
0,
NULL,
TRUE);
switch(Status)
{
// We succeeded or not "buffer too small" => break
case STATUS_SUCCESS:
default:
bEndLoop = TRUE;
break;
// We need to increment buffer size
case STATUS_BUFFER_OVERFLOW:
case STATUS_BUFFER_TOO_SMALL:
EaBufferSize *= 2;
EaBuffer = (PFILE_FULL_EA_INFORMATION)HeapReAlloc(g_hHeap, 0, EaBuffer, EaBufferSize);
Status = STATUS_SUCCESS;
if(EaBuffer == NULL)
{
Status = STATUS_INSUFFICIENT_RESOURCES;
bEndLoop = TRUE;
}
break;
}
}
}
// If we got something, fill the listview
if(Status == STATUS_SUCCESS)
{
ExtendedAttributesToListView(hDlg, EaBuffer);
}
// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
if(EaBuffer != NULL)
HeapFree(g_hHeap, 0, EaBuffer);
return TRUE;
}
static int OnSetEa(HWND hDlg)
{
PFILE_FULL_EA_INFORMATION pFileEa = NULL;
TFileTestData * pData = GetDialogData(hDlg);
IO_STATUS_BLOCK IoStatus = {0};
NTSTATUS Status = STATUS_SUCCESS;
ULONG dwEaLength = 0;
// Get the EA buffer and size
pFileEa = ListViewToExtendedAttributes(hDlg, dwEaLength);
// Set the extended attributes to the file
Status = NtSetEaFile(pData->hFile,
&IoStatus,
pFileEa,
dwEaLength);
// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
// Delete buffers and exit
if(pFileEa != NULL)
delete [] pFileEa;
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;
}