home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / zstud1 / unzip.cp_ / UNZIP.CPP
Encoding:
C/C++ Source or Header  |  1994-04-09  |  6.2 KB  |  174 lines

  1. // unzip.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "zdemo.h"
  6. #include "unzip.h"
  7. #include <zip.h>
  8. #include "czip.h"
  9. #include "mainfrm.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16.             ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17.             // CUnZip dialog box
  18.             
  19.             
  20.             CUnZip::CUnZip(CWnd* pParent /*=NULL*/)
  21.                 : CDialog(CUnZip::IDD, pParent)
  22.             {
  23.                 //{{AFX_DATA_INIT(CUnZip)
  24.                     // NOTE: the ClassWizard will add member initialization here
  25.                 //}}AFX_DATA_INIT
  26.             }
  27.             
  28.             void CUnZip::DoDataExchange(CDataExchange* pDX)
  29.             {
  30.                 CDialog::DoDataExchange(pDX);
  31.                 //{{AFX_DATA_MAP(CUnZip)
  32.                     // NOTE: the ClassWizard will add DDX and DDV calls here
  33.                 //}}AFX_DATA_MAP
  34.             }
  35.             
  36.             BEGIN_MESSAGE_MAP(CUnZip, CDialog)
  37.                 //{{AFX_MSG_MAP(CUnZip)
  38.                 ON_BN_CLICKED(IDCOMMENT, OnComment)
  39.                 ON_EN_CHANGE(IDC_EDITFILENAME, OnChangeEditfilename)
  40.                 ON_BN_CLICKED(IDVIEW, OnView)
  41.                 //}}AFX_MSG_MAP
  42.             END_MESSAGE_MAP()
  43.             
  44.             
  45.             //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46.             // CUnZip message handlers
  47.             
  48.                         
  49.                         
  50.                         
  51.                         /////////////////////////////////////////////////////////////////////////////////
  52.                         //    WM_INITDIALOG
  53.                         BOOL CUnZip::OnInitDialog()
  54.                             {
  55.                             CString CurrentPath;
  56.                             
  57.                             CDialog::OnInitDialog();
  58.                             if ( CurrentZipFile == "" )    // a zip file is compulsory
  59.                                 {
  60.                                 MessageBox( "Please select a zip file!", "Zip Studio", MB_OK | MB_ICONEXCLAMATION );
  61.                                 PostMessage( WM_CLOSE );
  62.                                 return TRUE;
  63.                                 }
  64.                             // Also, this zip file must exist and be actually ZIP compatable!
  65.                             if ( !IsThisFileAZipFile( CurrentZipFile ))
  66.                                 {
  67.                                 MessageBox( "When you choose to unzip a file\nyou must specify a valid zip file before!", "Zip Studio", MB_OK | MB_ICONEXCLAMATION );
  68.                                 PostMessage( WM_CLOSE );
  69.                                 return TRUE;
  70.                                 }
  71.                             // we just set the default values
  72.                             CheckDlgButton( IDC_CHECKPATH, 1 );
  73.                             CheckRadioButton( IDC_RADIOALWAYS, IDC_RADIOPROMPT, IDC_RADIOALWAYS );
  74.                             SetDlgItemText( IDC_EDITFILENAME, "*.*");
  75.                             SendDlgItemMessage( IDC_EDITFILENAME , EM_LIMITTEXT, 178 );
  76.                             // Activate or not the COMMENT button
  77.                             if (  GetZipCommentLength( CurrentZipFile) <2 )
  78.                                 GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
  79.                             GetDlgItem( IDC_EDITFILENAME)->SetFocus( );                                                
  80.                             GetDlgItem( IDC_EDITFILENAME)->SendMessage( EM_SETSEL, TRUE, MAKELONG( 0, -1L ));
  81.                             return FALSE;  // return TRUE  unless you set the focus to a control
  82.                             }
  83.                         
  84.                         
  85.                         /////////////////////////////////////////////////////////////////////////////////
  86.                         //    WM_COMMAND ( IDOK )
  87.                         void CUnZip::OnOK()
  88.                             {
  89.                             // we simply call the unzip main function
  90.                             CString Mask, FileName;       
  91.                             int Overwrite, KeepPath;
  92.                             GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ), 178);
  93.                             FileName.ReleaseBuffer();
  94.                             if ( FileName.GetLength() == 0 )
  95.                                 {
  96.                                 MessageBeep( 0 );
  97.                                 return;
  98.                                 }
  99.                             if ( IsDlgButtonChecked( IDC_RADIOPROMPT) )
  100.                                 Overwrite = OVERWRITE_QUERY;
  101.                             else if ( IsDlgButtonChecked( IDC_RADIONEVER) )
  102.                                 Overwrite = OVERWRITE_FALSE;
  103.                             else
  104.                                 Overwrite = OVERWRITE_TRUE;                                                                                                    
  105.                             KeepPath = IsDlgButtonChecked( IDC_CHECKPATH)?1:0;
  106.                             // set the values and Launch the zip process
  107.                             ((CMainFrame*)AfxGetMainWnd())->sMask = FileName;
  108.                             ((CMainFrame*)AfxGetMainWnd())->iOverwrite = Overwrite;
  109.                             ((CMainFrame*)AfxGetMainWnd())->bPath = KeepPath;
  110.                             ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_UNZIP );
  111.                             CDialog::OnOK();
  112.                             }
  113.                         
  114.                         
  115.                         
  116.                         /////////////////////////////////////////////////////////////////////////////////
  117.                         //    WM_COMMAND ( IDCOMMENT )
  118.                         void CUnZip::OnComment()
  119.                             {
  120.                             UINT iBufferSize;
  121.                             CString TheComment;
  122.                             
  123.                             if ( ( iBufferSize = GetZipCommentLength( CurrentZipFile)) <2 )
  124.                                 {
  125.                                 GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
  126.                                 return;                                                                             
  127.                                 }
  128.                             if ( iBufferSize > 32000 )
  129.                                 {
  130.                                 MessageBox( "Comment too long!\nWith this demo, comment longer than 32000 bytes\nwill not be displayed.","Zip Studio", MB_OK | MB_ICONEXCLAMATION );
  131.                                 GetDlgItem( IDCOMMENT)->EnableWindow( FALSE );
  132.                                 return;
  133.                                 }
  134.                             GetZipComment( CurrentZipFile, TheComment.GetBuffer( iBufferSize ));
  135.                             TheComment.ReleaseBuffer();
  136.                             MessageBox( TheComment, CurrentZipFile );
  137.                             }
  138.                         
  139.                         
  140.                         /////////////////////////////////////////////////////////////////////////////////
  141.                         //    WM_COMMAND ( EN_CHANGE, IDC_EDITFILENAME )
  142.                         void CUnZip::OnChangeEditfilename()
  143.                             {
  144.                             // Disable the OK button if no filename
  145.                             CString Temp;
  146.                             GetDlgItemText( IDC_EDITFILENAME, Temp.GetBuffer(160), 158 );
  147.                             Temp.ReleaseBuffer();
  148.                             if ( Temp.GetLength() == 0 )
  149.                                 GetDlgItem( IDOK )->EnableWindow( FALSE );
  150.                             else
  151.                                 GetDlgItem( IDOK )->EnableWindow( TRUE );    
  152.                             }
  153.             
  154.             
  155.             
  156.                             /////////////////////////////////////////////////////////////////////////////////
  157.                             //    WM_COMMAND ( IDVIEW )
  158.                             void CUnZip::OnView()
  159.                                 {
  160.                                 // Send PM_VIEW to activate the View process from MainFrame...
  161.                                 CString Mask, FileName;       
  162.                                 GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ), 178);
  163.                                 FileName.ReleaseBuffer();
  164.                                 if ( FileName.GetLength() == 0 )
  165.                                     {
  166.                                     MessageBeep( 0 );
  167.                                     return;
  168.                                     }
  169.                                 // set the values and Launch the view process
  170.                                 ((CMainFrame*)AfxGetMainWnd())->sMask = FileName;
  171.                                 ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_VIEW );
  172.                                 CDialog::OnOK();
  173.                                 }
  174.