home *** CD-ROM | disk | FTP | other *** search
- // Started.cpp : Defines the entry point for the console application.
- //
- // ATL Sample using The Xceed Zip Compression Library 4
- // Copyright (c) 1998-1999 Xceed Software Inc.
- //
-
- // We added ATL support in this file
- #include "stdafx.h"
- #include <stdio.h>
-
- // These two files are distributed with the Xceed Zip Compression Library 4
-
- #include "zipDispIds.h" // For events' DISPIDs
- #include "zipAtlFuncInfo.h" // For _ATL_FUNC_INFO structures
-
-
- // The easiest way to use the Xceed Zip Compression Library 4 with ATL
- // is using the #import directive. This will generate a wrapper class around
- // each interface in the ActiveX DLL.
-
- #import "XceedZip.dll" no_namespace named_guids
-
-
- // Our Xceed Zip Sink ID (It can be any value)
-
- #define DISPID_XCEEDZIP_SINK 1
-
-
- // Usually, a sink object derives from IDispEventImpl, which uses type info from the
- // event source's typelib to get the funcinfo. But IDispEventImpl::GetUserDefinedType()
- // only handles TKIND_ALIAS. In many of our events, we have TKIND_ENUM parameters.
- // This is why the sink object derives from IDispEventSimpleImpl, which does not use
- // type information. We need to provide an _ATL_FUNC_INFO for each event we want to
- // handle. These can be found in the zipAtlFuncInfo.h file
-
- class CXceedZipEventSink
- : public IDispEventSimpleImpl< DISPID_XCEEDZIP_SINK, CXceedZipEventSink, &DIID__IXceedZipEvents >
- {
- public:
- //
- // Constructor
- //
-
- CXceedZipEventSink( void ) { m_pZip = NULL; }
-
- //
- // Utility methods for our event handling routines
- //
-
- void SetXceedZip( IXceedZip * pZip = NULL ) { m_pZip = pZip; }
-
- //
- // The event handling routines
- //
-
- void _stdcall ListingFile( BSTR sFilename,
- BSTR sComment,
- long lSize,
- long lCompressedSize,
- short nCompressionRatio,
- long lAttributes,
- long lCRC,
- DATE dtLastModified,
- DATE dtLastAccessed,
- DATE dtCreated,
- enum xcdCompressionMethod xMethod,
- VARIANT_BOOL bEncrypted,
- int nDiskNumber,
- VARIANT_BOOL bExcluded,
- enum xcdSkippingReason xReason )
- {
- printf( "%S [%d bytes]\n", sFilename, lSize );
- }
-
- void __stdcall FileStatus( BSTR sFilename,
- long lSize,
- long lCompressedSize,
- long lBytesProcessed,
- short nBytesPercent,
- short nCompressionRatio,
- VARIANT_BOOL bFileCompleted )
- {
- if( m_pZip )
- {
- xcdCurrentOperation xOper = m_pZip->CurrentOperation;
-
- switch( xOper )
- {
- case xcoZipping:
- if( lBytesProcessed == 0 )
- {
- printf( "\nZipping %S [ 0%%]", sFilename );
- }
- else
- {
- printf( "\b\b\b\b\b%03d%%]", nBytesPercent );
- }
- break;
-
- case xcoUnzipping:
- if( lBytesProcessed == 0 )
- {
- printf( "\nUnzipping %S [ 0%%]", sFilename );
- }
- else
- {
- printf( "\b\b\b\b\b%03d%%]", nBytesPercent );
- }
- break;
- }
- }
- }
-
- // The sink map is used by IDispEventSimpleImpl<>. The map contains information about
- // each event handler we want to provide.
- BEGIN_SINK_MAP( CXceedZipEventSink )
- SINK_ENTRY_INFO(DISPID_XCEEDZIP_SINK, DIID__IXceedZipEvents, XCD_ZIP_DISPID_LISTINGFILE, ListingFile, &ListingFile_Info)
- SINK_ENTRY_INFO(DISPID_XCEEDZIP_SINK, DIID__IXceedZipEvents, XCD_ZIP_DISPID_FILESTATUS, FileStatus, &FileStatus_Info)
- END_SINK_MAP()
-
- private:
- //
- // Private members
- //
-
- IXceedZip* m_pZip;
- };
-
-
- int main(int argc, char* argv[])
- {
- printf( "ATL Getting Started sample using The Xceed Zip Compression Library 4\n\n" );
-
- char cAction = ' ';
- char* pszZipFilename = NULL;
- bool bRecurse = false;
- bool bPreserve = false;
- int nStartFiles = 0;
- int nEndFiles = 0;
- char* pszDestFolder = NULL;
-
- int nIndex = 1;
-
- while( nIndex < argc && !pszZipFilename )
- {
- if( !lstrcmpi( argv[nIndex], "-z" ) )
- {
- cAction = 'Z';
- }
- else if( !lstrcmpi( argv[nIndex], "-u" ) )
- {
- cAction = 'U';
- }
- else if( !lstrcmpi( argv[nIndex], "-l" ) )
- {
- cAction = 'L';
- }
- else if( !lstrcmpi( argv[nIndex], "-r" ) )
- {
- bRecurse = true;
- }
- else if( !lstrcmpi( argv[nIndex], "-p" ) )
- {
- bPreserve = true;
- }
- else
- {
- // This is the zip filename
- pszZipFilename = argv[nIndex];
-
- nStartFiles = nIndex + 1;
- nEndFiles = argc - 1;
-
- if( cAction == 'U' )
- {
- pszDestFolder = argv[argc-1];
- nEndFiles--;
- }
- }
-
- nIndex++;
- }
-
- if( cAction == ' '
- || !pszZipFilename
- || ( cAction == 'Z' && nStartFiles > nEndFiles ) )
- {
- printf( "Format: STARTED action [options] zip_filename [files] [destination]\n\n" );
- printf( "action : -z = zipping\n" );
- printf( " -u = unzipping\n" );
- printf( " -l = listing\n" );
- printf( "options : -r = recurse\n" );
- printf( " -p = preserve paths\n" );
- printf( "zip_filename : the zip file to create or read\n" );
- printf( "files : list of files to zip, unzip or list\n" );
- printf( "destination : unzipping destination (required)\n" );
-
- return 0;
- }
-
- CoInitialize( NULL );
-
- try
- {
- // Instanciate XceedZip
- IXceedZipPtr pZip( CLSID_XceedZip );
-
- // Create and connect event sink
- CXceedZipEventSink xEventSink;
- xEventSink.DispEventAdvise( pZip );
-
- // In this example, our event sink needs a pointer to an IXceedZip
- xEventSink.SetXceedZip( pZip );
-
- // Set properties
- pZip->ZipFilename = pszZipFilename;
- pZip->FilesToProcess = "";
-
- while( nStartFiles <= nEndFiles )
- {
- pZip->AddFilesToProcess( argv[nStartFiles++] );
- }
-
- pZip->ProcessSubfolders = bRecurse;
- pZip->PreservePaths = bPreserve;
-
- xcdError xErr = xerSuccess;
-
- switch( cAction )
- {
- case 'Z':
- xErr = pZip->Zip();
- break;
-
- case 'U':
- pZip->UnzipToFolder = pszDestFolder;
- xErr = pZip->Unzip();
- break;
-
- case 'L':
- xErr = pZip->ListZipContents();
- break;
- }
-
- if( xErr != xerSuccess )
- {
- printf( pZip->GetErrorDescription( xvtError, xErr ) );
- }
- }
- catch( const _com_error& xErr )
- {
- // The generated wrapper classes throw _com_error exceptions
- // when a COM error occurs.
- printf( "\nCOM Error 0x%08X ( %s ).\n", xErr.Error(), xErr.ErrorMessage() );
- }
- catch ( ... )
- {
- printf( "\nUnhandled Exception.\n" );
- }
-
- CoUninitialize();
-
- return 0;
- }
-