MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / readFileContent

Method readFileContent

tools/FileSearchUtils.cpp:217–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217QString FileSearchUtils::readFileContent(const QString &filePath)
218{
219 QFile file(filePath);
220 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
221 return QString();
222 }
223
224 QString canonicalPath = QFileInfo(filePath).canonicalFilePath();
225 bool isInProject = Context::ProjectUtils::isFileInProject(canonicalPath);
226
227 if (!isInProject) {
228 const auto &settings = Settings::toolsSettings();
229 if (!settings.allowAccessOutsideProject()) {
230 LOG_MESSAGE(QString("Access denied to file outside project: %1").arg(canonicalPath));
231 return QString();
232 }
233 LOG_MESSAGE(QString("Reading file outside project scope: %1").arg(canonicalPath));
234 }
235
236 QTextStream stream(&file);
237 stream.setAutoDetectUnicode(true);
238 QString content = stream.readAll();
239
240 return content;
241}
242
243} // namespace QodeAssist::Tools

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected