| 194 | } |
| 195 | |
| 196 | int apiGetFullPathName(LPCWSTR lpFileName, CEStr& rsPath) |
| 197 | { |
| 198 | if (!lpFileName || !*lpFileName) |
| 199 | { |
| 200 | _ASSERTE(lpFileName != nullptr); |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int iFoundLen = 0; |
| 205 | wchar_t* pszFilePart = nullptr; |
| 206 | // ReSharper disable once CppInitializedValueIsAlwaysRewritten |
| 207 | wchar_t* pszBuffer = nullptr; |
| 208 | wchar_t szFind[MAX_PATH+1] = L""; |
| 209 | |
| 210 | DWORD nLen = GetFullPathName(lpFileName, countof(szFind), szFind, &pszFilePart); |
| 211 | if (nLen) |
| 212 | { |
| 213 | if (nLen < countof(szFind)) |
| 214 | { |
| 215 | rsPath.Set(szFind); |
| 216 | iFoundLen = static_cast<int>(rsPath.GetLen()); |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | // Too long path, allocate more space |
| 221 | pszBuffer = static_cast<wchar_t*>(malloc((++nLen)*sizeof(*pszBuffer))); |
| 222 | if (pszBuffer) |
| 223 | { |
| 224 | const DWORD nLen2 = GetFullPathName(lpFileName, nLen, pszBuffer, &pszFilePart); |
| 225 | if (nLen2 && (nLen2 < nLen)) |
| 226 | { |
| 227 | rsPath.Set(pszBuffer); |
| 228 | iFoundLen = static_cast<int>(rsPath.GetLen()); |
| 229 | } |
| 230 | free(pszBuffer); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | return (iFoundLen > 0) ? iFoundLen : 0; |
| 236 | } |
| 237 | |
| 238 | bool FileSearchInDir(LPCWSTR asFilePath, CEStr& rsFound) |
| 239 | { |
no test coverage detected