/** * Return a FileEntry object. */ void PhoneGapFile::actionGetFile(PhoneGapMessage& message) { lprintfln("@@@ actionGetFile\n"); String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fullPath"); String path = message.getArgsField("path"); String fullFilePath = fullPath + "/" + path; // Get flags "create" and "exclusive". bool create = false; bool exclusive = false; bool success = message.getJSONParamsOptionsCreateExclusive(create, exclusive); if (!success) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Create file if requested. if (create) { if (exclusive) { // The file must not exist if "exclusive" is true. if (FileExists(fullFilePath)) { callFileError(callbackID, FILEERROR_PATH_EXISTS_ERR); return; } } if (!FileExists(fullFilePath)) { // Create the file. bool success = FileCreatePath(fullFilePath); if (!success) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } } } // Send back FileEntry data. String fileEntry = emitFileEntry( path, fullFilePath); callSuccess( callbackID, fileEntry, "window.localFileSystem._castEntry"); }
/** * Return a DirectoryEntry object. */ void PhoneGapFile::actionGetDirectory(PhoneGapMessage& message) { lprintfln("@@@ actionGetDirectory\n"); String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fullPath"); String path = message.getArgsField("path"); String fullFilePath = fullPath + "/" + path; // Add a trailing slash if not present. MoSync API requires this. if (fullFilePath[fullFilePath.size() - 1] != '/') { fullFilePath += "/"; } // Get flags "create" and "exclusive". bool create = false; bool exclusive = false; bool success = message.getJSONParamsOptionsCreateExclusive(create, exclusive); if (!success) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Create directory if requested. if (create) { if (exclusive) { // The file must not exist if "exclusive" is true. if (FileExists(fullFilePath)) { callFileError(callbackID, FILEERROR_PATH_EXISTS_ERR); return; } } if (!FileExists(fullFilePath)) { // Create the directory. // TODO: Invoke error if parent directory does not // exist to be compatible with the PhoneGap spec. bool success = FileCreatePath(fullFilePath); if (!success) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } } } // Send back DirectoryEntry data. String directoryEntry = emitDirectoryEntry( path, // Remove the trailing slash from the full path. fullFilePath.substr(0, fullFilePath.size() - 1)); callSuccess( callbackID, directoryEntry, "window.localFileSystem._castEntry"); }