MCPcopy Create free account
hub / github.com/bumptop/BumpTop / openFile

Method openFile

trunk/win/Source/BT_JavaScriptAPI.cpp:525–545  ·  view source on GitHub ↗

Open a file for reading or writing. 'mode' is a string of length 1 indicating the access mode. Valid values are "r" (read), "w" (truncate), "a" (append). Returns the file handle on success, or -1 on failure.

Source from the content-addressed store, hash-verified

523// are "r" (read), "w" (truncate), "a" (append).
524// Returns the file handle on success, or -1 on failure.
525int JavaScriptAPI::openFile(QString fileName, QString mode)
526{
527 QString filePath(winOS->GetUserApplicationDataPath().absoluteFilePath(fileName));
528
529 QFile* file = new QFile(native(filePath));
530 QIODevice::OpenMode flags;
531 if (mode == "r")
532 flags = QFile::ReadOnly;
533 else if (mode == "w")
534 flags = QFile::WriteOnly | QFile::Truncate;
535 else if (mode == "a")
536 flags = QFile::Append;
537
538 if (file->open(flags))
539 {
540 _fileMap.insert(file->handle(), file);
541 return file->handle();
542 }
543 SAFE_DELETE(file);
544 return -1;
545}
546
547QString JavaScriptAPI::readFile(int fileHandle)
548{

Callers 2

updateSettingsFileFunction · 0.80
loadSettingsFunction · 0.80

Calls 5

nativeFunction · 0.70
openMethod · 0.45
insertMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected