ZipPathComponent.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 
20 #if !defined(ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H)
21 #define ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H
22 
23 #if _MSC_VER > 1000
24  #pragma once
25  #if defined ZIP_HAS_DLL
26  #pragma warning (push)
27  #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
28  #endif
29 #endif
30 
31 #include "ZipString.h"
32 #include "ZipExport.h"
33 
37 class ZIP_API CZipPathComponent
38 {
39 
40 public:
41 #ifdef _ZIP_SYSTEM_WIN
42  static const CZipString PathPrefix;
47  {
48  ptNone = 0,
49  ptUnc = 2,
50  ptUnicode = 4,
51  ptUncWin = 8
52  };
62  static int IsPrefixed(const CZipString& path);
63 
76  static CZipString AddPrefix(LPCTSTR path, bool isFolder = true);
77 
87  static void AddPrefix(CZipString& path, bool isFolder = true);
88 
89 #endif
100  CZipPathComponent(LPCTSTR lpszFullPath)
101  {
102  SetFullPath(lpszFullPath);
103  }
104 
105  virtual ~CZipPathComponent();
106 
107  static const TCHAR m_cSeparator;
108 
115  static void AppendSeparator(CZipString& szPath)
116  {
117  RemoveSeparators(szPath);
118  szPath += m_cSeparator;
119  }
120 
130  static void Combine(CZipString& szPath, LPCTSTR lpszName)
131  {
132  AppendSeparator(szPath);
133  if (lpszName != NULL)
134  szPath += lpszName;
135  }
136 
143  static void RemoveSeparators(CZipString& szPath)
144  {
145  szPath.TrimRight(_T("\\/"));
146  }
147 
154  static void RemoveSeparatorsLeft(CZipString& szPath)
155  {
156  szPath.TrimLeft(_T("\\/"));
157  }
158 
159 
169  static bool IsSeparator(TCHAR c)
170  {
171  return c == _T('\\') || c == _T('/');
172  }
173 
183  static bool HasEndingSeparator(const CZipString& szPath)
184  {
185  int iLen = szPath.GetLength();
186  if (iLen)
187  return IsSeparator(szPath[iLen - 1]);
188  else
189  return false;
190  }
191 
199  void SetFullPath(LPCTSTR lpszFullPath);
200 
207  CZipString GetFileTitle() const { return m_szFileTitle;}
208 
215  void SetFileTitle(LPCTSTR lpszFileTitle) { m_szFileTitle = lpszFileTitle;}
216 
217 
224  void SetExtension(LPCTSTR lpszExt)
225  {
226  m_szFileExt = lpszExt;
227  m_szFileExt.TrimLeft(_T('.'));
228  }
229 
236  CZipString GetFileExt() const { return m_szFileExt;}
237 
244  CZipString GetFileDrive() const { return m_szDrive;}
245 
252  CZipString GetNoDrive() const ;
253 
260  CZipString GetFileName() const
261  {
262  CZipString szFullFileName = m_szFileTitle;
263  if (!m_szFileExt.IsEmpty())
264  {
265  szFullFileName += _T(".");
266  szFullFileName += m_szFileExt;
267  }
268  return szFullFileName;
269  }
270 
277  CZipString GetFullPath() const
278  {
279  CZipString szFullPath = GetFilePath();
280  CZipString szFileName = GetFileName();
281  if (!szFileName.IsEmpty())
282  {
283  if (szFullPath.IsEmpty())
284  szFullPath += _T('.');
285  szFullPath += m_cSeparator;
286  szFullPath += szFileName;
287  }
288  return szFullPath;
289  }
290 
297  CZipString GetFilePath() const
298  {
299  CZipString szDrive = m_szDrive;
300  CZipString szDir = m_szDirectory;
301  if (!szDrive.IsEmpty() && !szDir.IsEmpty())
302  szDrive += m_cSeparator;
303 
304  return m_szPrefix + szDrive + szDir;
305  }
306 protected:
311  CZipString m_szDirectory,
312  m_szFileTitle,
313  m_szFileExt,
314  m_szDrive,
315  m_szPrefix;
316 
317 
318 };
319 
320 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
321  #pragma warning (pop)
322 #endif
323 
324 
325 #endif // !defined(ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H)

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