-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPath.h
More file actions
191 lines (141 loc) · 5.08 KB
/
Copy pathPath.h
File metadata and controls
191 lines (141 loc) · 5.08 KB
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
//////////////////////////////////////////////////////////////////////
// Implemented by Samuel Gonzalo
//
// You may freely use or modify this code
//////////////////////////////////////////////////////////////////////
//
// Path.h: interface for the CPath class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(__PATH_H__)
#define __PATH_H__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include <afxtempl.h>
const TCHAR sCEmptyString = 0x0;
enum {PATH_CMDLINE, PATH_MODULE,PATH_CURDIR};
enum {FILE_CREATION, FILE_ACCESS, FILE_WRITE};
class CPath
{
public:
CPath();
CPath(LPCTSTR szPath, BOOL bIsFolderPath = FALSE, BOOL bHasArguments = FALSE);
CPath(DWORD dwSpecial);
virtual ~CPath();
// Parses a path or PATH_CMDLINE, PATH_MODULE
void SetPath(LPCTSTR szPath, BOOL bIsFolderPath = FALSE, BOOL bHasArguments = FALSE);
void SetPath(DWORD dwSpecial);
CString GetPath(BOOL bAppendArgs = FALSE, BOOL bOriginal = FALSE);
CString GetShortPath();
CString GetLongPath();
BOOL IsLocalPath();
BOOL IsRelativePath();
BOOL IsFilePath();
BOOL ExistFile();
BOOL ExistLocation();
// If the path set in the object is not a relative one returns empty
CString GetAbsolutePath(LPCTSTR szBaseFolder);
// If the path set in the object is a relative one returns empty
CString GetRelativePath(LPCTSTR szBaseFolder);
// Get drive string (empty for a network path) [e.g.: "c:"]
CString GetDrive();
// Get drive label (pc name for a network path) [e.g.: "MAIN_HD"]
CString GetDriveLabel(BOOL bPCNameIfNetwork = FALSE);
// Get folder count in path [e.g.: 2 for "c:\folder\subfolder\file.ext"]
int GetDirCount();
// Get 0 based nIndex folder string [e.g.: "folder" for nIndex = 0]
// If nIndex = -1 the return string is the full dir string
// [e.g.: "\folder\subfolder\" or "\\pcname\folder\" for non-local]
// If it's a relative path no "\" is added at the beginning [e.g.: "..\sub\"]
CString GetDir(int nIndex = -1);
// File location or directory path [e.g.: "c:\folder\subfolder\"]
CString GetLocation();
// File title string (without extension) [e.g.: "file" for "..\file.ext"]
CString GetFileTitle();
// Filename = File title + extension [e.g.: "file.ext"]
CString GetFileName();
// Extension string (dot included) [e.g.: ".ext"]
CString GetExtension();
// Extension name (dot not included) [e.g.: "ext"]
CString GetExtName();
// Get argument count [e.g.: 2 for <c:\app.exe param1 "param 2">]
int GetArgCount();
// Get 0 based nIndex argument string
// If nIndex = -1 the return string is the argument part of the path
// if bGetFlag is true, return the 0 based nIndex argument flag
CString GetArgument(int nIndex = -1, BOOL bGetFlag = FALSE);
// Set the arguments for the current file path
void SetArguments(LPCTSTR szArgs);
// Add or set an argument
void AddSetArgument(LPCTSTR szFlag, LPCTSTR szArgument);
// Remove argument nIndex
void RemoveArgument(int nIndex);
// Return 0 based index of the argument whose flag matches szFlag
// If it's not found, the return value is -1
int FindArgument(LPCTSTR szFlag);
// Get the size in bytes of the current file
BOOL GetFileSize(__int64 &nSize);
// Get the size in bytes of the current file
// values: FILE_CREATION, FILE_ACCESS, FILE_WRITE
// BOOL GetFileTime(CTime &time, DWORD dwType = FILE_WRITE);
// Return a temporary character pointer to the path data.
operator LPCTSTR ();
// Same as SetPath(szPath, FALSE, FALSE)
const CPath& operator = (LPCTSTR szPath);
// Makes a copy of the object
const CPath& operator = (CPath &ref);
// Add a back slash ('\' or '/' if bInverted is TRUE) if necessary
static CString AddBackSlash(LPCTSTR szFolderPath, BOOL bInverted = FALSE);
// Removes a trailing back slash if found
static CString RemoveBackSlash(LPCTSTR szFolderPath);
private:
typedef CSimpleArray<CString> CStringArray;
void FillDirArray();
void FillArgArray();
BOOL FillFileInfoStruct();
CString _sOriginalPath;
CString _sDrive;
CString _sDriveLabel;
CStringArray _aDir;
CString _sDir;
CString _sFileTitle;
CString _sExtName;
class CArgument
{
public:
CArgument()
{ cFlagMark = _T('/'); }
virtual ~CArgument() {}
CString GetString()
{
CString sArg;
if (!sFlag.IsEmpty()) sArg.Format(" %c%s", cFlagMark, sFlag);
if (!sValue.IsEmpty())
{
if (sValue.Find(_T(' ')) != -1)
sArg += CString(_T(" \"")) + sValue + CString(_T("\""));
else
sArg += CString(_T(" ")) + sValue;
}
return sArg;
}
void SetFlag(CString sFlagValue)
{
sFlag = sFlagValue;
if (sFlag.Remove('/') > 0) cFlagMark = '/';
if (sFlag.Remove('-') > 0) cFlagMark = '-';
sFlag.Remove(' ');
}
char cFlagMark;
CString sFlag;
CString sValue;
};
typedef CSimpleArray<CArgument> ATArguments;
CString _sArgs;
ATArguments _aArgs;
BOOL _bIsRelative;
BY_HANDLE_FILE_INFORMATION _fis;
CString _sLPCTSTRPath;
};
#endif // !defined(__PATH_H__)