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.
| 523 | // are "r" (read), "w" (truncate), "a" (append). |
| 524 | // Returns the file handle on success, or -1 on failure. |
| 525 | int 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 | |
| 547 | QString JavaScriptAPI::readFile(int fileHandle) |
| 548 | { |
no test coverage detected