ZipSplitNamesHandler.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive Library Open Source distribution
3 // and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: https://www.artpol-software.com
14 
21 #if !defined(ZIPARCHIVE_ZIPSPLITNAMESHANDLER_DOT_H)
22 #define ZIPARCHIVE_ZIPSPLITNAMESHANDLER_DOT_H
23 
24 #if _MSC_VER > 1000
25  #pragma once
26  #pragma warning( push )
27  #pragma warning (disable : 4100) // unreferenced formal parameter
28 #endif
29 
30 #include "_features.h"
31 #include "ZipString.h"
32 #include "ZipPathComponent.h"
33 #include "BitFlag.h"
34 
35 
42 class ZIP_API CZipSplitNamesHandler
43 {
44 
45 public:
49  enum Flags
50  {
51  flNone = 0x00,
52  flLast = 0x01,
53  flExisting = 0x02
54  };
55 
60  {
61 
62  }
63 
70  virtual void Initialize(const CZipString& szArchiveName)
71  {
72 
73  }
74 
87  virtual CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const = 0;
88 
102  virtual ZIP_VOLUME_TYPE GetVolumeNumber(const CZipString& szVolumePath) const
103  {
104  // unspecified
105  return 0;
106  }
107 
108  virtual ~CZipSplitNamesHandler()
109  {
110  }
111 };
112 
113 
121 {
122 protected:
123  CZipString m_szExt;
124 public:
126  :m_szExt(_T("zip"))
127  {
128  }
129 
130  void Initialize(const CZipString& szArchiveName)
131  {
132  CZipPathComponent zpc(szArchiveName);
133  m_szExt = zpc.GetFileExt();
134  }
135 
136  CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const
137  {
138  CZipString szExt;
140  szExt = m_szExt;
141  else
142  {
143  if (uCurrentVolume < 100)
144  szExt.Format(_T("z%.2u"), uCurrentVolume);
145  else
146  szExt.Format(_T("z%u"), uCurrentVolume);
147  }
148  CZipPathComponent zpc(szArchiveName);
149  zpc.SetExtension(szExt);
150  return zpc.GetFullPath();
151  }
152 };
153 
161 {
162 public:
163  CZipString GetVolumeName(const CZipString& szArchiveName, ZIP_VOLUME_TYPE uCurrentVolume, ZipArchiveLib::CBitFlag flags) const
164  {
165  CZipString szExt;
166  if (uCurrentVolume < 1000)
167  szExt.Format(_T("%.3u"), uCurrentVolume);
168  else
169  szExt.Format(_T("%u"), uCurrentVolume);
171  {
172  CZipPathComponent zpc(szArchiveName);
173  zpc.SetExtension(szExt);
174  return zpc.GetFullPath();
175  }
176  else
177  {
178  return szArchiveName + _T(".") + szExt;
179  }
180  }
181 
182  ZIP_VOLUME_TYPE GetVolumeNumber(const CZipString& szArchiveName) const
183  {
184  CZipPathComponent zpc(szArchiveName);
185  CZipString szExt = zpc.GetFileExt();
186  szExt.MakeLower();
187  if (szExt.GetLength() < 3)
188  return 0;
189  __int64 ret;
190 #if !defined __GNUC__ || defined __MINGW32__
191  ret = _ttoi64((LPCTSTR)szExt);
192 #else
193  errno = 0;
194 #ifdef _UNICODE
195  ret = (__int64)wcstoll((LPCTSTR)szExt, NULL, 10);
196 #else
197  ret = (__int64)strtoll((LPCTSTR)szExt, NULL, 10);
198 #endif
199  if (errno != 0)
200  return 0;
201 #endif
202  return (ZIP_VOLUME_TYPE)((ret <= 0 || ret > UINT_MAX) ? 0 : ret);
203  }
204 };
205 
206 #if _MSC_VER > 1000
207  #pragma warning( pop )
208 #endif
209 
210 #endif

The ZipArchive Library Copyright © 2000 - 2022 Artpol Software - Tadeusz Dracz. Generated at Sat Dec 17 2022 19:57:04.