コード例 #1
0
void OperationLocate::ProcessObjectAction(ObjectEntry & tObjectEntry)
{
	// skip any file names that do not match the regex
	const WCHAR * sFileName = tObjectEntry.Name.c_str();
	if (wcsrchr(sFileName, '\\') != NULL) sFileName = wcsrchr(sFileName, '\\') + 1;
	if (!std::regex_match(sFileName, tRegex)) return;

	// fetch file attribute data
	WIN32_FILE_ATTRIBUTE_DATA tData;
	if (GetFileAttributesExW(tObjectEntry.Name.c_str(), GetFileExInfoStandard, &tData) == 0)
	{
		InputOutput::AddError(L"ERROR: Unable to read file attributes.");
	}

	// convert the file size to a string
	WCHAR sSize[32] = { 0 };
	ULARGE_INTEGER iFileSize;
	iFileSize.LowPart = tData.nFileSizeLow;
	iFileSize.HighPart = tData.nFileSizeHigh;
	setlocale(LC_NUMERIC, "");
	wsprintf(sSize, L"%I64u", iFileSize.QuadPart);

	// decode attributes
	std::wstring sAttributes = L"";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) sAttributes += L"R";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) sAttributes += L"H";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) sAttributes += L"S";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) sAttributes += L"D";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) sAttributes += L"A";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) sAttributes += L"T";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) sAttributes += L"C";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) sAttributes += L"O";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) sAttributes += L"N";
	if (tData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) sAttributes += L"E";

	// write the string to a file
	std::wstring sToWrite = std::wstring(L"") + Q(tObjectEntry.Name) + L"," +
		Q(FileTimeToString(&tData.ftCreationTime)) + L"," + Q(FileTimeToString(&tData.ftLastWriteTime)) +
		L"," + Q(sSize) + L"," + Q(sAttributes) + L"\r\n";
	if (WriteToFile(sToWrite, hReportFile) == 0)
	{
		InputOutput::AddError(L"ERROR: Unable to write security information to report file.");
	}
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: DaZhu/gac
	// Fill all information about a directory or a file.
	FOREACH(WString, file, files)
	{
		Ptr<list::ListViewItem> item=new list::ListViewItem;
		WString fullPath=path+L"\\"+file;

		// Get large icon.
		item->largeImage=GetFileIcon(fullPath, SHGFI_LARGEICON | SHGFI_ICON);
		// Get small icon.
		item->smallImage=GetFileIcon(fullPath, SHGFI_SMALLICON | SHGFI_ICON);
		// Get display name
		item->text=GetFileDisplayName(fullPath);
		// Get type name
		item->subItems.Add(GetFileTypeName(fullPath));
		// Get last write time
		item->subItems.Add(FileTimeToString(GetFileLastWriteTime(fullPath)));
		// Get file size
		item->subItems.Add(FileSizeToString(GetFileSize(fullPath)));

		listView->GetItems().Add(item);
	}