home *** CD-ROM | disk | FTP | other *** search
- // czip.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "zdemo.h"
- #include "czip.h"
- #include <zip.h>
- #include "mainfrm.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // CCzip dialog box
-
-
- CCzip::CCzip(CWnd* pParent /*=NULL*/)
- : CDialog(CCzip::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCzip)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- void CCzip::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCzip)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CCzip, CDialog)
- //{{AFX_MSG_MAP(CCzip)
- ON_EN_CHANGE(IDC_EDITFILENAME, OnChangeEditfilename)
- ON_EN_CHANGE(IDC_EDITFILEPATH, OnChangeEditfilepath)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // CCzip message handlers
-
- ////////////////////////////////////////////////////////
- // WM_INITDIALOG
- BOOL CCzip::OnInitDialog()
- {
- CString CurrentPath, Temp;
- CDialog::OnInitDialog();
- if ( CurrentZipFile == "" ) // a zip file is compulsory
- {
- MessageBox( "Please select a zip file!" );
- PostMessage( WM_CLOSE );
- return TRUE;
- }
- // we just set the default values
- CheckDlgButton( IDC_CHECKPATH, 1 );
- CheckRadioButton( IDC_RADIOALWAYS, IDC_RADIOUPDATE, IDC_RADIOALWAYS );
- CurrentPath = GetPathFromFileName( CurrentZipFile );
- Temp = CurrentPath;
- Temp = Temp.Right(1);
- if ( Temp != "\\" )
- CurrentPath += "\\";
- SetDlgItemText( IDC_EDITFILEPATH, CurrentPath );
- SetDlgItemText( IDC_EDITFILENAME, "*.*");
- SendDlgItemMessage( IDC_EDITFILENAME , EM_LIMITTEXT, 178 );
- SendDlgItemMessage( IDC_EDITFILEPATH , EM_LIMITTEXT, 178 );
- GetDlgItem( IDC_EDITFILENAME)->SetFocus( );
- GetDlgItem( IDC_EDITFILENAME)->SendMessage( EM_SETSEL, TRUE, MAKELONG( 0, -1L ));
- return FALSE; // return TRUE unless you set the focus to a control
- }
-
-
- ////////////////////////////////////////////////////////
- // WM_COMMAND ( IDOK )
- void CCzip::OnOK()
- {
- CString Mask, FileName, Path;
- int Overwrite;
- BOOL Recurse, KeepPath;
-
- GetDlgItemText( IDC_EDITFILENAME, FileName.GetBuffer( 180 ),178);
- FileName.ReleaseBuffer();
- // we simply call the zip main function
- GetDlgItemText( IDC_EDITFILEPATH, Path.GetBuffer( 180 ),178);
- Path.ReleaseBuffer();
- if (( FileName.GetLength() == 0 ) || ( Path.GetLength() == 0 ))
- {
- MessageBeep( 0 );
- GetDlgItem( IDOK )->EnableWindow( FALSE );
- return;
- }
- if ( (FileName.GetLength() + Path.GetLength() ) > 180 )
- {
- MessageBox( "Path plus filter must not be longer than 180 characters!","Zip Studio", MB_OK | MB_ICONEXCLAMATION );
- GetDlgItem( IDOK )->EnableWindow( FALSE );
- return;
- }
- if ( Path.Right(1) != "\\" )
- Path += "\\";
- Mask = Path + FileName;
- if ( IsDlgButtonChecked( IDC_RADIOUPDATE) )
- Overwrite = OVERWRITE_UPDATE;
- else if ( IsDlgButtonChecked( IDC_RADIOPROMPT) )
- Overwrite = OVERWRITE_PROMPT;
- else if ( IsDlgButtonChecked( IDC_RADIONEVER) )
- Overwrite = OVERWRITE_NEVER;
- else
- Overwrite = OVERWRITE_ALWAYS;
-
- Recurse = IsDlgButtonChecked( IDC_CHECKRECURSE)?1:0;
- KeepPath = IsDlgButtonChecked( IDC_CHECKPATH)?1:0;
- // we give correct values to mainframe
- ((CMainFrame*)AfxGetMainWnd())->sMask = Mask;
- ((CMainFrame*)AfxGetMainWnd())->iOverwrite = Overwrite;
- ((CMainFrame*)AfxGetMainWnd())->bRecurse = Recurse;
- ((CMainFrame*)AfxGetMainWnd())->bPath = KeepPath;
-
- // Launch the zip process
- ((CMainFrame*)AfxGetMainWnd())->PostMessage( PM_ZIP );
- CDialog::OnOK();
- }
-
-
- ////////////////////////////////////////////////////////
- // WM_COMMAND ( EN_CHANGE , IDC_EDITFILENAME )
- void CCzip::OnChangeEditfilename()
- {
- // Disable the OK button if no filename
- CString Temp;
- GetDlgItemText( IDC_EDITFILENAME, Temp.GetBuffer(160), 158 );
- Temp.ReleaseBuffer();
- if ( Temp.GetLength() == 0 )
- GetDlgItem( IDOK )->EnableWindow( FALSE );
- else
- GetDlgItem( IDOK )->EnableWindow( TRUE );
- }
-
-
- ////////////////////////////////////////////////////////
- // WM_COMMAND ( EN_CHANGE, IDC_EDITFILEPATH )
- void CCzip::OnChangeEditfilepath()
- {
- // Disable the OK button if no path
- CString Temp;
- GetDlgItemText( IDC_EDITFILEPATH, Temp.GetBuffer(160), 158 );
- Temp.ReleaseBuffer();
- if ( Temp.GetLength() == 0 )
- GetDlgItem( IDOK )->EnableWindow( FALSE );
- else
- GetDlgItem( IDOK )->EnableWindow( TRUE );
-
- }
-