Skip to main content
Email Password   helpLost your password?

Sample Image - ZipSearch.jpg

Introduction

This is a small dialog based multithreaded app which helps us to search inside ZIP archives. It uses the CZipArchive class to open and process ZIP archives.

Background

This app uses CZipArchive class, for more about this CZipArchive information follow the link

void CZipSearchDlg::EnumerateDirectory(CString Directory)
{
  int nCount,i;
  CString strFilename;
  BOOL bResult;
  CFileFind ZIPFiles;
  CZipArchive ZIPFile;
  CZipFileHeader ZIPFileHeader;
  CLike CompareLike;
  CString strStatus;
  BOOL bDisplayStatus=TRUE;
  SHFILEINFO    sfi;

  LV_ITEM lvItem;struct ItemFile *ifFile;

  Directory.TrimLeft();Directory.TrimRight();
  if(Directory.Right(1)=="\\")
    bResult=ZIPFiles.FindFile(Directory+"*.*");
  else
    bResult=ZIPFiles.FindFile(Directory+"\\"+"*.*");
  //Does the recursive search
  while(bResult && !m_bStopEnumeration && !m_bSkipDirectory)
  {
    if(bDisplayStatus)
    {
      strStatus.Format("Processing %s",Directory);
      m_wndStatusBar.SetText(strStatus,0,0);
      bDisplayStatus=TRUE;
    }
    bResult=ZIPFiles.FindNextFile();
    if(!ZIPFiles.IsDots())
      if(ZIPFiles.IsDirectory())
      {
        //Calls itself again
        EnumerateDirectory(ZIPFiles.GetFilePath());
        bDisplayStatus=TRUE;
      }
      else
      {
        strFilename=ZIPFiles.GetFileName();
        strFilename.MakeUpper();
        //Checks whether it is a ZIP file or not.
        if(strFilename.Right(3)=="ZIP")
        {
          try
          {
            ZIPFile.Open(ZIPFiles.GetFilePath());
            nCount=ZIPFile.GetNoEntries();
            if(nCount>50)
            {
              //Updates the statusbar
              strStatus.Format("Processing %s", ZIPFiles.GetFilePath());
              m_wndStatusBar.SetText(strStatus,0,0);
              m_wndProgressSearch.SetRange(0,nCount-1);
              m_wndProgressSearch.ShowWindow(SW_SHOW);
            }
            //Searches inside ZIP file
            for(i=0; i<nCount && !m_bStopEnumeration &&
                !m_bSkipDirectory && !m_bSkipFile;i++)
            {
              if(nCount>10)
                m_wndProgressSearch.SetPos(i);
              ZIPFile.GetFileInfo(ZIPFileHeader,(WORD)i);
              if(CompareLike.IsLike(ZIPFileHeader.GetFileName(), 
                m_strFilename))
              {
                SHGetFileInfo(ZIPFileHeader.GetFileName(),
                  0,&sfi,sizeof(SHFILEINFO),
                  SHGFI_USEFILEATTRIBUTES|SHGFI_SYSICONINDEX|
                  SHGFI_TYPENAME|
                  (m_lvResult.GetStyle()&
                     LVS_ICON?SHGFI_LARGEICON:SHGFI_SMALLICON));

                ifFile=new ItemFile;
                ifFile->strFilename=ZIPFileHeader.GetFileName();
                ifFile->strType=sfi.szTypeName;
                if(ifFile->strType.IsEmpty())
                if(ifFile->strFilename.ReverseFind('.')>0)
                {
                  ifFile->strType=ifFile->strFilename.Right((
                    ifFile->strFilename.GetLength() -
                    ifFile->strFilename.ReverseFind('.'))-1);
                  ifFile->strType.MakeUpper();
                  ifFile->strType+=" File";
                }
                else
                  ifFile->strType="Unknown";
                // If it satisfies the search criteria then obtain the file 
                // information and it's associated icon
                ifFile->strSize.Format("%u KB",
                  (ZIPFileHeader.m_uUncomprSize/1024)?
                  (ZIPFileHeader.m_uUncomprSize/1024):1);
                ifFile->strZIPFilename=ZIPFiles.GetFileName();
                ifFile->strPath=ZIPFiles.GetRoot();
                                
                lvItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
                lvItem.iItem=m_lvResult.GetItemCount();
                lvItem.iSubItem=0;
                lvItem.iImage=sfi.iIcon;
                lvItem.pszText=(LPSTR)ifFile->strFilename.operator LPCTSTR();
                lvItem.lParam=(LPARAM)ifFile;
                m_lvResult.InsertItem(&lvItem);
                                
                }
              }
              if(nCount>10)
              {
                m_wndProgressSearch.ShowWindow(SW_HIDE);
                bDisplayStatus=TRUE;
              }
              m_bSkipFile=FALSE;
              ZIPFile.Close();                    
            }
            catch(...)
            {
              if(!ZIPFile.IsClosed())
                ZIPFile.Close();
            }
          }    
       }
    }
  m_bSkipDirectory=FALSE;
  ZIPFiles.Close();
}

Points of Interest

Yes, I learned how to write a multithreaded app and how to process ZIP archives.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralThe ZipSearch_src.zip is invalid !!! Pin
virusss
22:40 10 Dec '06  
GeneralThread discussion? Pin
DavidCrow
3:39 2 Oct '03  
Generaldelete Pin
Anonymous
15:12 30 Sep '03  
Generaldelete Pin
Anonymous
15:12 30 Sep '03  
GeneralDownload size Pin
Hans Dietrich
2:47 28 Sep '03  
GeneralRe: Download size Pin
Antony M Kancidrowski
6:40 30 Sep '03  
GeneralCould you fix the horizontal scrolling annoyance? Pin
WREY
1:09 28 Sep '03  
GeneralRe: Could you fix the horizontal scrolling annoyance? Pin
Uwe Keim
2:35 28 Sep '03  
GeneralRe: Could you fix the horizontal scrolling annoyance? Pin
Marc Clifton
4:14 28 Sep '03  


Last Updated 27 Sep 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009