Click here to 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 !!!
virusss
22:40 10 Dec '06  
The ZipSearch_src.zip is invalid !!!
GeneralThread discussion?
DavidCrow
3:39 2 Oct '03  
You've shown the code that handles the ZIP files, but have no mention of where the multiple threads come into play.


Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?

Generaldelete
Anonymous
15:12 30 Sep '03  
Is it managed code? Where is delete for ifFile?

Regards
Generaldelete
Anonymous
15:12 30 Sep '03  
Is it manage code? Where is delete for ifFile?

Regards
GeneralDownload size
Hans Dietrich
2:47 28 Sep '03  
The source download size is 165KB, not 33KB. You could reduce the download size by not including unnecessary project files like .aps, .clw, .opt, .plg (the only two project files that are necessary are .dsp and .dsw).

Best wishes,
Hans

GeneralRe: Download size
Antony M Kancidrowski
6:40 30 Sep '03  
You don't need the .dsw file either as it will be regenerated when you load the .dsp.Big Grin

Ant.
GeneralCould you fix the horizontal scrolling annoyance?
WREY
1:09 28 Sep '03  
The reader shouldn't have to use a horizontal scrollbar in order to read your article. Could you modify the settings so that a HSB does not show up?

Eek!

William

Fortes in fide et opere!
GeneralRe: Could you fix the horizontal scrolling annoyance?
Uwe Keim
2:35 28 Sep '03  
Yes; he really should do!

--
- Free Windows-based CMS: www.zeta-software.de/enu/producer/freeware/download.html - See me: www.magerquark.de

GeneralRe: Could you fix the horizontal scrolling annoyance?
Marc Clifton
4:14 28 Sep '03  
WREY wrote: Could you modify the settings so that a HSB does not show up?
Is that better? Big Grin

Marc

Latest AAL Article My blog Join my forum!


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