File: ScanForFilesDlg.cpp

package info (click to toggle)
kompozer 1%3A0.8~b3.dfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 283,956 kB
  • ctags: 314,166
  • sloc: cpp: 1,763,181; ansic: 990,028; xml: 97,969; makefile: 46,334; asm: 34,989; perl: 26,943; sh: 20,165; cs: 6,232; java: 5,513; python: 3,221; pascal: 340; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (110 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (11)
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
// ScanForFilesDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IEPatcher.h"
#include "ScanForFilesDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScanForFilesDlg dialog


CScanForFilesDlg::CScanForFilesDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScanForFilesDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScanForFilesDlg)
	m_sFilePattern = _T("");
	//}}AFX_DATA_INIT
}


void CScanForFilesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScanForFilesDlg)
	DDX_Text(pDX, IDC_FILEPATTERN, m_sFilePattern);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScanForFilesDlg, CDialog)
	//{{AFX_MSG_MAP(CScanForFilesDlg)
	ON_BN_CLICKED(IDC_SELECTFILE, OnSelectFile)
	ON_BN_CLICKED(IDC_SELECTFOLDER, OnSelectFolder)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScanForFilesDlg message handlers

void CScanForFilesDlg::OnOK() 
{
	UpdateData();
	CDialog::OnOK();
}

void CScanForFilesDlg::OnSelectFile() 
{
	CFileDialog dlg(TRUE, NULL, _T("*.*"));
	
	if (dlg.DoModal() == IDOK)
	{
		m_sFilePattern = dlg.GetPathName();
		UpdateData(FALSE);
	}
}

void CScanForFilesDlg::OnSelectFolder() 
{
	BROWSEINFO bi;
	TCHAR szFolder[MAX_PATH + 1];

	memset(szFolder, 0, sizeof(szFolder));

	memset(&bi, 0, sizeof(bi));
	bi.hwndOwner = GetSafeHwnd();
	bi.pidlRoot = NULL;
	bi.pszDisplayName = szFolder;
	bi.lpszTitle = _T("Pick a folder to scan");

	// Open the folder browser dialog
	LPITEMIDLIST pItemList = SHBrowseForFolder(&bi);
	if (pItemList)
	{
		IMalloc *pShellAllocator = NULL;
		
		SHGetMalloc(&pShellAllocator);
		if (pShellAllocator)
		{
			char szPath[MAX_PATH + 1];

			if (SHGetPathFromIDList(pItemList, szPath))
			{
				// Chop off the end path separator
				int nPathSize = strlen(szPath);
				if (nPathSize > 0)
				{
					if (szPath[nPathSize - 1] == '\\')
					{
						szPath[nPathSize - 1] = '\0';
					}
				}

				// Form the file pattern
				USES_CONVERSION;
				m_sFilePattern.Format(_T("%s\\*.*"), A2T(szPath));
				UpdateData(FALSE);
			}

			pShellAllocator->Free(pItemList);
			pShellAllocator->Release();
		}

	}
}