MCPcopy Create free account
hub / github.com/ConEmu/ConEmu / GetShortFileNameEx

Function GetShortFileNameEx

src/common/WObjects.cpp:388–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388CEStr 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;

Callers 3

CConEmuMainMethod · 0.85
ChangeExecuteParamsMethod · 0.85
SetConEmuFoldersMethod · 0.85

Calls 7

GetShortFileNameFunction · 0.85
GetBufferMethod · 0.80
SetAtMethod · 0.80
GetMaxCountMethod · 0.80
c_strMethod · 0.80
dataMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected