-
Notifications
You must be signed in to change notification settings - Fork 0
/
Path.h
224 lines (193 loc) · 5.24 KB
/
Path.h
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
#pragma once
namespace Easy {
typedef bool (WINAPI * FILITER)(CString);
/*!
* @class Path
* @brief Path Tools
*
* Used to get different path
*/
class Path
{
public:
/*!
* @brief GetFileName
*
* Get filename from path
* @param sPath The path.
* @return CString The filename
*/
static CString GetFileName(CString sPath);
/*!
* @brief GetDirectory
*
* Get directory from path
* @param sPath The path.
* @return CString The directory
*/
static CString GetDirectory(CString sPath);
/*!
* @brief GetExtName
*
* Get extension from path
* @param sPath The path.
* @return CString The extension
*/
static CString GetExtName(CString sPath);
/*!
* @brief Resolve
*
* Stitching path
* @param sPath The path of one.
* @param sPathNext The path of next. You can use `..` to indicate the parent directory
* @return CString The final path
*/
static CString Resolve(CString sPath, CString sPathNext);
/*!
* @brief Omit
*
* Compressed path
* @param sPath The path.
* @param nSize The path length you want to compressed.
* @return CString The final path, like as `C:\...\sample.txt`
*/
static CString Omit(CString sPath, int nSize);
/*!
* @brief GetCurDirectory
*
* The Directory of Program
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetCurDirectory(CString sPath=_T(""));
/*!
* @brief GetTmpDirectory
*
* System temporary directory
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetTmpDirectory(CString sPath=_T(""));
/*!
* @brief GetUserDirectory
*
* The user root directory
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetUserDirectory(CString sPath=_T(""));
/*!
* @brief GetAppDataDirectory
*
* The user application data directory
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetAppDataDirectory(CString sPath=_T(""));
/*!
* @brief GetDesktopDirectory
*
* The user desktop path
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetDesktopDirectory(CString sPath=_T(""));
/*!
* @brief GetStartupDirectory
*
* The user startup path
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetStartupDirectory(CString sPath=_T(""));
/*!
* @brief GetStartMenuDirectory
*
* The system start menu path
* @param sPath The path you want to expand.
* @return CString The final path
*/
static CString GetStartMenuDirectory(CString sPath=_T(""));
/*!
* @brief GetProgramPath
*
* Get program path
* @return CString The program path
*/
static CString GetProgramPath(void);
/*!
* @brief GetProgramName
*
* Get program filename
* @return CString The program filename
*/
static CString GetProgramName(void);
/*!
* @brief IsDirectory
*
* Check Path is directory or not
* @return bool Is directory or not
*/
static bool IsDirectory(CString sPath);
/*!
* @brief IsDirectory
*
* Check directory is empty or not
* @return bool Is empty or not
*/
static bool IsEmpty(CString sPath);
/*!
* @brief Exists
*
* Check Path is exists or not
* @return bool Is exists or not
*/
static bool Exists(CString sPath);
/*!
* @brief Browse
*
* Open a dialog to browse file
* @param lpszFilter A series of string pairs that specify filters you can apply to the file.
* @param lpszDefExt The default file name extension. If this parameter is NULL, no extension is appended.
* @param bOpen Type of dialog box to create, TRUE to construct a File Open dialog box. Set it to FALSE to construct a File Save As dialog box.
* @param lpszFileName The initial file name that appears in the Filename box. If NULL, no initial file name appears.
* @return CString The file Path. User cancels if it's empty.
*/
static CString Browse(LPCTSTR lpszFilter, LPCTSTR lpszDefExt, BOOL bOpen, LPCTSTR lpszFileName);
/*!
* @brief Folder
*
* Open a dialog to browse folder
* @param hWnd A handle to the owner window for the dialog box.
* @param sRootPath Specifies the path of a folder to select.
* @return CString The final path
*/
static CString Folder(HWND hWnd, CString sRootPath=_T(""));
/*!
* @brief Traversing
*
* Traversing folder and get file list
* @param sDirectory The folder to traversing.
* @param filter A Callback used to check file. It will be skip file/folder when return false
* @return CString The final path
*/
static vector<CString> Path::Traversing(CString sDirectory, FILITER filter=NULL);
/*!
* @brief Create
*
* Creates all the directories in the specified path, beginning with the root.
* @param sPath A valid path name. If the final component of the path is a directory, not a file name.
* @return bool If the function succeeds, the return value is true;
*/
static bool Create(CString sPath);
};
/*!
* @brief _pr
*
* Stitching path macro define
* @param sPath The path of one.
* @param sPathNext The path of next. You can use `..` to indicate the parent directory
* @return CString The final path
*/
#define _pr(_x_,_y_) Path::Resolve(_x_,_y_)
}