| 1371 | } |
| 1372 | |
| 1373 | bool 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 |
no outgoing calls