Click here to Skip to main content
5,786,882 members and growing! (26,094 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » Tools with source code     Intermediate

Multithreaded Zip Search

By P.Siva Chandran

This is an small app which searches inside ZIP archives
VC6, VC7, VC7.1, C++Windows, Win2K, WinXP, Win2003, MFC, VS6, Visual Studio, Dev

Posted: 27 Sep 2003
Updated: 27 Sep 2003
Views: 30,092
Bookmarked: 17 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
5 votes for this Article.
Popularity: 2.40 Rating: 3.43 out of 5
0 votes, 0.0%
1
2 votes, 40.0%
2
1 vote, 20.0%
3
2 votes, 40.0%
4
0 votes, 0.0%
5

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

  • ZipSearch Version 1.0 – First Release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

P.Siva Chandran


Hi everybody, Myself Siva Chandran.P.,doing M.C.A. - IInd year, Also a Microsoft Certified Professinal in Visual Basic 6.0
For futher proceedings or queries con. me
@ "scpmdu [at] yahoo.com"
Occupation: Web Developer
Location: India India

Other popular Applications & Tools articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
GeneralThe ZipSearch_src.zip is invalid !!!membervirusss22:40 10 Dec '06  
GeneralThread discussion?memberDavidCrow3:39 2 Oct '03  
GeneraldeletesussAnonymous15:12 30 Sep '03  
GeneraldeletesussAnonymous15:12 30 Sep '03  
GeneralDownload sizememberHans Dietrich2:47 28 Sep '03  
GeneralRe: Download sizememberAntony M Kancidrowski6:40 30 Sep '03  
GeneralCould you fix the horizontal scrolling annoyance?memberWREY1:09 28 Sep '03  
GeneralRe: Could you fix the horizontal scrolling annoyance?sitebuilderUwe Keim2:35 28 Sep '03  
GeneralRe: Could you fix the horizontal scrolling annoyance?editorMarc Clifton4:14 28 Sep '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Sep 2003
Editor: Nishant Sivakumar
Copyright 2003 by P.Siva Chandran
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project