Back to index

lightning-sunbird  0.9+nobinonly
ScanForFilesDlg.cpp
Go to the documentation of this file.
00001 // ScanForFilesDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "IEPatcher.h"
00006 #include "ScanForFilesDlg.h"
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013 
00015 // CScanForFilesDlg dialog
00016 
00017 
00018 CScanForFilesDlg::CScanForFilesDlg(CWnd* pParent /*=NULL*/)
00019        : CDialog(CScanForFilesDlg::IDD, pParent)
00020 {
00021        //{{AFX_DATA_INIT(CScanForFilesDlg)
00022        m_sFilePattern = _T("");
00023        //}}AFX_DATA_INIT
00024 }
00025 
00026 
00027 void CScanForFilesDlg::DoDataExchange(CDataExchange* pDX)
00028 {
00029        CDialog::DoDataExchange(pDX);
00030        //{{AFX_DATA_MAP(CScanForFilesDlg)
00031        DDX_Text(pDX, IDC_FILEPATTERN, m_sFilePattern);
00032        //}}AFX_DATA_MAP
00033 }
00034 
00035 
00036 BEGIN_MESSAGE_MAP(CScanForFilesDlg, CDialog)
00037        //{{AFX_MSG_MAP(CScanForFilesDlg)
00038        ON_BN_CLICKED(IDC_SELECTFILE, OnSelectFile)
00039        ON_BN_CLICKED(IDC_SELECTFOLDER, OnSelectFolder)
00040        //}}AFX_MSG_MAP
00041 END_MESSAGE_MAP()
00042 
00044 // CScanForFilesDlg message handlers
00045 
00046 void CScanForFilesDlg::OnOK() 
00047 {
00048        UpdateData();
00049        CDialog::OnOK();
00050 }
00051 
00052 void CScanForFilesDlg::OnSelectFile() 
00053 {
00054        CFileDialog dlg(TRUE, NULL, _T("*.*"));
00055        
00056        if (dlg.DoModal() == IDOK)
00057        {
00058               m_sFilePattern = dlg.GetPathName();
00059               UpdateData(FALSE);
00060        }
00061 }
00062 
00063 void CScanForFilesDlg::OnSelectFolder() 
00064 {
00065        BROWSEINFO bi;
00066        TCHAR szFolder[MAX_PATH + 1];
00067 
00068        memset(szFolder, 0, sizeof(szFolder));
00069 
00070        memset(&bi, 0, sizeof(bi));
00071        bi.hwndOwner = GetSafeHwnd();
00072        bi.pidlRoot = NULL;
00073        bi.pszDisplayName = szFolder;
00074        bi.lpszTitle = _T("Pick a folder to scan");
00075 
00076        // Open the folder browser dialog
00077        LPITEMIDLIST pItemList = SHBrowseForFolder(&bi);
00078        if (pItemList)
00079        {
00080               IMalloc *pShellAllocator = NULL;
00081               
00082               SHGetMalloc(&pShellAllocator);
00083               if (pShellAllocator)
00084               {
00085                      char szPath[MAX_PATH + 1];
00086 
00087                      if (SHGetPathFromIDList(pItemList, szPath))
00088                      {
00089                             // Chop off the end path separator
00090                             int nPathSize = strlen(szPath);
00091                             if (nPathSize > 0)
00092                             {
00093                                    if (szPath[nPathSize - 1] == '\\')
00094                                    {
00095                                           szPath[nPathSize - 1] = '\0';
00096                                    }
00097                             }
00098 
00099                             // Form the file pattern
00100                             USES_CONVERSION;
00101                             m_sFilePattern.Format(_T("%s\\*.*"), A2T(szPath));
00102                             UpdateData(FALSE);
00103                      }
00104 
00105                      pShellAllocator->Free(pItemList);
00106                      pShellAllocator->Release();
00107               }
00108 
00109        }
00110 }