Error RegistryKey::getStringValue(std::string name, std::string *pValue) { if (!hKey_) return systemError(ERROR_INVALID_HANDLE, ERROR_LOCATION); std::vector<char> buffer; buffer.reserve(260); while (true) { DWORD type; DWORD size = buffer.capacity(); LONG result = ::RegQueryValueEx(hKey_, name.c_str(), NULL, &type, (LPBYTE)(&buffer[0]), &size); switch (result) { case ERROR_SUCCESS: { if (type != REG_SZ && type != REG_EXPAND_SZ) return systemError(ERROR_INVALID_DATATYPE, ERROR_LOCATION); *pValue = std::string(&buffer[0], buffer.capacity()); // REG_SZ and friends may or may not be null-terminated. // So trim the string at the first null, if any. size_t idxNull = pValue->find('\0'); if (idxNull != std::string::npos) pValue->resize(idxNull); if (type == REG_EXPAND_SZ) { Error error = expandEnvironmentVariables(*pValue, pValue); if (error) return error; } return Success(); } case ERROR_MORE_DATA: buffer.reserve(size); continue; default: return systemError(result, ERROR_LOCATION); } } }
void CFileSystemObject::setPath(const QString& path) { if (path.isEmpty()) { *this = CFileSystemObject(); return; } _rootFileSystemId = std::numeric_limits<uint64_t>::max(); _fileInfo.setFile(expandEnvironmentVariables(path)); refreshInfo(); }
CFileSystemObject::CFileSystemObject(const QString& path) : _fileInfo(expandEnvironmentVariables(path)) { refreshInfo(); }