Skip to content

Commit

Permalink
Merge pull request #30 from ladislav-zezula/LZ_ImprovementsUI
Browse files Browse the repository at this point in the history
UI Improvements by Diversenok
  • Loading branch information
ladislav-zezula authored Jun 11, 2024
2 parents 99fee74 + 9b977a3 commit d572c08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
3 changes: 3 additions & 0 deletions Page02NtCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,10 @@ static int OnNtCreateFileClick(HWND hDlg)
{
// Convert object ID to binary value
if(StringToFileID(szFileName, NULL, ObjectID, &cbObjectID) != ERROR_SUCCESS)
{
SetResultInfo(hDlg, RSI_NTSTATUS, STATUS_INVALID_DATA_FORMAT);
return TRUE;
}

// Set the object ID to the UNICODE_STRING
FileName.MaximumLength =
Expand Down
56 changes: 15 additions & 41 deletions Page08Ea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,52 +63,22 @@ static int OnSetActive(HWND hDlg)

static int OnQueryEa(HWND hDlg)
{
PFILE_FULL_EA_INFORMATION NewEaBuffer;
PFILE_FULL_EA_INFORMATION NewEaBuffer = NULL;
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;
}
ULONG EaBufferSize = 0x400;

// Query the EAs, if any. If the buffer is not large enough,
// double its size and try again
if(Status == STATUS_SUCCESS && EaBufferSize > 0)
// Allocate the buffer for extended attributes
EaBuffer = (PFILE_FULL_EA_INFORMATION)HeapAlloc(g_hHeap, 0, EaBufferSize);
if(EaBuffer != NULL)
{
__TryQueryEA:

// Retrieve the extended attributes
Status = NtQueryEaFile(pData->hFile,
&IoStatus,
EaBuffer,
EaBufferSize,
FALSE,
NULL,
0,
NULL,
TRUE);

// 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
Expand All @@ -125,17 +95,21 @@ static int OnQueryEa(HWND hDlg)
}

// Failed to reallocate - free the buffer and stop
HeapFree(g_hHeap, 0, EaBuffer);
Status = STATUS_INSUFFICIENT_RESOURCES;
EaBuffer = NULL;
break;

// If OK, format the list view with extended attributes
case STATUS_SUCCESS:
ExtendedAttributesToListView(hDlg, EaBuffer);
HeapFree(g_hHeap, 0, EaBuffer);
break;
}

// Free the buffer for extended attributes
HeapFree(g_hHeap, 0, EaBuffer);
}
else
{
Status = STATUS_INSUFFICIENT_RESOURCES;
}

// Set the result to the dialog
Expand Down

0 comments on commit d572c08

Please sign in to comment.