Author: hbelusca
Date: Tue May 23 22:30:54 2017
New Revision: 74637
URL:
http://svn.reactos.org/svn/reactos?rev=74637&view=rev
Log:
[USETUP]: Transform the existing ConcatPaths() function into a variadic function, and
derive a CombinePaths() from it (plus their equivalent taking va_list). This allows
building concatenated paths with an arbitrary number of separated components (as done in
the rest of the code). Will be used soon.
Modified:
branches/setup_improvements/base/setup/lib/filesup.c
branches/setup_improvements/base/setup/lib/filesup.h
Modified: branches/setup_improvements/base/setup/lib/filesup.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] Tue May 23 22:30:54
2017
@@ -40,35 +40,108 @@
#endif
HRESULT
-ConcatPaths(
- IN OUT PWSTR PathElem1,
+ConcatPathsV(
+ IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
- IN PCWSTR PathElem2 OPTIONAL)
-{
- HRESULT hr;
+ IN ULONG NumberOfPathComponents,
+ IN va_list PathComponentsList)
+{
+ HRESULT hr = S_OK;
SIZE_T cchPathLen;
-
- if (!PathElem2)
+ PCWSTR PathComponent;
+
+ if (cchPathSize < 1)
return S_OK;
- if (cchPathSize <= 1)
- return S_OK;
-
- cchPathLen = min(cchPathSize, wcslen(PathElem1));
-
- if (PathElem2[0] != L'\\' && cchPathLen > 0 &&
PathElem1[cchPathLen-1] != L'\\')
- {
- /* PathElem2 does not start with '\' and PathElem1 does not end with
'\' */
- hr = StringCchCatW(PathElem1, cchPathSize, L"\\");
+
+ while (NumberOfPathComponents--)
+ {
+ PathComponent = va_arg(PathComponentsList, PCWSTR);
+ if (!PathComponent)
+ continue;
+
+ cchPathLen = min(cchPathSize, wcslen(PathBuffer));
+ if (cchPathLen >= cchPathSize)
+ return STRSAFE_E_INSUFFICIENT_BUFFER;
+
+ if (PathComponent[0] != OBJ_NAME_PATH_SEPARATOR &&
+ cchPathLen > 0 && PathBuffer[cchPathLen-1] !=
OBJ_NAME_PATH_SEPARATOR)
+ {
+ /* PathComponent does not start with '\' and PathBuffer does not end
with '\' */
+ hr = StringCchCatW(PathBuffer, cchPathSize, L"\\");
+ if (FAILED(hr))
+ return hr;
+ }
+ else if (PathComponent[0] == OBJ_NAME_PATH_SEPARATOR &&
+ cchPathLen > 0 && PathBuffer[cchPathLen-1] ==
OBJ_NAME_PATH_SEPARATOR)
+ {
+ /* PathComponent starts with '\' and PathBuffer ends with '\'
*/
+ while (*PathComponent == OBJ_NAME_PATH_SEPARATOR)
+ ++PathComponent; // Skip any backslash
+ }
+ hr = StringCchCatW(PathBuffer, cchPathSize, PathComponent);
if (FAILED(hr))
return hr;
}
- else if (PathElem2[0] == L'\\' && cchPathLen > 0 &&
PathElem1[cchPathLen-1] == L'\\')
- {
- /* PathElem2 starts with '\' and PathElem1 ends with '\' */
- while (*PathElem2 == L'\\')
- ++PathElem2; // Skip any backslash
- }
- hr = StringCchCatW(PathElem1, cchPathSize, PathElem2);
+
+ return hr;
+}
+
+HRESULT
+CombinePathsV(
+ OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN va_list PathComponentsList)
+{
+ if (cchPathSize < 1)
+ return S_OK;
+
+ *PathBuffer = UNICODE_NULL;
+ return ConcatPathsV(PathBuffer, cchPathSize,
+ NumberOfPathComponents, PathComponentsList);
+}
+
+HRESULT
+ConcatPaths(
+ IN OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN /* PCWSTR */ ...)
+{
+ HRESULT hr;
+ va_list PathComponentsList;
+
+ if (cchPathSize < 1)
+ return S_OK;
+
+ va_start(PathComponentsList, NumberOfPathComponents);
+ hr = ConcatPathsV(PathBuffer, cchPathSize,
+ NumberOfPathComponents, PathComponentsList);
+ va_end(PathComponentsList);
+
+ return hr;
+}
+
+HRESULT
+CombinePaths(
+ OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN /* PCWSTR */ ...)
+{
+ HRESULT hr;
+ va_list PathComponentsList;
+
+ if (cchPathSize < 1)
+ return S_OK;
+
+ *PathBuffer = UNICODE_NULL;
+
+ va_start(PathComponentsList, NumberOfPathComponents);
+ hr = CombinePathsV(PathBuffer, cchPathSize,
+ NumberOfPathComponents, PathComponentsList);
+ va_end(PathComponentsList);
+
return hr;
}
@@ -121,13 +194,7 @@
UNICODE_STRING Name;
WCHAR FullName[MAX_PATH];
- if (PathName)
- StringCchCopyW(FullName, ARRAYSIZE(FullName), PathName);
- else
- FullName[0] = UNICODE_NULL;
-
- ConcatPaths(FullName, ARRAYSIZE(FullName), FileName);
-
+ CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
RtlInitUnicodeString(&Name, FullName);
InitializeObjectAttributes(&ObjectAttributes,
@@ -268,14 +335,7 @@
UNICODE_STRING Name;
WCHAR FullName[MAX_PATH];
- if (PathName)
- StringCchCopyW(FullName, ARRAYSIZE(FullName), PathName);
- else
- FullName[0] = UNICODE_NULL;
-
- if (FileName)
- ConcatPaths(FullName, ARRAYSIZE(FullName), FileName);
-
+ CombinePaths(FullName, ARRAYSIZE(FullName), 2, PathName, FileName);
RtlInitUnicodeString(&Name, FullName);
InitializeObjectAttributes(&ObjectAttributes,
Modified: branches/setup_improvements/base/setup/lib/filesup.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] Tue May 23 22:30:54
2017
@@ -17,10 +17,32 @@
#endif
HRESULT
+ConcatPathsV(
+ IN OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN va_list PathComponentsList);
+
+HRESULT
+CombinePathsV(
+ OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN va_list PathComponentsList);
+
+HRESULT
ConcatPaths(
- IN OUT PWSTR PathElem1,
+ IN OUT PWSTR PathBuffer,
IN SIZE_T cchPathSize,
- IN PCWSTR PathElem2 OPTIONAL);
+ IN ULONG NumberOfPathComponents,
+ IN /* PCWSTR */ ...);
+
+HRESULT
+CombinePaths(
+ OUT PWSTR PathBuffer,
+ IN SIZE_T cchPathSize,
+ IN ULONG NumberOfPathComponents,
+ IN /* PCWSTR */ ...);
BOOLEAN
DoesPathExist(