Files
harbour-core/harbour/contrib/hbziparch/ZipException.cpp
Viktor Szakats 40338a87d6 2008-06-24 00:35 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* contrib/hbziparch/_features.h
   * contrib/hbziparch/_platform.h
   * contrib/hbziparch/Aes.cpp
   * contrib/hbziparch/Aes.h
   * contrib/hbziparch/BaseLibCompressor.cpp
   * contrib/hbziparch/BaseLibCompressor.h
   * contrib/hbziparch/BytesWriter.h
   * contrib/hbziparch/Bzip2Compressor.cpp
   * contrib/hbziparch/Bzip2Compressor.h
   * contrib/hbziparch/DeflateCompressor.cpp
   * contrib/hbziparch/DeflateCompressor.h
   * contrib/hbziparch/DirEnumerator.cpp
   * contrib/hbziparch/DirEnumerator.h
   * contrib/hbziparch/FileFilter.cpp
   * contrib/hbziparch/FileFilter.h
   * contrib/hbziparch/FileInfo.h
   * contrib/hbziparch/Hmac.cpp
   * contrib/hbziparch/Hmac.h
   * contrib/hbziparch/RandomPool.cpp
   * contrib/hbziparch/RandomPool.h
   * contrib/hbziparch/Sha1.cpp
   * contrib/hbziparch/Sha1.h
   * contrib/hbziparch/std_mfc.h
   * contrib/hbziparch/std_stl.h
   * contrib/hbziparch/Wildcard.cpp
   * contrib/hbziparch/Wildcard.h
   * contrib/hbziparch/ZipAbstractFile.h
   * contrib/hbziparch/ZipAesCryptograph.cpp
   * contrib/hbziparch/ZipAesCryptograph.h
   * contrib/hbziparch/ZipArchive.cpp
   * contrib/hbziparch/ZipArchive.h
   * contrib/hbziparch/ZipAutoBuffer.cpp
   * contrib/hbziparch/ZipAutoBuffer.h
   * contrib/hbziparch/ZipBaseException.h
   * contrib/hbziparch/ZipCallback.h
   * contrib/hbziparch/ZipCallbackProvider.h
   * contrib/hbziparch/ZipCentralDir.cpp
   * contrib/hbziparch/ZipCentralDir.h
   * contrib/hbziparch/ZipCollections.h
   * contrib/hbziparch/ZipCollections_mfc.h
   * contrib/hbziparch/ZipCollections_stl.h
   * contrib/hbziparch/ZipCompatibility.cpp
   * contrib/hbziparch/ZipCompatibility.h
   * contrib/hbziparch/ZipCompressor.cpp
   * contrib/hbziparch/ZipCompressor.h
   * contrib/hbziparch/ZipCrc32Cryptograph.cpp
   * contrib/hbziparch/ZipCrc32Cryptograph.h
   * contrib/hbziparch/ZipCryptograph.cpp
   * contrib/hbziparch/ZipCryptograph.h
   * contrib/hbziparch/ZipException.cpp
   * contrib/hbziparch/ZipException.h
   * contrib/hbziparch/ZipExtraData.cpp
   * contrib/hbziparch/ZipExtraData.h
   * contrib/hbziparch/ZipExtraField.cpp
   * contrib/hbziparch/ZipExtraField.h
   * contrib/hbziparch/ZipFile.h
   * contrib/hbziparch/ZipFile_mfc.cpp
   * contrib/hbziparch/ZipFile_mfc.h
   * contrib/hbziparch/ZipFile_stl.cpp
   * contrib/hbziparch/ZipFile_stl.h
   * contrib/hbziparch/ZipFileHeader.cpp
   * contrib/hbziparch/ZipFileHeader.h
   * contrib/hbziparch/ZipFileMapping.h
   * contrib/hbziparch/ZipFileMapping_lnx.h
   * contrib/hbziparch/ZipFileMapping_win.h
   * contrib/hbziparch/ZipMemFile.cpp
   * contrib/hbziparch/ZipMemFile.h
   * contrib/hbziparch/ZipMutex.h
   * contrib/hbziparch/ZipMutex_lnx.h
   * contrib/hbziparch/ZipMutex_win.h
   * contrib/hbziparch/ZipPathComponent.h
   * contrib/hbziparch/ZipPlatform.h
   * contrib/hbziparch/ZipPlatformComm.cpp
   * contrib/hbziparch/ZipStorage.cpp
   * contrib/hbziparch/ZipStorage.h
   * contrib/hbziparch/ZipString.h
   * contrib/hbziparch/ZipString_mfc.h
   * contrib/hbziparch/ZipString_stl.h
   * contrib/hbziparch/ZipStringStoreSettings.h
     + ZipArchive lib update finished.
     ; Pass 2/2
     ; Please test.
2008-06-23 22:41:33 +00:00

280 lines
7.0 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ZipException.h"
#include "zlib/zlib.h"
#include <errno.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#if defined _MFC_VER && defined ZIP_ARCHIVE_MFC
IMPLEMENT_DYNAMIC( CZipException, CException)
#endif
CZipException::CZipException(int iCause, LPCTSTR lpszZipName)
#ifdef _MFC_VER
:CException(TRUE)
#endif
{
m_iCause = iCause;
if (lpszZipName)
m_szFileName = lpszZipName;
}
CZipException::~CZipException() throw()
{
}
// inline void CZipException::Throw(int iZipError, LPCTSTR lpszZipName)
// {
// #ifdef _MFC_VER
// throw new CZipException(iZipError, lpszZipName);
// #else
// CZipException e(iZipError, lpszZipName);
// throw e;
// #endif
// MSVC++: ignore "Unreachable code" warning here, it's due to
// optimizations
// }
#ifdef ZIP_ENABLE_ERROR_DESCRIPTION
ZBOOL CZipException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
UINT* )
{
if (!lpszError || !nMaxError)
return FALSE;
CZipString sz = GetErrorDescription();
if (sz.IsEmpty())
return FALSE;
UINT iLen = sz.GetLength();
if (nMaxError - 1 < iLen)
iLen = nMaxError - 1;
LPTSTR lpsz = sz.GetBuffer(iLen);
#if _MSC_VER >= 1400
#ifdef _UNICODE
wcsncpy_s(lpszError, nMaxError, lpsz, iLen);
#else
strncpy_s(lpszError, nMaxError, lpsz, iLen);
#endif
#else
#ifdef _UNICODE
wcsncpy(lpszError, lpsz, iLen);
#else
strncpy(lpszError, lpsz, iLen);
#endif
#endif
lpszError[iLen] = _T('\0');
return TRUE;
}
CZipString CZipException::GetErrorDescription()
{
return GetInternalErrorDescription(m_iCause);
}
CZipString CZipException::GetSystemErrorDescription()
{
#ifdef WIN32
DWORD x = GetLastError();
if (x)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, x, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
CZipString sz = (LPCTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
return sz;
}
#endif
return GetInternalErrorDescription(errno == 0 ? genericError : errno, true);
}
CZipString CZipException::GetInternalErrorDescription(int iCause, bool bNoLoop)
{
CZipString sz;
switch (iCause)
{
case EROFS:
sz = _T("Read-only file system.");
break;
case ESPIPE:
sz = _T("Illegal seek.");
break;
case ENOSPC:
sz = _T("No space left on device.");
break;
case EFBIG:
sz = _T("File too large.");
break;
case EMFILE:
sz = _T("Too many open files.");
break;
case ENFILE:
sz = _T("File table overflow.");
break;
case EINVAL:
sz = _T("Invalid argument.");
break;
case EISDIR:
sz = _T("Is a directory.");
break;
case ENOTDIR:
sz = _T("Not a directory.");
break;
case ENODEV:
sz = _T("No such device.");
break;
case EXDEV:
sz = _T("Cross-device link.");
break;
case EEXIST:
sz = _T("File exists.");
break;
case EFAULT:
sz = _T("Bad address.");
break;
case EACCES:
sz = _T("Permission denied.");
break;
case ENOMEM:
sz = _T("Not enough space.");
break;
case EBADF:
sz = _T("Bad file number.");
break;
case ENXIO:
sz = _T("No such device or address.");
break;
case EIO:
sz = _T("I/O error.");
break;
case EINTR:
sz = _T("Interrupted system call.");
break;
case ENOENT:
sz = _T("No such file or directory.");
break;
case EPERM:
sz = _T("Not super-user.");
break;
case badZipFile:
sz = _T("Damaged or not a zip file.");
break;
case badCrc:
sz = _T("Crc is mismatched.");
break;
case noCallback:
sz = _T("There is no spanned archive callback object set.");
break;
case aborted:
sz = _T("Volume change aborted in a segmented archive.");
break;
case abortedAction:
sz = _T("Action aborted.");
break;
case abortedSafely:
sz = _T("Action aborted safely.");
break;
case nonRemovable:
sz = _T("The device selected for the spanned archive is not removable.");
break;
case tooManyVolumes:
sz = _T("The limit of the maximum volumes reached.");
break;
case tooManyFiles:
sz = _T("The limit of the maximum files in an archive reached.");
break;
case tooLongData:
sz = _T("The filename, the comment or the local or central extra field of the file added to the archive is too long.");
break;
case tooBigSize:
sz = _T("The file size is too large to be supported.");
break;
case badPassword:
sz = _T("An incorrect password set for the file being decrypted.");
break;
case dirWithSize:
sz = _T("The directory with a non-zero size found while testing.");
break;
case internalError:
sz = _T("An internal error.");
break;
case notRemoved:
sz.Format(_T("%s (%s)."), _T("Error while removing a file"), (LPCTSTR)GetSystemErrorDescription());
break;
case notRenamed:
sz.Format(_T("%s (%s)."), _T("Error while renaming a file"), (LPCTSTR)GetSystemErrorDescription());
break;
case platfNotSupp:
sz = _T("Cannot create a file for the specified platform.");
break;
case cdirNotFound:
sz = _T("The central directory was not found in the archive (or you were trying to open not the last volume of a segmented archive).");
break;
case noZip64:
sz = _T("The Zip64 format has not been enabled for the library, but is required to use the archive.");
break;
case noAES:
sz = _T("WinZip AES encryption has not been enabled for the library, but is required to decompress the archive.");
break;
#ifdef ZIP_ARCHIVE_STL
case outOfBounds:
sz = _T("The collection is empty and the bounds do not exist.");
break;
#endif
#ifdef ZIP_ARCHIVE_USE_LOCKING
case mutexError:
sz = _T("Locking or unlocking resources access was unsuccessful.");
break;
#endif
case streamEnd:
sz = _T("Zlib library error (end of stream).");
break;
case errNo:
sz = GetInternalErrorDescription(errno != errNo ? errno : genericError);
break;
case streamError:
sz = _T("Zlib library error (stream error).");
break;
case dataError:
sz = _T("Zlib library error (data error).");
break;
case memError:
sz = _T("Not enough memory.");
break;
case bufError:
sz = _T("Zlib library error (buffer error).");
break;
case versionError:
sz = _T("Zlib library error (version error).");
break;
default:
sz = bNoLoop ? _T("Unknown error") :(LPCTSTR) GetSystemErrorDescription();
}
return sz;
}
#endif //ZIP_ENABLE_ERROR_DESCRIPTION