void NTPath::Transform() { string& Data = *this; if (!Data.empty()) { if(!HasPathPrefix(Data)) { ConvertNameToFull(Data,Data); if (!HasPathPrefix(Data)) { ReplaceSlashToBackslash(Data); string Prefix(ParsePath(Data) == PATH_DRIVELETTER? L"\\\\?\\" : L"\\\\?\\UNC"); while(ReplaceStrings(Data,L"\\\\",L"\\")) ; Data=Prefix+Data; } } if(Data.size() > 5 && Data[5] == L':') { // "\\?\C:" -> "\\?\c:" // Some file operations fails on Win2k if a drive letter is in upper case ToLower(Data, 4, 1); } } }
// Косметические преобразования строки пути. // CheckFullPath используется в FCTL_SET[ANOTHER]PANELDIR void PrepareDiskPath(string &strPath, bool CheckFullPath) { // elevation not required during cosmetic operation SCOPED_ACTION(elevation::suppress); if (!strPath.empty()) { if (strPath.size() > 1 && (strPath[1]==L':' || (IsSlash(strPath[0]) && IsSlash(strPath[1])))) { ReplaceSlashToBackslash(strPath); bool DoubleSlash = strPath[1]==L'\\'; while(ReplaceStrings(strPath, L"\\\\"sv, L"\\"sv)) ; if(DoubleSlash) { strPath = L'\\' + strPath; } if (CheckFullPath) { strPath = ConvertNameToFull(strPath); size_t DirOffset = 0; const auto Type = ParsePath(strPath, &DirOffset); if (Type == root_type::unknown && HasPathPrefix(strPath)) { DirOffset = 4; } size_t StartPos = DirOffset; if (StartPos < strPath.size()) { string TmpStr; TmpStr.reserve(strPath.size()); size_t LastPos = StartPos; const auto EndsWithSlash = IsSlash(strPath.back()); for (size_t i = StartPos; i <= strPath.size(); ++i) { if ((i < strPath.size() && IsSlash(strPath[i])) || (i == strPath.size() && !EndsWithSlash)) { TmpStr.assign(strPath, 0, i); os::fs::find_data fd; if (os::fs::get_find_data(TmpStr, fd)) { strPath.replace(LastPos, i - LastPos, fd.FileName); i += fd.FileName.size() - (i - LastPos); } if (i != strPath.size()) { LastPos = i + 1; } } } } } if (ParsePath(strPath) == root_type::drive_letter) { strPath[0] = upper(strPath[0]); } } } }