Click here to Skip to main content
Licence 
First Posted 27 Sep 2003
Views 38,397
Downloads 1,024
Bookmarked 25 times

Multithreaded Zip Search

By Siva Chandran P | 27 Sep 2003
This is an small app which searches inside ZIP archives

1
2 votes, 40.0%
2
1 vote, 20.0%
3
2 votes, 40.0%
4

5
3.43/5 - 5 votes
μ 3.43, σa 1.75 [?]

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

Siva Chandran P

Web Developer

India India

Member
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"

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThe ZipSearch_src.zip is invalid !!! Pinmembervirusss22:40 10 Dec '06  
QuestionThread discussion? PinmemberDavidCrow3:39 2 Oct '03  
Generaldelete PinsussAnonymous15:12 30 Sep '03  
Generaldelete PinsussAnonymous15:12 30 Sep '03  
GeneralDownload size PinmemberHans Dietrich2:47 28 Sep '03  
GeneralRe: Download size PinmemberAntony M Kancidrowski6:40 30 Sep '03  
QuestionCould you fix the horizontal scrolling annoyance? PinmemberWREY1: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! | :eek:
 
William
 
Fortes in fide et opere!
AnswerRe: Could you fix the horizontal scrolling annoyance? PinsitebuilderUwe Keim2:35 28 Sep '03  
AnswerRe: Could you fix the horizontal scrolling annoyance? PineditorMarc Clifton4:14 28 Sep '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120210.1 | Last Updated 28 Sep 2003
Article Copyright 2003 by Siva Chandran P
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid