MCPcopy Create free account
hub / github.com/TeXworks/texworks / writeFile

Method writeFile

src/scripting/ScriptAPI.cpp:301–321  ·  view source on GitHub ↗

Q_INVOKABLE

Source from the content-addressed store, hash-verified

299
300//Q_INVOKABLE
301int ScriptAPI::writeFile(const QString& filename, const QString& content) const
302{
303 // relative paths are taken to be relative to the folder containing the
304 // executing script's file
305 QDir scriptDir(QFileInfo(m_script->getFilename()).dir());
306 QString path = scriptDir.absoluteFilePath(filename);
307
308 if (!mayWriteFile(path, m_target))
309 return ScriptAPI::SystemAccess_PermissionDenied;
310
311 QFile fout(path);
312 qint64 numBytes = -1;
313
314 if (!fout.open(QIODevice::WriteOnly | QIODevice::Text))
315 return ScriptAPI::SystemAccess_Failed;
316
317 numBytes = fout.write(content.toUtf8());
318 fout.close();
319
320 return (numBytes < 0 ? ScriptAPI::SystemAccess_Failed : ScriptAPI::SystemAccess_OK);
321}
322
323//Q_INVOKABLE
324QMap<QString, QVariant> ScriptAPI::readFile(const QString& filename) const

Callers

nothing calls this directly

Calls 3

getFilenameMethod · 0.45
absoluteFilePathMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected