home *** CD-ROM | disk | FTP | other *** search
Wrap
// StartedDlg.cpp : implementation file // // This file is part of the Xceed Zip 4 "Getting Started" sample using MFC // Copyright (c) 1998-1999 Xceed Software Inc. // #include "stdafx.h" #include "Started.h" #include "StartedDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CStartedDlg dialog CStartedDlg::CStartedDlg(CWnd* pParent /*=NULL*/) : CDialog(CStartedDlg::IDD, pParent) { //{{AFX_DATA_INIT(CStartedDlg) m_bPreserve = TRUE; m_bSubfolders = TRUE; m_bUseTemp = TRUE; m_sFilesToExclude = _T(""); m_sFilesToProcess = _T(""); m_sUnzipFolder = _T(""); m_sZipFilename = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CStartedDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStartedDlg) DDX_Control(pDX, IDC_PR_STATUS, m_prStatus); DDX_Control(pDX, IDC_L_RESULTS, m_lstResults); DDX_Control(pDX, IDC_CB_LEVEL, m_cbLevel); DDX_Control(pDX, IDC_Z_XCEED, m_xZip); DDX_Check(pDX, IDC_C_PRESERVE, m_bPreserve); DDX_Check(pDX, IDC_C_SUBFOLDERS, m_bSubfolders); DDX_Check(pDX, IDC_C_TEMP, m_bUseTemp); DDX_Text(pDX, IDC_E_FILESTOEXCLUDE, m_sFilesToExclude); DDX_Text(pDX, IDC_E_FILESTOPROCESS, m_sFilesToProcess); DDX_Text(pDX, IDC_E_UNZIPFOLDER, m_sUnzipFolder); DDX_Text(pDX, IDC_E_ZIPFILENAME, m_sZipFilename); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CStartedDlg, CDialog) //{{AFX_MSG_MAP(CStartedDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDOK, OnQuit) ON_BN_CLICKED(IDC_B_ZIP, OnZip) ON_BN_CLICKED(IDC_B_UNZIP, OnUnzip) ON_BN_CLICKED(IDC_B_TEST, OnTest) ON_BN_CLICKED(IDC_B_LIST, OnList) ON_BN_CLICKED(IDC_B_PREVIEW, OnPreview) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CStartedDlg message handlers BOOL CStartedDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // Fill the "Compression Level" combo box (not sorted!) m_cbLevel.AddString( "No compression" ); m_cbLevel.AddString( "Low compression" ); m_cbLevel.AddString( "Medium compression" ); m_cbLevel.AddString( "Maximum compression" ); m_cbLevel.SetItemData( 0, 0 /* xclNone */ ); m_cbLevel.SetItemData( 1, 1 /* xclLow */ ); m_cbLevel.SetItemData( 2, 6 /* xclMedium */ ); m_cbLevel.SetItemData( 3, 9 /* xclHigh */ ); m_cbLevel.SetCurSel( 3 ); // Set the status bar limits m_prStatus.SetRange( 0, 100 ); // We'll work with the Xceed Zip Control in background processing m_xZip.SetBackgroundProcessing( TRUE ); return TRUE; // return TRUE unless you set the focus to a control } void CStartedDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CStartedDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CStartedDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } // We created this utility method to match a string with an Xceed Zip operation CString CStartedDlg::GetOperation( int nOperation ) { switch( nOperation ) { case 0: /* xcoIdle */ return CString( "doing nothing" ); case 1: /* xcoPreviewing */ return CString( "previewing" ); case 2: /* xcoListing */ return CString( "listing" ); case 3: /* xcoZipping */ return CString( "zipping" ); case 4: /* xcoUnzipping */ return CString( "unzipping" ); case 5: /* xcoRemoving */ return CString( "removing" ); case 6: /* xcoTestingZipFile */ return CString( "testing" ); case 7: /* xcoConverting */ return CString( "converting" ); } return CString(); } void CStartedDlg::OnQuit() { if( m_xZip.GetCurrentOperation() != 0 /* xcoIdle */ ) { m_xZip.SetAbort( TRUE ); } else { EndDialog( IDOK ); } } void CStartedDlg::OnZip() { if( UpdateData( TRUE ) ) { // First, set the general properties m_xZip.SetZipFilename( m_sZipFilename ); m_xZip.SetFilesToProcess( m_sFilesToProcess ); m_xZip.SetFilesToExclude( m_sFilesToExclude ); m_xZip.SetProcessSubfolders( m_bSubfolders ); m_xZip.SetPreservePaths( m_bPreserve ); // Then set the zipping specific properties int nIndex = m_cbLevel.GetCurSel(); if( nIndex != CB_ERR ) { m_xZip.SetCompressionLevel( m_cbLevel.GetItemData( nIndex ) ); } m_xZip.SetUseTempFile( m_bUseTemp ); // Reset the list and status bar if( m_xZip.GetCurrentOperation() == 0 /* xcoIdle */ ) { m_lstResults.ResetContent(); m_prStatus.SetPos( 0 ); } // Else, for the sake of the demonstration, we'll let the call to Zip // go through even if the control is already doing something // Call the Zip method to start zipping int nErr = m_xZip.Zip(); if( nErr == 1 /* xerProcessStarted */ ) { SetDlgItemText( IDOK, "&Abort" ); GetDlgItem( IDOK )->UpdateWindow(); } else { MessageBox( m_xZip.GetErrorDescription( 0 /* xvtError */, nErr ), NULL, MB_ICONSTOP | MB_OK ); } } } void CStartedDlg::OnUnzip() { if( UpdateData( TRUE ) ) { // First, set the general properties m_xZip.SetZipFilename( m_sZipFilename ); m_xZip.SetFilesToProcess( m_sFilesToProcess ); m_xZip.SetFilesToExclude( m_sFilesToExclude ); m_xZip.SetProcessSubfolders( m_bSubfolders ); m_xZip.SetPreservePaths( m_bPreserve ); // Then set the unzipping specific properties m_xZip.SetUnzipToFolder( m_sUnzipFolder ); // Reset the list and status bar if( m_xZip.GetCurrentOperation() == 0 /* xcoIdle */ ) { m_lstResults.ResetContent(); m_prStatus.SetPos( 0 ); } // Else, for the sake of the demonstration, we'll let the call to Unzip // go through even if the control is already doing something // Call the Unzip method to start zipping int nErr = m_xZip.Unzip(); if( nErr == 1 /* xerProcessStarted */ ) { SetDlgItemText( IDOK, "&Abort" ); GetDlgItem( IDOK )->UpdateWindow(); } else { MessageBox( m_xZip.GetErrorDescription( 0 /* xvtError */, nErr ), NULL, MB_ICONSTOP | MB_OK ); } } } void CStartedDlg::OnTest() { if( UpdateData( TRUE ) ) { // First, set the general properties m_xZip.SetZipFilename( m_sZipFilename ); // When testing, file masks are not used // Reset the list and status bar if( m_xZip.GetCurrentOperation() == 0 /* xcoIdle */ ) { m_lstResults.ResetContent(); m_prStatus.SetPos( 0 ); } // Else, for the sake of the demonstration, we'll let the call to // TestZipFile go through even if the control is already doing something // Call the TestZipFile method to start zipping int nErr = m_xZip.TestZipFile( TRUE ); if( nErr == 1 /* xerProcessStarted */ ) { SetDlgItemText( IDOK, "&Abort" ); GetDlgItem( IDOK )->UpdateWindow(); } else { MessageBox( m_xZip.GetErrorDescription( 0 /* xvtError */, nErr ), NULL, MB_ICONSTOP | MB_OK ); } } } void CStartedDlg::OnList() { if( UpdateData( TRUE ) ) { // First, set the general properties m_xZip.SetZipFilename( m_sZipFilename ); m_xZip.SetFilesToProcess( m_sFilesToProcess ); m_xZip.SetFilesToExclude( m_sFilesToExclude ); m_xZip.SetProcessSubfolders( m_bSubfolders ); m_xZip.SetPreservePaths( m_bPreserve ); // Reset the list and status bar if( m_xZip.GetCurrentOperation() == 0 /* xcoIdle */ ) { m_lstResults.ResetContent(); m_prStatus.SetPos( 0 ); } // Else, for the sake of the demonstration, we'll let the call to // ListZipContents go through even if the control is already doing something // Call the ListZipContents method to start zipping int nErr = m_xZip.ListZipContents(); if( nErr == 1 /* xerProcessStarted */ ) { SetDlgItemText( IDOK, "&Abort" ); GetDlgItem( IDOK )->UpdateWindow(); } else { MessageBox( m_xZip.GetErrorDescription( 0 /* xvtError */, nErr ), NULL, MB_ICONSTOP | MB_OK ); } } } void CStartedDlg::OnPreview() { if( UpdateData( TRUE ) ) { // First, set the general properties m_xZip.SetZipFilename( m_sZipFilename ); m_xZip.SetFilesToProcess( m_sFilesToProcess ); m_xZip.SetFilesToExclude( m_sFilesToExclude ); m_xZip.SetProcessSubfolders( m_bSubfolders ); m_xZip.SetPreservePaths( m_bPreserve ); // Reset the list and status bar if( m_xZip.GetCurrentOperation() == 0 /* xcoIdle */ ) { m_lstResults.ResetContent(); m_prStatus.SetPos( 0 ); } // Else, for the sake of the demonstration, we'll let the call to // PreviewFiles go through even if the control is already doing something // Call the PreviewFiles method to start zipping int nErr = m_xZip.PreviewFiles( FALSE ); if( nErr != 1 /* xerProcessStarted */ ) { MessageBox( m_xZip.GetErrorDescription( 0 /* xvtError */, nErr ), NULL, MB_ICONSTOP | MB_OK ); } } } BOOL CStartedDlg::DestroyWindow() { // Do not let this application quit if the Xceed Zip Control is busy if( m_xZip.m_hWnd && m_xZip.GetCurrentOperation() != 0 /* xcoIdle */ ) { return FALSE; } return CDialog::DestroyWindow(); } BEGIN_EVENTSINK_MAP(CStartedDlg, CDialog) //{{AFX_EVENTSINK_MAP(CStartedDlg) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6001 /* ListingFile */, OnXceedZipListingFile, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I4 VTS_DATE VTS_DATE VTS_DATE VTS_I4 VTS_BOOL VTS_I4 VTS_BOOL VTS_I4) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6000 /* PreviewingFile */, OnXceedZipPreviewingFile, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_DATE VTS_DATE VTS_DATE VTS_BOOL VTS_I4) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6102 /* SkippingFile */, OnXceedZipSkippingFile, VTS_BSTR VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_DATE VTS_DATE VTS_DATE VTS_I4 VTS_BOOL VTS_I4) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6100 /* FileStatus */, OnXceedZipFileStatus, VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I2 VTS_BOOL) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6101 /* GlobalStatus */, OnXceedZipGlobalStatus, VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4 VTS_I2) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 8900 /* ProcessCompleted */, OnXceedZipProcessCompleted, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I2 VTS_I4) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6103 /* Warning */, OnXceedZipWarning, VTS_BSTR VTS_I4) ON_EVENT(CStartedDlg, IDC_Z_XCEED, 6104 /* ZipContentsStatus */, OnXceedZipContentsStatus, VTS_I4 VTS_I4 VTS_I2) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CStartedDlg::OnXceedZipListingFile(LPCTSTR sFilename, LPCTSTR sComment, long lSize, long lCompressedSize, short nCompressionRatio, long xAttributes, long lCRC, DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated, long xMethod, BOOL bEncrypted, long lDiskNumber, BOOL bExcluded, long xReason) { // A file in the zip is being listed CString sLine; sLine.Format( "%s [%d kb]", sFilename, lSize/1024 ); m_lstResults.AddString( sLine ); } void CStartedDlg::OnXceedZipPreviewingFile(LPCTSTR sFilename, LPCTSTR sSourceFilename, long lSize, long xAttributes, DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated, BOOL bExcluded, long xReason) { // A file on the disk is being scanned CString sLine; sLine.Format( "%s [%d kb]", sFilename, lSize/1024 ); m_lstResults.AddString( sLine ); } void CStartedDlg::OnXceedZipSkippingFile(LPCTSTR sFilename, LPCTSTR sComment, LPCTSTR sFilenameOnDisk, long lSize, long lCompressedSize, long xAttributes, long lCRC, DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated, long xMethod, BOOL bEncrypted, long xReason) { // A file is being skipped for a specific reason CString sLine; sLine.Format( "File %s is skipped for reason %d", sFilename, xReason ); m_lstResults.AddString( sLine ); m_lstResults.AddString( m_xZip.GetErrorDescription( 2 /* xvtSkippingReason */, xReason ) ); } void CStartedDlg::OnXceedZipFileStatus(LPCTSTR sFilename, long lSize, long lCompressedSize, long lBytesProcessed, short nBytesPercent, short nCompressionRatio, BOOL bFileCompleted) { // ZipPreprocessingFile and UnzipPreprocessingFile occur for each file // before a single byte is actually processed. Thus, the FileStatus is // the best place to display file info WHILE each file is processed. if( lBytesProcessed == 0 ) { // First time FileStatus is triggered for this file! m_lstResults.AddString( GetOperation( m_xZip.GetCurrentOperation() ) + " " + sFilename ); } } void CStartedDlg::OnXceedZipGlobalStatus(long lFilesTotal, long lFilesProcessed, long lFilesSkipped, short nFilesPercent, long lBytesTotal, long lBytesProcessed, long lBytesSkipped, short nBytesPercent, long lBytesOutput, short nCompressionRatio) { // More processing in general was done m_prStatus.SetPos( nBytesPercent ); } void CStartedDlg::OnXceedZipProcessCompleted(long lFilesTotal, long lFilesProcessed, long lFilesSkipped, long lBytesTotal, long lBytesProcessed, long lBytesSkipped, long lBytesOutput, short nCompressionRatio, long xResult) { // The operation completed m_lstResults.AddString( m_xZip.GetErrorDescription( 0 /* xvtError */, xResult ) ); // Change the "Abort" button back to "Quit" SetDlgItemText( IDOK, "&Quit" ); GetDlgItem( IDOK )->UpdateWindow(); } void CStartedDlg::OnXceedZipWarning(LPCTSTR sFilename, long xWarning) { // A warning occured. Processing of the file continues (as opposed to skipping) CString sLine; sLine.Format( "Warning %d occured on file %s", xWarning, sFilename ); m_lstResults.AddString( sLine ); m_lstResults.AddString( m_xZip.GetErrorDescription( 1 /* xvtWarning */, xWarning ) ); } void CStartedDlg::OnXceedZipContentsStatus(long lFilesRead, long lFilesTotal, short nFilesPercent) { // This event is triggered while reading an existing zip file. m_prStatus.SetPos( nFilesPercent ); }