File: ZipPathComponent.h

package info (click to toggle)
tuxcmd-modules 0.6.70%2Bds-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,872 kB
  • sloc: cpp: 11,743; ansic: 8,064; makefile: 245
file content (276 lines) | stat: -rw-r--r-- 6,500 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
////////////////////////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////////////////////////

/**
* \file ZipPathComponent.h
* Includes the CZipPathComponent class.
*
*/
#if !defined(ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H)
#define ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H

#if _MSC_VER > 1000
	#pragma once
	#if defined ZIP_HAS_DLL
		#pragma warning (push)
		#pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
	#endif
#endif

#include "ZipString.h"
#include "ZipExport.h"

/**
	Splits a file path into components.
*/
class ZIP_API CZipPathComponent  
{
public:
	CZipPathComponent(){}
	virtual ~CZipPathComponent();

	static const TCHAR m_cSeparator; ///< A system - specific default path separator.

	/**
		Appends a path separator to \a szPath, if it is not already appended.

		\param szPath
			The path to have a separator appended.
	*/
	static void AppendSeparator(CZipString& szPath)
	{
		RemoveSeparators(szPath);
		szPath += m_cSeparator;
	}

	/**
		Combines a path information with a file name information.

		\param szPath
			Provides the path information and retrieves the result.

		\param lpszName
			The filename to be appended to the path.
	*/
	static void Combine(CZipString& szPath, LPCTSTR lpszName)
	{
		AppendSeparator(szPath);
		if (lpszName != NULL)
			szPath += lpszName;
	}

	/**
		Removes path separators from the end of \a szPath

		\param szPath
			The path to have path separators removed.
	*/
	static void RemoveSeparators(CZipString& szPath)
	{
// 		szPath.TrimRight(m_cSeparator);
		szPath.TrimRight(_T("\\/"));
	}

	/**
		Removes path separators from the beginning of \a szPath.

		\param szPath
			The path to have path separators removed.
	*/
	static void RemoveSeparatorsLeft(CZipString& szPath)
	{
		szPath.TrimLeft(_T("\\/"));
	}


    /**
		Tests the character, if it is a separator or not.	

		\param c 
			The character to test.

		\return
			\c true, if \a c is a path separator; \c false otherwise.
     */
	static bool IsSeparator(TCHAR c)
	{
		return c == _T('\\') || c == _T('/');
	}
	
	/**
		Checks if \a szPath has a path separator appended.

		\param szPath
			The path to be tested.

		\return
			\c true, if \a szPath has a path separator at the end; \c false otherwise.
	*/
	static bool HasEndingSeparator(const CZipString& szPath)
	{
		int iLen = szPath.GetLength();
		if (iLen)
			return IsSeparator(szPath[iLen - 1]);
		else
			return false;
	}

	/**
		Initializes a new instance of the CZipPathComponent class.

		\param	lpszFullPath
			The full path to the file.

		\see
			SetFullPath
	*/
	CZipPathComponent(LPCTSTR lpszFullPath)
	{
		SetFullPath(lpszFullPath);
	}
	
	/**
		Sets the full path to the file.

		\param	lpszFullPath
			The full path to the file including a filename.
			The last element in the path is assumed to be a filename.
	*/
	void SetFullPath(LPCTSTR lpszFullPath);

	/**
		Gets the name of the file without an extension (and without a path).

		\return
			The title of the file.
	*/
	CZipString GetFileTitle() const { return m_szFileTitle;}

	/**
		Sets the file title (the name without an extension and without a path).

		\param	lpszFileTitle
			The title to set.
	*/
	void SetFileTitle(LPCTSTR lpszFileTitle) { m_szFileTitle = lpszFileTitle;}

	
	/**
		Sets the extension alone.

		\param	lpszExt
			The extension to set. May contain a dot at the beginning, but doesn't have to.
	*/
	void SetExtension(LPCTSTR lpszExt) 
	{
		m_szFileExt = lpszExt;
		m_szFileExt.TrimLeft(_T('.'));
	}

	/**
		Gets the extension of the file.

		\return
			The extension without a dot.
	*/
	CZipString GetFileExt() const { return m_szFileExt;}

	/**
		Gets the drive of the file.

		\return
			The drive without a path separator at the end.
	*/
	CZipString GetFileDrive() const { return m_szDrive;}

	/**
		Gets the full path to the file without the drive.

		\return
			The path without the drive and without a path separator at the beginning.
	*/
	CZipString GetNoDrive() const ;

	/**
		Get the filename.

		\return
			The filename including an extension and without a path.
	*/
	CZipString GetFileName() const
	{
		CZipString szFullFileName = m_szFileTitle;
		if (!m_szFileExt.IsEmpty())
		{
			szFullFileName += _T(".");
			szFullFileName += m_szFileExt;
		}
		return szFullFileName;
	}

	/**
		Gets the full path to the file.

		\return
			The full path information including the filename.
	*/
	CZipString GetFullPath() const
	{
		CZipString szFullPath = GetFilePath();
		CZipString szFileName = GetFileName();
		if (!szFileName.IsEmpty())
		{
			if (szFullPath.IsEmpty())
				szFullPath += _T('.');
			szFullPath  += m_cSeparator;
			szFullPath  += szFileName;
		}
		return szFullPath;
	}

	/**
		Gets the path part only.

		\return
			The path to the file without a filename and without a path separator at the end.
	*/
	CZipString GetFilePath() const
	{
		CZipString szDrive = m_szDrive;
		CZipString szDir = m_szDirectory;
		if (!szDrive.IsEmpty() && !szDir.IsEmpty())
			szDrive += m_cSeparator;

		return m_szPrefix + szDrive + szDir;	
	}
protected:
	/**
		\name Path parts.
	*/
	//@{
	CZipString m_szDirectory,	///< A directory(ies) only without path separators at the end and the beginning.
		m_szFileTitle,			///< A filename without an extension.
		m_szFileExt,			///< A file extension without a dot.
		m_szDrive,				///< A drive (if the system path standard uses it) without a path separator at the end.
		m_szPrefix;				///< A prefix (e.g. for the UNC path or Unicode path under Windows).
	//@}
	
};

#if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
	#pragma warning (pop)	
#endif


#endif // !defined(ZIPARCHIVE_ZIPPATHCOMPONENT_DOT_H)