home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- File: Tools.cpp
- Description: Zip Manager sample application using The Xceed Zip Compression
- Library 4
- Copyright (c) 1995-1999 Xceed Software Inc.
- *******************************************************************************/
-
- #include <vcl\vcl.h>
- // For Directory Browser
- #include <shlobj.h>
- #include <objbase.h>
- // ---------------------
- #pragma hdrstop
-
- #include "XceedZipLib_OCX.h"
- #include "Tools.h"
-
- //
- // The ParseTab function extracts a field from a string containing tab-separated
- // fields. For example, this function can extract the third item in a string that
- // was assigned the value of an item in a multi-column listbox, since items in
- // each column of a listbox are separated by tabs. Pass the column number in the
- // FieldIndex parameter. The variable passed in the FieldIndex parameter will be
- // incremented. The return value of ParseTab is the extracted string.
- //
- void ParseTab(AnsiString Str, int &FieldIndex, AnsiString &ReturnValue)
- {
- int i;
-
- ReturnValue = "";
-
- if ((FieldIndex > 0) && (FieldIndex <= Str.Length()))
- {
- for(i=FieldIndex; i <= Str.Length(); i++)
- if ((i <= Str.Length()) && (Str[i] == '\t'))
- break;
-
- if (i <= Str.Length())
- {
- ReturnValue = Str.SubString(FieldIndex, i - FieldIndex);
- FieldIndex = i + 1;
- }
- else
- {
- ReturnValue = Str.SubString(FieldIndex, Str.Length()-FieldIndex);
- FieldIndex = 0;
- }
- }
- else
- FieldIndex = 0;
- }
-
- //
- // The AssignFromLb procedure takes all the entries in the first column of a
- // listbox and places them in a TStringList. In this demo, AssignFromLb is used
- // to take all the path and filenames and place them in a TStringList. When the
- // demo is running, it may look as if only filenames appear in the first column,
- // and the pathnames are in column 7, but that is only on screen. In reality,
- // the data in column 1 contains paths and filenames.
- //
- void AssignFromLb(TListBox *SourceLb, TXceedZip *pZip)
- {
- int i, C;
- AnsiString Value;
-
- pZip->FilesToProcess = "";
-
- if (SourceLb->SelCount > 0)
- {
- for (i = 0; i < SourceLb->Items->Count; i++)
- {
- if (SourceLb->Selected[i])
- {
- C = 1;
- ParseTab(SourceLb->Items->Strings[i], C, Value);
- pZip->AddFilesToProcess( WideString( Value ) );
- }
- }
- }
- }
-
- //
- // The HandleError function is a sample error handling routine for the purposes
- // of this demo, but can be used in your own programs as well. When an error
- // occurs, it displays a message box indicating the nature of the error. If a
- // warning occurs, an information message box will be shown. The function also
- // returns a result of 0 if ErrorCode was 0, 1 if a warning occured, or 2 if an
- // error occured.
- //
- int HandleError(xcdError ErrorCode, AnsiString DoingWhat, TXceedZip* pZip)
- {
- BSTR bstrMessage = NULL;
- int ErrorType = 2;
-
- switch (ErrorCode)
- {
- case xerWarnings:
- case xerFilesSkipped:
- case xerProcessStarted:
- ErrorType = 1;
- break;
-
- case xerSuccess:
- ErrorType = 0;
- break;
-
- default:
- bstrMessage = pZip->GetErrorDescription( xvtError, ErrorCode );
- break;
- }
-
- if( bstrMessage )
- {
- Application->MessageBox( AnsiString( bstrMessage ).c_str(), DoingWhat.c_str(), MB_OK + MB_ICONERROR );
- SysFreeString( bstrMessage );
- }
-
- return ErrorType;
- }
-
- //
- // This function displays a dialog box prompting the user to select a
- // directory. If the user cancels, the directory path will be blank.
- // This directory browser is not available under Windows NT3.51 or previous
- //
- bool SelectDirectory(char * pszDir, HWND hParent)
- {
- BROWSEINFO bi;
- LPITEMIDLIST pidlBrowse;
-
- // Fill in the BROWSEINFO structure.
- bi.hwndOwner = hParent;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = pszDir;
- bi.lpszTitle = "Select the destination directory";
- bi.ulFlags = BIF_RETURNONLYFSDIRS;
- bi.lpfn = NULL;
- bi.lParam = 0;
- bi.iImage = 0;
-
- // Browse for a folder and return its PIDL.
- pidlBrowse = SHBrowseForFolder(&bi);
-
- if (pidlBrowse == NULL)
- return false;
-
- bool bResult = (SHGetPathFromIDList(pidlBrowse, pszDir) != 0);
-
- CoTaskMemFree(pidlBrowse);
-
- return bResult;
- }
-
-