| 386 | } |
| 387 | |
| 388 | CEStr GetShortFileNameEx(LPCWSTR asLong, BOOL abFavorLength/*=TRUE*/) |
| 389 | { |
| 390 | if (!asLong) |
| 391 | return {}; |
| 392 | |
| 393 | const int nSrcLen = lstrlenW(asLong); //-V303 |
| 394 | const int nMaxLen = nSrcLen + MAX_PATH; // "short" name could be longer than MAX_PATH |
| 395 | |
| 396 | CEStr pszResult; |
| 397 | const CEStr pszLong(asLong); |
| 398 | CEStr pszShort; |
| 399 | CEStr szName; |
| 400 | wchar_t* pszSrc = pszLong.data(); |
| 401 | wchar_t* pszSlash; |
| 402 | bool lbNetwork = false; |
| 403 | int nLen, nCurLen = 0; |
| 404 | |
| 405 | if (!pszLong || !pszSrc || !pszShort.GetBuffer(nMaxLen) || !szName.GetBuffer(MAX_PATH)) |
| 406 | goto wrap; |
| 407 | |
| 408 | // Если путь сетевой (или UNC?) пропустить префиксы/серверы |
| 409 | if (pszSrc[0] == L'\\' && pszSrc[1] == '\\') |
| 410 | { |
| 411 | // пропуск первых двух слешей |
| 412 | pszSrc += 2; |
| 413 | // формат "диска" не поддерживаем \\.\Drive\... |
| 414 | if (pszSrc[0] == L'.' && pszSrc[1] == L'\\') |
| 415 | goto wrap; |
| 416 | // UNC |
| 417 | if (pszSrc[0] == L'?' && pszSrc[1] == L'\\') |
| 418 | { |
| 419 | pszSrc += 2; |
| 420 | if (pszSrc[0] == L'U' && pszSrc[1] == L'N' && pszSrc[2] == L'C' && pszSrc[3] == L'\\') |
| 421 | { |
| 422 | // UNC\Server\share\... |
| 423 | pszSrc += 4; //-V112 |
| 424 | lbNetwork = true; |
| 425 | } |
| 426 | // иначе - ожидается диск |
| 427 | } |
| 428 | // Network (\\Server\\Share\...) |
| 429 | else |
| 430 | { |
| 431 | lbNetwork = true; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | if (pszSrc[0] == 0) |
| 436 | goto wrap; |
| 437 | |
| 438 | if (lbNetwork) |
| 439 | { |
| 440 | pszSlash = wcschr(pszSrc, L'\\'); |
| 441 | if (!pszSlash) |
| 442 | goto wrap; |
| 443 | pszSlash = wcschr(pszSlash+1, L'\\'); |
| 444 | if (!pszSlash) |
| 445 | goto wrap; |
no test coverage detected