returns 8.3 file format from long path
| 1657 | #ifdef Q_OS_WIN |
| 1658 | // returns 8.3 file format from long path |
| 1659 | QString shortPathName(const QString& file) |
| 1660 | { |
| 1661 | auto input = file.toStdWString(); |
| 1662 | std::wstring output; |
| 1663 | long length = GetShortPathNameW(input.c_str(), NULL, 0); |
| 1664 | if (length == 0) |
| 1665 | return {}; |
| 1666 | // NOTE: this resizing might seem weird... |
| 1667 | // when GetShortPathNameW fails, it returns length including null character |
| 1668 | // when it succeeds, it returns length excluding null character |
| 1669 | // See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx |
| 1670 | output.resize(length); |
| 1671 | if (GetShortPathNameW(input.c_str(), (LPWSTR)output.c_str(), length) == 0) |
| 1672 | return {}; |
| 1673 | output.resize(length - 1); |
| 1674 | QString ret = QString::fromStdWString(output); |
| 1675 | return ret; |
| 1676 | } |
| 1677 | |
| 1678 | // if the string survives roundtrip through local 8bit encoding... |
| 1679 | bool fitsInLocal8bit(const QString& string) |
no test coverage detected