00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00021 #if !defined(ZIPARCHIVE_ZIPSPLITNAMESHANDLER_DOT_H)
00022 #define ZIPARCHIVE_ZIPSPLITNAMESHANDLER_DOT_H
00023
00024 #if _MSC_VER > 1000
00025 #pragma once
00026 #pragma warning( push )
00027 #pragma warning (disable : 4100) // unreferenced formal parameter
00028 #endif
00029
00030 #include "_features.h"
00031 #include "ZipString.h"
00032 #include "ZipPathComponent.h"
00033 #include "BitFlag.h"
00034
00035
00042 class ZIP_API CZipSplitNamesHandler
00043 {
00044
00045 public:
00049 enum Flags
00050 {
00051 flNone = 0x00,
00052 flLast = 0x01,
00053 flExisting = 0x02
00054 };
00055
00059 CZipSplitNamesHandler()
00060 {
00061
00062 }
00063
00070 virtual void Initialize(const CZipString& szArchiveName)
00071 {
00072
00073 }
00074
00087 virtual CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const = 0;
00088
00102 virtual ZIP_VOLUME_TYPE GetVolumeNumber(const CZipString& szVolumePath) const
00103 {
00104
00105 return 0;
00106 }
00107
00108 virtual ~CZipSplitNamesHandler()
00109 {
00110 }
00111 };
00112
00113
00120 class ZIP_API CZipRegularSplitNamesHandler : public CZipSplitNamesHandler
00121 {
00122 protected:
00123 CZipString m_szExt;
00124 public:
00125 CZipRegularSplitNamesHandler()
00126 :m_szExt(_T("zip"))
00127 {
00128 }
00129
00130 void Initialize(const CZipString& szArchiveName)
00131 {
00132 CZipPathComponent zpc(szArchiveName);
00133 m_szExt = zpc.GetFileExt();
00134 }
00135
00136 CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const
00137 {
00138 CZipString szExt;
00139 if (flags.IsSetAny(CZipSplitNamesHandler::flLast))
00140 szExt = m_szExt;
00141 else
00142 {
00143 if (uCurrentVolume < 100)
00144 szExt.Format(_T("z%.2u"), uCurrentVolume);
00145 else
00146 szExt.Format(_T("z%u"), uCurrentVolume);
00147 }
00148 CZipPathComponent zpc(szArchiveName);
00149 zpc.SetExtension(szExt);
00150 return zpc.GetFullPath();
00151 }
00152 };
00153
00160 class ZIP_API CZipBinSplitNamesHandler : public CZipSplitNamesHandler
00161 {
00162 public:
00163 CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const
00164 {
00165 CZipString szExt;
00166 if (uCurrentVolume < 1000)
00167 szExt.Format(_T("%.3u"), uCurrentVolume);
00168 else
00169 szExt.Format(_T("%u"), uCurrentVolume);
00170 if (flags.IsSetAny(CZipSplitNamesHandler::flExisting))
00171 {
00172 CZipPathComponent zpc(szArchiveName);
00173 zpc.SetExtension(szExt);
00174 return zpc.GetFullPath();
00175 }
00176 else
00177 {
00178 return szArchiveName + _T(".") + szExt;
00179 }
00180 }
00181
00182 ZIP_VOLUME_TYPE GetVolumeNumber(const CZipString& szArchiveName) const
00183 {
00184 CZipPathComponent zpc(szArchiveName);
00185 CZipString szExt = zpc.GetFileExt();
00186 szExt.MakeLower();
00187 if (szExt.GetLength() < 3)
00188 return 0;
00189 __int64 ret;
00190 #if !defined __GNUC__ || defined __MINGW32__
00191 ret = _ttoi64((LPCTSTR)szExt);
00192 #else
00193 errno = 0;
00194 ret = (__int64)strtoll((LPCTSTR)szExt, NULL, 10);
00195 if (errno != 0)
00196 return 0;
00197 #endif
00198 return (ZIP_VOLUME_TYPE)((ret <= 0 || ret > UINT_MAX) ? 0 : ret);
00199 }
00200 };
00201
00202 #if _MSC_VER > 1000
00203 #pragma warning( pop )
00204 #endif
00205
00206 #endif