/** * Return a FileSystem object. */ void PhoneGapFile::actionRequestFileSystem(PhoneGapMessage& message) { lprintfln("@@@ actionRequestFileSystem\n"); String callbackID = message.getParam("PhoneGapCallBackId"); // We support only persistent storage. int type = message.getArgsFieldInt("type"); if (LOCALFILESYSTEM_PERSISTENT != type) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Size parameter must be zero. int size = message.getArgsFieldInt("size"); if (0 != size) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // TODO: Replace hard-coded path with platform aware path handling. String rootEntry = emitDirectoryEntry("sdcard", "/sdcard"); String fileSystemInfo = emitFileSystemInfo("persistent", rootEntry); callSuccess( callbackID, fileSystemInfo, "window.localFileSystem._castFS"); }
void PhoneGapFile::actionTruncate(PhoneGapMessage& message) { lprintfln("@@@ actionTruncate\n"); String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fileName"); int size = message.getArgsFieldInt("size"); int result = FileTruncate(fullPath, size); if (result < 0) { callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } // Send back the result, the new length of the file. char lengthBuf[32]; sprintf(lengthBuf, "%i", result); callSuccess(callbackID, lengthBuf); }
void PhoneGapFile::actionWrite(PhoneGapMessage& message) { lprintfln("@@@ actionWrite\n"); String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fileName"); String data = message.getArgsField("data"); int position = message.getArgsFieldInt("position"); int result = FileWrite(fullPath, data, position); if (result < 0) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Send back the new file size. char sizeBuf[32]; sprintf(sizeBuf, "%i", FileGetSize(fullPath)); callSuccess( callbackID, sizeBuf); }