summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-03 17:47:31 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-07 19:44:36 -0500
commit8a4d03207633e9fdc364aaed82bd167f844679f9 (patch)
tree9ca862bb51fd3507fc5867c292aef236e3411867 /src/libs/dutil/WixToolset.DUtil/fileutil.cpp
parent5d35ff01e33b8ffdab04a49ddc5927185309391a (diff)
downloadwix-8a4d03207633e9fdc364aaed82bd167f844679f9.tar.gz
wix-8a4d03207633e9fdc364aaed82bd167f844679f9.tar.bz2
wix-8a4d03207633e9fdc364aaed82bd167f844679f9.zip
Resolve paths while parsing them from the command line.
The current directory is a process wide setting that can potentially be changed by any thread. Remove fileutil methods that had equivalent pathutil methods.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/fileutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/fileutil.cpp118
1 files changed, 0 insertions, 118 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
index 1822727a..2fe04de1 100644
--- a/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/fileutil.cpp
@@ -25,124 +25,6 @@ const BYTE UTF16BOM[] = {0xFF, 0xFE};
25const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; 25const LPCWSTR REGISTRY_PENDING_FILE_RENAME_KEY = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
26const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations"; 26const LPCWSTR REGISTRY_PENDING_FILE_RENAME_VALUE = L"PendingFileRenameOperations";
27 27
28/*******************************************************************
29 FileFromPath - returns a pointer to the file part of the path
30
31********************************************************************/
32extern "C" LPWSTR DAPI FileFromPath(
33 __in_z LPCWSTR wzPath
34 )
35{
36 if (!wzPath)
37 return NULL;
38
39 LPWSTR wzFile = const_cast<LPWSTR>(wzPath);
40 for (LPWSTR wz = wzFile; *wz; ++wz)
41 {
42 // valid delineators
43 // \ => Windows path
44 // / => unix and URL path
45 // : => relative path from mapped root
46 if (L'\\' == *wz || L'/' == *wz || L':' == *wz)
47 wzFile = wz + 1;
48 }
49
50 return wzFile;
51}
52
53
54/*******************************************************************
55 FileResolvePath - gets the full path to a file resolving environment
56 variables along the way.
57
58********************************************************************/
59extern "C" HRESULT DAPI FileResolvePath(
60 __in_z LPCWSTR wzRelativePath,
61 __out LPWSTR *ppwzFullPath
62 )
63{
64 Assert(wzRelativePath && *wzRelativePath);
65
66 HRESULT hr = S_OK;
67 DWORD cch = 0;
68 LPWSTR pwzExpandedPath = NULL;
69 DWORD cchExpandedPath = 0;
70
71 LPWSTR pwzFullPath = NULL;
72 DWORD cchFullPath = 0;
73
74 LPWSTR wzFileName = NULL;
75
76 //
77 // First, expand any environment variables.
78 //
79 cchExpandedPath = MAX_PATH;
80 hr = StrAlloc(&pwzExpandedPath, cchExpandedPath);
81 FileExitOnFailure(hr, "Failed to allocate space for expanded path.");
82
83 cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath);
84 if (0 == cch)
85 {
86 FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
87 }
88 else if (cchExpandedPath < cch)
89 {
90 cchExpandedPath = cch;
91 hr = StrAlloc(&pwzExpandedPath, cchExpandedPath);
92 FileExitOnFailure(hr, "Failed to re-allocate more space for expanded path.");
93
94 cch = ::ExpandEnvironmentStringsW(wzRelativePath, pwzExpandedPath, cchExpandedPath);
95 if (0 == cch)
96 {
97 FileExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath);
98 }
99 else if (cchExpandedPath < cch)
100 {
101 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
102 FileExitOnRootFailure(hr, "Failed to allocate buffer for expanded path.");
103 }
104 }
105
106 //
107 // Second, get the full path.
108 //
109 cchFullPath = MAX_PATH;
110 hr = StrAlloc(&pwzFullPath, cchFullPath);
111 FileExitOnFailure(hr, "Failed to allocate space for full path.");
112
113 cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName);
114 if (0 == cch)
115 {
116 FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
117 }
118 else if (cchFullPath < cch)
119 {
120 cchFullPath = cch;
121 hr = StrAlloc(&pwzFullPath, cchFullPath);
122 FileExitOnFailure(hr, "Failed to re-allocate more space for full path.");
123
124 cch = ::GetFullPathNameW(pwzExpandedPath, cchFullPath, pwzFullPath, &wzFileName);
125 if (0 == cch)
126 {
127 FileExitWithLastError(hr, "Failed to get full path for string: %ls", pwzExpandedPath);
128 }
129 else if (cchFullPath < cch)
130 {
131 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
132 FileExitOnRootFailure(hr, "Failed to allocate buffer for full path.");
133 }
134 }
135
136 *ppwzFullPath = pwzFullPath;
137 pwzFullPath = NULL;
138
139LExit:
140 ReleaseStr(pwzFullPath);
141 ReleaseStr(pwzExpandedPath);
142
143 return hr;
144}
145
146 28
147/******************************************************************* 29/*******************************************************************
148FileStripExtension - Strip extension from filename 30FileStripExtension - Strip extension from filename