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

Function IsFilePath

src/common/CmdLine.cpp:1373–1438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1371}
1372
1373bool IsFilePath(LPCWSTR asFilePath, const bool abFullRequired /*= false*/)
1374{
1375 if (!asFilePath || !*asFilePath)
1376 return false;
1377
1378 // Если в пути встречаются недопустимые символы
1379 // If contains some illegal characters
1380 if (wcschr(asFilePath, L'"') ||
1381 wcschr(asFilePath, L'>') ||
1382 wcschr(asFilePath, L'<') ||
1383 wcschr(asFilePath, L'|')
1384 // '/' don't restrict - it's allowed both in Windows and in cygwin
1385 )
1386 {
1387 return false;
1388 }
1389
1390 // skip UNC prefix "\\?\" in paths like "\\?\C:\Tools" or "\\?\UNC\Server\Share"
1391 bool isUncPath = false;
1392 if (asFilePath[0] == L'\\' && asFilePath[1] == L'\\' && asFilePath[2] == L'?' && asFilePath[3] == L'\\')
1393 {
1394 asFilePath += 4; //-V112
1395 isUncPath = true;
1396 }
1397
1398 // Don't allow two (and more) ":\"
1399 const auto* pszColon = wcschr(asFilePath, L':');
1400 if (pszColon)
1401 {
1402 // If the ":" exists, that it should be the path like "X:\xxx", i.e. ":" should be second character
1403 if (pszColon != (asFilePath + 1))
1404 return false;
1405
1406 if (!isDriveLetter(asFilePath[0]))
1407 return false;
1408
1409 if (wcschr(pszColon + 1, L':'))
1410 return false;
1411 }
1412
1413 if (abFullRequired)
1414 {
1415 if (isUncPath)
1416 {
1417 // For UNC network paths here should be "UNC\server\..."
1418 const auto* unc = asFilePath;
1419 if (unc[0] == L'U' && unc[1] == L'N' && unc[2] == L'C'
1420 && unc[3] == L'\\' && unc[4] && unc[4] != L'\\' && wcschr(unc + 5, L'\\'))
1421 return true;
1422 }
1423 else
1424 {
1425 const auto* srv = asFilePath;
1426 if (srv[0] == L'\\' && srv[1] == L'\\' && srv[2] && srv[2] != L'\\' && wcschr(srv + 3, L'\\'))
1427 return true;
1428 }
1429
1430 // And old good driver letter paths

Callers 15

debugLogShellMethod · 0.85
GetFileFromConsoleMethod · 0.85
UnitPathTestsFunction · 0.85
IsValidFileMethod · 0.85
PasteMethod · 0.85
FindOnDrivesFunction · 0.85
UnExpandEnvStringsFunction · 0.85
ParseCommandLineMethod · 0.85
ShowProtocolWarningMethod · 0.85
ProcessDragFromMethod · 0.85
FileSearchInDirFunction · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by 2

UnitPathTestsFunction · 0.68
TESTFunction · 0.68