📄 itfindfiles.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//
// $NoKeywords: $
//
// @doc EXTERNAL UTILITY
#include "StdAfx.h"
#include "ITFindFiles.h"
#include "ITSimpleFindFiles.h"
#include "ITAPI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
DWORD ITCFindFiles::None = 0x0000;
DWORD ITCFindFiles::IncludeSubfolders = 0x0001;
DWORD ITCFindFiles::SearchingSubfolders = 0x0002;
DWORD ITCFindFiles::AllAttributes = ITCSimpleFindFiles::AllAttributes;
DWORD ITCFindFiles::DefaultAttributes = ITCSimpleFindFiles::DefaultAttributes;
DWORD ITCFindFiles::FilesOnly = ITCSimpleFindFiles::FilesOnly;
DWORD ITCFindFiles::FoldersOnly = ITCSimpleFindFiles::FoldersOnly;
/////////////////////////////////////////////////////////////////////////////
// ITCFindFiles helpers
static BOOL IsNonFatalError(DWORD dwError)
{
BOOL bNonFatal = FALSE; // Assume so
switch (dwError)
{
case ERROR_FILE_NOT_FOUND:
case ERROR_NO_MORE_FILES:
bNonFatal = TRUE;
break;
}
return bNonFatal;
}
/////////////////////////////////////////////////////////////////////////////
// ITCFindFiles construction
// @mfunc Constructs a <c ITCFindFiles> object.
//
// @xref <c ITCFindFiles>
ITCFindFiles::ITCFindFiles()
{
m_lpEnumProc = NULL;
m_lEnumParam = 0;
}
// @mfunc Destroys a <c ITCFindFiles> object.
//
// @xref <c ITCFindFiles>
ITCFindFiles::~ITCFindFiles()
{
while (!m_findStack.IsEmpty())
CloseSearch();
m_findStack.RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
// ITCFindFiles attributes
// @mfunc Call this method to determine if the found file is archived.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is archived; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsArchived() const
{
return HasFileAttributes(FILE_ATTRIBUTE_ARCHIVE);
}
// @mfunc Call this method to determine if the found file is compressed.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is compressed; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsCompressed() const
{
return HasFileAttributes(FILE_ATTRIBUTE_COMPRESSED);
}
// @mfunc Call this method to determine if the found file is a folder.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is a folder; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsFolder() const
{
return HasFileAttributes(FILE_ATTRIBUTE_DIRECTORY);
}
// @mfunc Call this method to determine if the found file is hidden.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is hidden; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsHidden() const
{
return HasFileAttributes(FILE_ATTRIBUTE_HIDDEN);
}
// @mfunc Call this method to determine if the found file is normal.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is normal; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsNormal() const
{
return HasFileAttributes(FILE_ATTRIBUTE_NORMAL);
}
// @mfunc Call this method to determine if the found file is offline.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is offline; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsOffline() const
{
return HasFileAttributes(FILE_ATTRIBUTE_OFFLINE);
}
// @mfunc Call this method to determine if the found file is read-only.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is read-only; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsReadOnly() const
{
return HasFileAttributes(FILE_ATTRIBUTE_READONLY);
}
// @mfunc Call this method to determine if the found file is a system file.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is a system file; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsSystem() const
{
return HasFileAttributes(FILE_ATTRIBUTE_SYSTEM);
}
// @mfunc Call this method to determine if the found file is temporary.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc Nonzero if the file is a temporary file; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::IsTemporary() const
{
return HasFileAttributes(FILE_ATTRIBUTE_TEMPORARY);
}
// @mfunc Call this method to test the file attributes of the found file.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @parm Specifies one or more file attributes, identified in the
// <t WIN32_FIND_DATA> structure. Any combination of the attributes is
// acceptable.
//
// @rdesc Nonzero if the file has all of the specified attributes; otherwise 0.
//
// @xref <c ITCFindFiles>
BOOL ITCFindFiles::HasFileAttributes(DWORD dwFileAttributes) const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->HasFileAttributes(dwFileAttributes);
}
// @mfunc Call this method to get the length of the found file, in bytes.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// This method will only return a valid length if the file is less than
// four gigabytes in size.
//
// @rdesc The length of the found file, in bytes.
//
// @xref <c ITCFindFiles>
DWORD ITCFindFiles::GetLength() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetLength();
}
// @mfunc Returns the file attributes, identified in the <t WIN32_FIND_DATA>
// structure, of the found file. You must call <mf ITCFindFiles::NextFile>
// at least once before calling this method.
//
// @rdesc The file attributes of the found file.
//
// @xref <c ITCFindFiles>
DWORD ITCFindFiles::GetFileAttributes() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFileAttributes();
}
// @mfunc Call this method to get the root of the found file.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc The root of the search.
//
// @comm This method returns the drive specifier and path name where
// the search began. This method will always return the complete
// path of the search origin.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFilePath>
// <mf ITCFindFiles::GetFileName> <mf ITCFindFiles::GetFileTitle>
// <mf ITCFindFiles::GetFileFolder>
CString ITCFindFiles::GetRoot() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetRoot();
}
// @mfunc Call this method to get the extension of the found file. For example,
// if the name of the file is DATA.TXT, <mf ITCFindFiles::GetFileExt>
// returns "TXT".
//
// You must call <mf ITCFindFiles::NextFile> at least once before calling
// this method.
//
// @rdesc The extension of the found file.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFileName>
// <mf ITCFindFiles::GetFilePath> <mf ITCFindFiles::GetRoot>
// <mf ITCFindFiles::GetFileFolder>
CString ITCFindFiles::GetFileExt() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFileExt();
}
// @mfunc Call this method to get the full path of the found file. You
// must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc The path of the found file.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFileName>
// <mf ITCFindFiles::GetFileTitle> <mf ITCFindFiles::GetRoot>
// <mf ITCFindFiles::GetFileFolder>
CString ITCFindFiles::GetFilePath() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFilePath();
}
// @mfunc Call this method to get the name of the found file,
// without the extension. You must call <mf ITCFindFiles::NextFile>
// at least once before calling this method.
//
// @rdesc The title of the found file.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFileName>
// <mf ITCFindFiles::GetFilePath> <mf ITCFindFiles::GetRoot>
// <mf ITCFindFiles::GetFileFolder>
CString ITCFindFiles::GetFileTitle() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFileTitle();
}
// @mfunc Call this method to get the name of the found file,
// including the extension. You must call <mf ITCFindFiles::NextFile>
// at least once before calling this method.
//
// @rdesc The name of the found file.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFileTitle>
// <mf ITCFindFiles::GetFilePath> <mf ITCFindFiles::GetRoot>
// <mf ITCFindFiles::GetFileFolder>
LPCTSTR ITCFindFiles::GetFileName() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFileName();
}
// @mfunc Call this method to get the folder containing the found file.
// You must call <mf ITCFindFiles::NextFile> at least once before calling
// this method.
//
// @rdesc The folder containing the found file.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFileTitle>
// <mf ITCFindFiles::GetFilePath> <mf ITCFindFiles::GetRoot>
CString ITCFindFiles::GetFileFolder() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFileFolder();
}
// @mfunc Returns the <t WIN32_FIND_DATA> structure of the found file.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc A pointer to the <t WIN32_FIND_DATA> of the found file.
//
// @xref <c ITCFindFiles>
const WIN32_FIND_DATA* ITCFindFiles::GetFindData() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFindData();
}
// @mfunc Call this method to get the file pattern the search is based on.
// For example, the pattern would be something like *.*, *.DAT, or MY*.TXT.
//
// @rdesc The file pattern of the search.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFindAttributes>
CString ITCFindFiles::GetFindPattern() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFindPattern();
}
// @mfunc Call this method to get the complete search pattern of the search.
// This is based on the find root, determined by <mf ITCFindFiles::GetRoot>
// and the find pattern, determined by <mf ITCFindFiles::GetFindPattern>.
//
// @rdesc The complete search pattern the search is based on.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFindPattern>
CString ITCFindFiles::GetFindFileName() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetFindFileName();
}
// @mfunc Call this method to get the file attributes the search is based on.
// Only files that have the specified attributes will be returned in the
// search.
//
// @parm Specifies file attributes that must be set.
// @parm Specifies file attributes that must not be set.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::SetFindAttributes>
void ITCFindFiles::GetFindAttributes(DWORD& dwAttribSet, DWORD& dwAttribClear) const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
pFind->GetFindAttributes(dwAttribSet, dwAttribClear);
}
// @mfunc Sets the file attributes that are being used to filter the search.
// Only files with attributes that include all of the <p dwAttribSet>
// and none of the <p dwAttribClear> file attributes will be returned.
//
// @parm Specifies file attributes that must be set; 0 to match all files.
// @parm Specifies file attributes that must not be set; 0 to match all files.
//
// @ex |
// // Search for compressed files.
// SetAttributeFilter(FILE_ATTRIBUTE_COMPRESSED, FILE_ATTRIBUTE_DIRECTORY);
//
// // Search for compressed folders.
// SetAttributeFilter(FILE_ATTRIBUTE_COMPRESSED|FILE_ATTRIBUTE_DIRECTORY, 0);
//
// // Search for compressed files and folders.
// SetAttributeFilter(FILE_ATTRIBUTE_COMPRESSED, 0);
//
// // Search for everything.
// SetAttributeFilter(0, 0);
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::GetFindAttributes>
void ITCFindFiles::SetFindAttributes(DWORD dwAttribSet, DWORD dwAttribClear)
{
ASSERT(!m_findStack.IsEmpty());
// This method affects all the searches currently in progress.
// If you only change one of the search objects, there are
// problems when multiple search values are specified in NewSearch.
POSITION pos = m_findStack.GetHeadPosition();
while (pos)
{
ITCSimpleFindFiles* pFind = m_findStack.GetNext(pos);
pFind->SetFindAttributes(dwAttribSet, dwAttribClear);
}
}
// @mfunc Retrieve the string that describes the file's type. This is the same
// description displayed in the Type column of the Windows Explorer.
// You must call <mf ITCFindFiles::NextFile> at least once before
// calling this method.
//
// @rdesc The string that describes the file's type.
//
// @xref <c ITCFindFiles> <mf ITCFindFiles::SHGetFileInfo>
CString ITCFindFiles::GetTypeName() const
{
ASSERT(!m_findStack.IsEmpty());
ITCSimpleFindFiles* pFind = m_findStack.GetTail();
return pFind->GetTypeName();
}
// @mfunc Retrieves shell information about the found file using the
// Win32 <f SHGetFileInfo> function. You must call <mf ITCFindFiles::NextFile>
// at least once before calling this method.
//
// @parm Combination of one or more file attribute flags.
// @parm Address of a <t SHFILEINFO> structure to receive the file information.
// @parm Flags that specify the file information to retrieve.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -