aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h
blob: de46b95d82f8d9a85c30a815e87d373f2558da10 (plain)
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#pragma once
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.


#ifdef __cplusplus
extern "C" {
#endif

typedef enum _PATH_CANONICALIZE
{
    // Always prefix fully qualified paths with the extended path prefix (\\?\).
    PATH_CANONICALIZE_APPEND_EXTENDED_PATH_PREFIX = 0x0001,
    // Always terminate the path with \.
    PATH_CANONICALIZE_BACKSLASH_TERMINATE = 0x0002,
    // Don't collapse . or .. in the \\server\share portion of a UNC path.
    PATH_CANONICALIZE_KEEP_UNC_ROOT = 0x0004,
} PATH_CANONICALIZE;

typedef enum _PATH_EXPAND
{
    PATH_EXPAND_ENVIRONMENT = 0x0001,
    PATH_EXPAND_FULLPATH    = 0x0002,
} PATH_EXPAND;

typedef enum _PATH_PREFIX
{
    // Add prefix even if the path is not longer than MAX_PATH.
    PATH_PREFIX_SHORT_PATHS    = 0x0001,
    // Error with E_INVALIDARG if the path is not fully qualified.
    PATH_PREFIX_EXPECT_FULLY_QUALIFIED = 0x0002,
} PATH_PREFIX;


/*******************************************************************
 PathFile -  returns a pointer to the file part of the path.
********************************************************************/
DAPI_(LPWSTR) PathFile(
    __in_z LPCWSTR wzPath
    );

/*******************************************************************
 PathExtension -  returns a pointer to the extension part of the path
                  (including the dot).
********************************************************************/
DAPI_(LPCWSTR) PathExtension(
    __in_z LPCWSTR wzPath
    );

/*******************************************************************
 PathGetDirectory - extracts the directory from a path including the directory separator.
    Calling the function again with the previous result returns the same result.
    Returns S_FALSE if the path only contains a file name.
    For example, C:\a\b -> C:\a\ -> C:\a\
********************************************************************/
DAPI_(HRESULT) PathGetDirectory(
    __in_z LPCWSTR wzPath,
    __out_z LPWSTR *psczDirectory
    );

/*******************************************************************
PathGetParentPath - extracts the parent directory from a path
    ignoring a trailing slash so that when called repeatedly,
    it eventually returns the root portion of the path.
    *psczDirectory is NULL if the path only contains a file name or
    the path only contains the root.
    *pcchRoot is the length of the root part of the path.
    For example, C:\a\b -> C:\a\ -> C:\ -> NULL
********************************************************************/
DAPI_(HRESULT) PathGetParentPath(
    __in_z LPCWSTR wzPath,
    __out_z LPWSTR *psczDirectory,
    __out_opt SIZE_T* pcchRoot
    );

/*******************************************************************
 PathExpand - gets the full path to a file resolving environment
              variables along the way.
********************************************************************/
DAPI_(HRESULT) PathExpand(
    __out LPWSTR *psczFullPath,
    __in_z LPCWSTR wzRelativePath,
    __in DWORD dwResolveFlags
    );

/*******************************************************************
 PathGetFullPathName - wrapper around GetFullPathNameW.
*******************************************************************/
DAPI_(HRESULT) PathGetFullPathName(
    __in_z LPCWSTR wzPath,
    __deref_out_z LPWSTR* psczFullPath,
    __inout_z_opt LPCWSTR* pwzFileName,
    __out_opt SIZE_T* pcch
    );

/*******************************************************************
 PathPrefix - prefixes a path with \\?\ or \\?\UNC if it doesn't
    already have an extended prefix, is longer than MAX_PATH,
    and is fully qualified.
********************************************************************/
DAPI_(HRESULT) PathPrefix(
    __inout_z LPWSTR *psczFullPath,
    __in SIZE_T cchFullPath,
    __in DWORD dwPrefixFlags
    );

/*******************************************************************
 PathFixedNormalizeSlashes - replaces all / with \ and
    removes redundant consecutive slashes.
********************************************************************/
DAPI_(HRESULT) PathFixedNormalizeSlashes(
    __inout_z LPWSTR wzPath
    );

/*******************************************************************
 PathFixedReplaceForwardSlashes - replaces all / with \
********************************************************************/
DAPI_(void) PathFixedReplaceForwardSlashes(
    __inout_z LPWSTR wzPath
    );

/*******************************************************************
 PathFixedBackslashTerminate - appends a \ if path does not have it
                                 already, but fails if the buffer is
                                 insufficient.
********************************************************************/
DAPI_(HRESULT) PathFixedBackslashTerminate(
    __inout_ecount_z(cchPath) LPWSTR wzPath,
    __in SIZE_T cchPath
    );

/*******************************************************************
 PathBackslashTerminate - appends a \ if path does not have it
                                 already.
********************************************************************/
DAPI_(HRESULT) PathBackslashTerminate(
    __inout_z LPWSTR* psczPath
    );

/*******************************************************************
 PathForCurrentProcess - gets the full path to the currently executing
                         process or (optionally) a module inside the process.
********************************************************************/
DAPI_(HRESULT) PathForCurrentProcess(
    __inout LPWSTR *psczFullPath,
    __in_opt HMODULE hModule
    );

/*******************************************************************
 PathRelativeToModule - gets the name of a file in the same 
    directory as the current process or (optionally) a module inside 
    the process
********************************************************************/
DAPI_(HRESULT) PathRelativeToModule(
    __inout LPWSTR *psczFullPath,
    __in_opt LPCWSTR wzFileName,
    __in_opt HMODULE hModule
    );

/*******************************************************************
 PathCreateTempFile

 Note: if wzDirectory is null, ::GetTempPath2() will be used instead.
       if wzFileNameTemplate is null, GetTempFileName() will be used instead.
*******************************************************************/
DAPI_(HRESULT) PathCreateTempFile(
    __in_opt LPCWSTR wzDirectory,
    __in_opt __format_string LPCWSTR wzFileNameTemplate,
    __in DWORD dwUniqueCount,
    __in_z LPCWSTR wzPrefix,
    __in DWORD dwFileAttributes,
    __out_opt LPWSTR* psczTempFile,
    __out_opt HANDLE* phTempFile
    );

/*******************************************************************
 PathGetTempFileName - wrapper around ::GetTempFileName.
    If the wzPathName is too long, it will use its own algorithm.
*******************************************************************/
DAPI_(HRESULT) PathGetTempFileName(
    __in LPCWSTR wzPathName,
    __in LPCWSTR wzPrefixString,
    __in UINT uUnique,
    __out LPWSTR* psczTempFileName
    );

/*******************************************************************
 PathCreateTimeBasedTempFile - creates an empty temp file based on current
                           system time
********************************************************************/
DAPI_(HRESULT) PathCreateTimeBasedTempFile(
    __in_z_opt LPCWSTR wzDirectory,
    __in_z LPCWSTR wzPrefix,
    __in_z_opt LPCWSTR wzPostfix,
    __in_z LPCWSTR wzExtension,
    __deref_opt_out_z LPWSTR* psczTempFile,
    __out_opt HANDLE* phTempFile
    );

/*******************************************************************
 PathCreateTempDirectory

 Note: if wzDirectory is null, ::GetTempPath2() will be used instead.
*******************************************************************/
DAPI_(HRESULT) PathCreateTempDirectory(
    __in_opt LPCWSTR wzDirectory,
    __in __format_string LPCWSTR wzDirectoryNameTemplate,
    __in DWORD dwUniqueCount,
    __out LPWSTR* psczTempDirectory
    );

/*******************************************************************
 PathGetTempPath - returns the path to the temp folder
    that is backslash terminated.
*******************************************************************/
DAPI_(HRESULT) PathGetTempPath(
    __out_z LPWSTR* psczTempPath,
    __out_opt SIZE_T* pcch
    );

/*******************************************************************
 PathGetSystemDirectory - returns the path to the system folder
    that is backslash terminated.
*******************************************************************/
DAPI_(HRESULT) PathGetSystemDirectory(
    __out_z LPWSTR* psczSystemPath
    );

/*******************************************************************
 PathGetSystemWow64Directory - returns the path to the system WoW 64 folder
    that is backslash terminated.
*******************************************************************/
DAPI_(HRESULT) PathGetSystemWow64Directory(
    __out_z LPWSTR* psczSystemPath
    );

/*******************************************************************
 PathSystemWindowsSubdirectory - returns the path to the Windows folder
    or a subdirectory of that folder that is backslash terminated.
*******************************************************************/
DAPI_(HRESULT) PathSystemWindowsSubdirectory(
    __in_z_opt LPCWSTR wzSubdirectory,
    __out_z LPWSTR* psczFullPath
    );

/*******************************************************************
 PathGetSystemTempPaths - returns the paths to system temp folders
    that are backslash terminated with higher preference first.
*******************************************************************/
DAPI_(HRESULT) PathGetSystemTempPaths(
    __inout_z LPWSTR** prgsczSystemTempPaths,
    __inout DWORD* pcSystemTempPaths
    );

/*******************************************************************
 PathGetVolumePathName - wrapper for ::GetVolumePathNameW.
*******************************************************************/
DAPI_(HRESULT) PathGetVolumePathName(
    __in_z LPCWSTR wzFileName,
    __out_z LPWSTR* psczVolumePathName
    );

/*******************************************************************
 PathSkipPastRoot - returns a pointer to the first character after
    the root portion of the path or NULL if the path has no root.
    For example, the pointer will point to the "a" in "after":
    C:\after, C:after, \after, \\server\share\after,
    \\?\C:\afterroot, \\?\UNC\server\share\after
*******************************************************************/
DAPI_(LPCWSTR) PathSkipPastRoot(
    __in_z LPCWSTR wzPath,
    __out_opt BOOL* pfHasExtendedPrefix,
    __out_opt BOOL* pfFullyQualified,
    __out_opt BOOL* pfUNC
    );

/*******************************************************************
 PathIsFullyQualified - returns true if the path is fully qualified; false otherwise.
    Note that some rooted paths like C:dir are not fully qualified.
    For example, these are all fully qualified: C:\dir, C:/dir, \\server\share, \\?\C:\dir.
    For example, these are not fully qualified: C:dir, C:, \dir, dir, dir\subdir.
*******************************************************************/
DAPI_(BOOL) PathIsFullyQualified(
    __in_z LPCWSTR wzPath
    );

/*******************************************************************
 PathIsRooted - returns true if the path is rooted; false otherwise.
    Note that some rooted paths like C:dir are not fully qualified.
    For example, these are all rooted: C:\dir, C:/dir, C:dir, C:, \dir, \\server\share, \\?\C:\dir.
    For example, these are not rooted: dir, dir\subdir.
*******************************************************************/
DAPI_(BOOL) PathIsRooted(
    __in_z LPCWSTR wzPath
    );

/*******************************************************************
 PathConcat - like .NET's Path.Combine, lets you build up a path
    one piece -- file or directory -- at a time.
*******************************************************************/
DAPI_(HRESULT) PathConcat(
    __in_opt LPCWSTR wzPath1,
    __in_opt LPCWSTR wzPath2,
    __deref_out_z LPWSTR* psczCombined
    );

/*******************************************************************
 PathConcatCch - like .NET's Path.Combine, lets you build up a path
    one piece -- file or directory -- at a time.
*******************************************************************/
DAPI_(HRESULT) PathConcatCch(
    __in_opt LPCWSTR wzPath1,
    __in SIZE_T cchPath1,
    __in_opt LPCWSTR wzPath2,
    __in SIZE_T cchPath2,
    __deref_out_z LPWSTR* psczCombined
    );

/*******************************************************************
 PathConcatRelativeToBase - canonicalizes a relative path before
    concatenating it to the base path to ensure the resulting path
    is inside the base path.
*******************************************************************/
DAPI_(HRESULT) PathConcatRelativeToBase(
    __in LPCWSTR wzBase,
    __in_opt LPCWSTR wzRelative,
    __deref_out_z LPWSTR* psczCombined
    );

/*******************************************************************
 PathConcatRelativeToFullyQualifiedBase - ensures the base path is
    fully qualified and then calls PathConcatRelativeToBase.
*******************************************************************/
DAPI_(HRESULT) PathConcatRelativeToFullyQualifiedBase(
    __in LPCWSTR wzBase,
    __in_opt LPCWSTR wzRelative,
    __deref_out_z LPWSTR* psczCombined
    );

/*******************************************************************
 PathCompareCanonicalized - canonicalizes the two paths using PathCanonicalizeForComparison
    which does not resolve relative paths into fully qualified paths.
    The strings are then compared using ::CompareStringW().
*******************************************************************/
DAPI_(HRESULT) PathCompareCanonicalized(
    __in_z LPCWSTR wzPath1,
    __in_z LPCWSTR wzPath2,
    __out BOOL* pfEqual
    );

/*******************************************************************
 PathCompress - sets the compression state on an existing file or 
                directory. A no-op on file systems that don't 
                support compression.
*******************************************************************/
DAPI_(HRESULT) PathCompress(
    __in_z LPCWSTR wzPath
    );

/*******************************************************************
 PathGetHierarchyArray - allocates an array containing,
                in order, every parent directory of the specified path,
                ending with the actual input path
                This function also works with registry subkeys
*******************************************************************/
DAPI_(HRESULT) PathGetHierarchyArray(
    __in_z LPCWSTR wzPath,
    __deref_inout_ecount_opt(*pcPathArray) LPWSTR **prgsczPathArray,
    __inout LPUINT pcPathArray
    );

/********************************************************************
 Path2FunctionAllowFallback - allow functions only available in newer versions of Windows.
                              Typically used for unit testing.

*********************************************************************/
void DAPI Path2FunctionAllowFallback();

/********************************************************************
 Path2FunctionForceFallback - ignore functions only available in newer versions of Windows.
                              Typically used for unit testing.

*********************************************************************/
void DAPI Path2FunctionForceFallback();

/*******************************************************************
 PathCanonicalizePath - wrapper around PathCanonicalizeW.
*******************************************************************/
DAPI_(HRESULT) PathCanonicalizePath(
    __in_z LPCWSTR wzPath,
    __deref_out_z LPWSTR* psczCanonicalized
    );

/*******************************************************************
 PathAllocCanonicalizePath - wrapper around PathAllocCanonicalize.
*******************************************************************/
DAPI_(HRESULT) PathAllocCanonicalizePath(
    __in_z LPCWSTR wzPath,
    __in DWORD dwFlags,
    __deref_out_z LPWSTR* psczCanonicalized
    );

/*******************************************************************
 PathCanonicalizeForComparison - canonicalizes the path based on the given flags.
    . and .. directories are collapsed.
    All / are replaced with \.
    All redundant consecutive slashes are replaced with a single \.
*******************************************************************/
DAPI_(HRESULT) PathCanonicalizeForComparison(
    __in_z LPCWSTR wzPath,
    __in DWORD dwCanonicalizeFlags,
    __deref_out_z LPWSTR* psczCanonicalized
    );

/*******************************************************************
 PathDirectoryContainsPath - checks if wzPath is located inside wzDirectory.
    wzDirectory must be a fully qualified path.
*******************************************************************/
DAPI_(HRESULT) PathDirectoryContainsPath(
    __in_z LPCWSTR wzDirectory,
    __in_z LPCWSTR wzPath
    );

#ifdef __cplusplus
}
#endif