-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileSearchDlg.cpp
130 lines (110 loc) · 2.76 KB
/
FileSearchDlg.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
// Copyleft 2004 Chris Korda
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or any later version.
/*
chris korda
revision history:
rev date comments
00 09jan04 initial version
01 17jan04 add drive type mask
abstract class to search for files recursively
*/
// FileSearchDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Resource.h"
#include "FileSearchDlg.h"
#include "SubFileFind.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileSearchDlg dialog
CFileSearchDlg::CFileSearchDlg(LPCSTR Folder, CWnd* pParent)
: m_Folder(Folder), CDialog(CFileSearchDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileSearchDlg)
//}}AFX_DATA_INIT
m_DriveTypeMask = DTM_FIXED;
}
CFileSearchDlg::~CFileSearchDlg()
{
}
void CFileSearchDlg::SetDriveTypeMask(int Mask)
{
m_DriveTypeMask = Mask;
}
void CFileSearchDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileSearchDlg)
//}}AFX_DATA_MAP
}
bool CFileSearchDlg::SearchFolder(LPCSTR Folder)
{
CSubFileFind sff;
CFileFind *ff;
BOOL Working = sff.FindFile(CString(Folder) + "\\*.*");
while (Working) {
Working = sff.FindNextFile(ff);
if (!OnFile(ff->GetFilePath()) || m_Cancel)
return(FALSE);
}
return(TRUE);
}
bool CFileSearchDlg::SearchAllDrives()
{
DWORD len = GetLogicalDriveStrings(0, NULL); // get list size
CString DriveList;
char *p = DriveList.GetBufferSetLength(len);
GetLogicalDriveStrings(len, p);
while (*p) {
// if drive type is selected by type mask
if ((1 << GetDriveType(p)) & m_DriveTypeMask) {
p[2] = 0; // remove backslash
if (!SearchFolder(p))
return(FALSE);
}
p += 4; // drive letter, colon, backslash, null
}
return(TRUE);
}
void CFileSearchDlg::Search()
{
if (m_Folder.IsEmpty())
SearchAllDrives();
else
SearchFolder(m_Folder);
PostMessage(WM_USER);
}
UINT CFileSearchDlg::SearchThread(LPVOID pParam)
{
((CFileSearchDlg *)pParam)->Search();
return(0);
}
BEGIN_MESSAGE_MAP(CFileSearchDlg, CDialog)
//{{AFX_MSG_MAP(CFileSearchDlg)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER, OnUser)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileSearchDlg message handlers
BOOL CFileSearchDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_Cancel = FALSE;
AfxBeginThread(SearchThread, this);
return(TRUE);
}
void CFileSearchDlg::OnCancel()
{
m_Cancel = TRUE;
}
LRESULT CFileSearchDlg::OnUser(WPARAM wParam, LPARAM lParam)
{
EndDialog(m_Cancel ? IDCANCEL : IDOK);
return(0);
}