diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/pathutil.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp index 5fad519b..7bac8ac3 100644 --- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp | |||
| @@ -21,108 +21,6 @@ | |||
| 21 | #define PATH_GOOD_ENOUGH 64 | 21 | #define PATH_GOOD_ENOUGH 64 |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | DAPI_(HRESULT) PathCommandLineAppend( | ||
| 25 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 26 | __in_z LPCWSTR wzArgument | ||
| 27 | ) | ||
| 28 | { | ||
| 29 | HRESULT hr = S_OK; | ||
| 30 | LPWSTR sczQuotedArg = NULL; | ||
| 31 | BOOL fRequiresQuoting = FALSE; | ||
| 32 | DWORD dwMaxEscapedSize = 0; | ||
| 33 | |||
| 34 | // Loop through the argument determining if it needs to be quoted and what the maximum | ||
| 35 | // size would be if there are escape characters required. | ||
| 36 | for (LPCWSTR pwz = wzArgument; *pwz; ++pwz) | ||
| 37 | { | ||
| 38 | // Arguments with whitespace need quoting. | ||
| 39 | if (L' ' == *pwz || L'\t' == *pwz || L'\n' == *pwz || L'\v' == *pwz) | ||
| 40 | { | ||
| 41 | fRequiresQuoting = TRUE; | ||
| 42 | } | ||
| 43 | else if (L'"' == *pwz) // quotes need quoting and sometimes escaping. | ||
| 44 | { | ||
| 45 | fRequiresQuoting = TRUE; | ||
| 46 | ++dwMaxEscapedSize; | ||
| 47 | } | ||
| 48 | else if (L'\\' == *pwz) // some backslashes need escaping, so we'll count them all to make sure there is room. | ||
| 49 | { | ||
| 50 | ++dwMaxEscapedSize; | ||
| 51 | } | ||
| 52 | |||
| 53 | ++dwMaxEscapedSize; | ||
| 54 | } | ||
| 55 | |||
| 56 | // If we found anything in the argument that requires our argument to be quoted | ||
| 57 | if (fRequiresQuoting) | ||
| 58 | { | ||
| 59 | hr = StrAlloc(&sczQuotedArg, dwMaxEscapedSize + 3); // plus three for the start and end quote plus null terminator. | ||
| 60 | PathExitOnFailure(hr, "Failed to allocate argument to be quoted."); | ||
| 61 | |||
| 62 | LPCWSTR pwz = wzArgument; | ||
| 63 | LPWSTR pwzQuoted = sczQuotedArg; | ||
| 64 | |||
| 65 | *pwzQuoted = L'"'; | ||
| 66 | ++pwzQuoted; | ||
| 67 | while (*pwz) | ||
| 68 | { | ||
| 69 | DWORD dwBackslashes = 0; | ||
| 70 | while (L'\\' == *pwz) | ||
| 71 | { | ||
| 72 | ++dwBackslashes; | ||
| 73 | ++pwz; | ||
| 74 | } | ||
| 75 | |||
| 76 | // Escape all backslashes at the end of the string. | ||
| 77 | if (!*pwz) | ||
| 78 | { | ||
| 79 | dwBackslashes *= 2; | ||
| 80 | } | ||
| 81 | else if (L'"' == *pwz) // escape all backslashes before the quote and escape the quote itself. | ||
| 82 | { | ||
| 83 | dwBackslashes = dwBackslashes * 2 + 1; | ||
| 84 | } | ||
| 85 | // the backslashes don't have to be escaped. | ||
| 86 | |||
| 87 | // Add the appropriate number of backslashes | ||
| 88 | for (DWORD i = 0; i < dwBackslashes; ++i) | ||
| 89 | { | ||
| 90 | *pwzQuoted = L'\\'; | ||
| 91 | ++pwzQuoted; | ||
| 92 | } | ||
| 93 | |||
| 94 | // If there is a character, add it after all the escaped backslashes | ||
| 95 | if (*pwz) | ||
| 96 | { | ||
| 97 | *pwzQuoted = *pwz; | ||
| 98 | ++pwz; | ||
| 99 | ++pwzQuoted; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | *pwzQuoted = L'"'; | ||
| 104 | ++pwzQuoted; | ||
| 105 | *pwzQuoted = L'\0'; // ensure the arg is null terminated. | ||
| 106 | } | ||
| 107 | |||
| 108 | // If there is already data in the command line, append a space before appending the | ||
| 109 | // argument. | ||
| 110 | if (*psczCommandLine && **psczCommandLine) | ||
| 111 | { | ||
| 112 | hr = StrAllocConcat(psczCommandLine, L" ", 0); | ||
| 113 | PathExitOnFailure(hr, "Failed to append space to command line with existing data."); | ||
| 114 | } | ||
| 115 | |||
| 116 | hr = StrAllocConcat(psczCommandLine, sczQuotedArg ? sczQuotedArg : wzArgument, 0); | ||
| 117 | PathExitOnFailure(hr, "Failed to copy command line argument."); | ||
| 118 | |||
| 119 | LExit: | ||
| 120 | ReleaseStr(sczQuotedArg); | ||
| 121 | |||
| 122 | return hr; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | DAPI_(LPWSTR) PathFile( | 24 | DAPI_(LPWSTR) PathFile( |
| 127 | __in_z LPCWSTR wzPath | 25 | __in_z LPCWSTR wzPath |
| 128 | ) | 26 | ) |
