/** * Load the object data from file. * The file is expected to be already open for reading. * The data will be read and the file will not be closed. * @returns True on success, false on failure */ bool UAVObject::load(QFile & file) { QMutexLocker locker(mutex); quint8 buffer[numBytes]; quint8 tmpId[4]; // Read the object ID if (file.read((char *)tmpId, 4) != 4) { return false; } // Check that the IDs match if (qFromLittleEndian<quint32>(tmpId) != objID) { return false; } // Read the instance ID if (file.read((char *)tmpId, 2) != 2) { return false; } // Check that the IDs match if (qFromLittleEndian<quint16>(tmpId) != instID) { return false; } // Read and unpack the data if (file.read((char *)buffer, numBytes) != numBytes) { return false; } unpack(buffer); // Done return true; }
bool ccObject::fromFile(QFile& in, short dataVersion) { assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly)); if (dataVersion<20) return CorruptError(); //DGM: if we are here, we assume the class ID has already been read! //Call ccObject::readClassIDFromFile if necessary ////class ID (dataVersion>=20) //uint32_t classID = 0; //if (in.read((char*)&classID,4)<0) // return ReadError(); //unique ID (dataVersion>=20) //DGM: this ID will be usefull to recreate dynamic links between entities! uint32_t uniqueID = 0; if (in.read((char*)&uniqueID,4)<0) return ReadError(); m_uniqueID = (unsigned)uniqueID; //name (dataVersion>=20) if (in.read(m_name,256)<0) return ReadError(); //flags (dataVersion>=20) uint32_t flags = 0; if (in.read((char*)&flags,4)<0) return ReadError(); m_flags = (unsigned)flags; return true; }
void QAniTransferFunctionInstance::load(QFile & file) { file.read((char *)&m_resolution, 4); file.read((char *)&m_tfResolutionChange, 4); m_tfDrawArrayChange = new float[m_resolution]; file.read((char *)m_tfDrawArrayChange, 4 * m_resolution); int size; file.read((char *)&size, 4); for (int i = 0; i < size; ++i) { double mean,sigma,height; file.read((char *)&mean, 8); file.read((char *)&sigma, 8); file.read((char *)&height, 8); GaussianObjectChange goc(mean, sigma, height); m_gaussianObjectChange.push_back(goc); } file.read((char *)&size, 4); for (int i = 0; i < size; ++i) { float x; Vector4 color; file.read((char *)&x, 4); file.read((char *)((double*)color), 32); ColorTickChange ctc(x, color); m_tfColorTickChange.push_back(ctc); } }
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion) { if (!ccHObject::fromFile_MeOnly(in, dataVersion)) return false; if (dataVersion<20) return CorruptError(); //'coordinates shift' (dataVersion>=20) if (in.read((char*)m_originalShift,sizeof(double)*3)<0) return ReadError(); //'visibility' array (dataVersion>=20) bool hasVisibilityArray = false; if (in.read((char*)&hasVisibilityArray,sizeof(bool))<0) return ReadError(); if (hasVisibilityArray) { if (!m_visibilityArray) { m_visibilityArray = new VisibilityTableType(); m_visibilityArray->link(); } if (!ccSerializationHelper::GenericArrayFromFile(*m_visibilityArray,in,dataVersion)) { unallocateVisibilityArray(); return false; } } return true; }
bool ccGenericMesh::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; //'show wired' state (dataVersion>=20) if (in.read((char*)&m_showWired,sizeof(bool))<0) return ReadError(); //'per-triangle normals shown' state (dataVersion>=29)) if (dataVersion >= 29) { if (in.read((char*)&m_triNormsShown,sizeof(bool))<0) return ReadError(); //'materials shown' state (dataVersion>=29)) if (in.read((char*)&m_materialsShown,sizeof(bool))<0) return ReadError(); //'polygon stippling' state (dataVersion>=29)) if (in.read((char*)&m_stippling,sizeof(bool))<0) return ReadError(); } return true; }
bool ccObject::fromFile(QFile& in, short dataVersion, int flags) { assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly)); if (dataVersion<20) return CorruptError(); //DGM: if we are here, we assume the class ID has already been read! //Call ccObject::readClassIDFromFile if necessary ////class ID (dataVersion>=20) //uint32_t classID = 0; //if (in.read((char*)&classID,4) < 0) // return ReadError(); //unique ID (dataVersion>=20) //DGM: this ID will be usefull to recreate dynamic links between entities! uint32_t uniqueID = 0; if (in.read((char*)&uniqueID,4) < 0) return ReadError(); m_uniqueID = (unsigned)uniqueID; //name if (dataVersion < 22) //old style { char name[256]; if (in.read(name,256) < 0) return ReadError(); setName(name); } else //(dataVersion>=22) { QDataStream inStream(&in); inStream >> m_name; } //flags (dataVersion>=20) uint32_t objFlags = 0; if (in.read((char*)&objFlags,4) < 0) return ReadError(); m_flags = (unsigned)objFlags; //meta data (dataVersion>=30) if (dataVersion >= 30) { //count uint32_t metaDataCount = 0; if (in.read((char*)&metaDataCount,4) < 0) return ReadError(); //"key + value" pairs for (uint32_t i=0; i<metaDataCount; ++i) { QDataStream inStream(&in); QString key; QVariant value; inStream >> key; inStream >> value; setMetaData(key,value); } }
bool ccHObject::fromFile(QFile& in, short dataVersion) { assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly)); //read 'ccObject' header if (!ccObject::fromFile(in,dataVersion)) return false; //read own data if (!fromFile_MeOnly(in,dataVersion)) return false; //(serializable) child count (dataVersion>=20) uint32_t serializableCount = 0; if (in.read((char*)&serializableCount,4)<0) return ReadError(); //read serializable children (if any) for (uint32_t i=0; i<serializableCount; ++i) { //read children class ID unsigned classID=0; if (!ReadClassIDFromFile(classID, in, dataVersion)) return false; //create corresponding child object ccHObject* child = New(classID); assert(child && child->isSerializable()); if (child) { if (child->fromFile(in,dataVersion)) { addChild(child,child->getFlagState(CC_FATHER_DEPENDANT)); } else { delete child; return false; } } else { return CorruptError(); } } //write current selection behavior (dataVersion>=23) if (dataVersion>=23) { if (in.read((char*)&m_selectionBehavior,sizeof(SelectionBehavior))<0) return ReadError(); } else { m_selectionBehavior = SELECTION_AA_BBOX; } return true; }
bool ccPolyline::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; if (dataVersion<28) return false; //as the associated cloud (=vertices) can't be saved directly (as it may be shared by multiple polylines) //we only store its unique ID (dataVersion>=28) --> we hope we will find it at loading time (i.e. this //is the responsibility of the caller to make sure that all dependencies are saved together) uint32_t vertUniqueID = 0; if (in.read((char*)&vertUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the vertices unique ID in the 'm_associatedCloud' pointer!!! *(uint32_t*)(&m_theAssociatedCloud) = vertUniqueID; //number of points (references to) (dataVersion>=28) uint32_t pointCount = 0; if (in.read((char*)&pointCount,4) < 0) return ReadError(); if (!reserve(pointCount)) return false; //points (references to) (dataVersion>=28) for (uint32_t i=0; i<pointCount; ++i) { uint32_t pointIndex = 0; if (in.read((char*)&pointIndex,4) < 0) return ReadError(); addPointIndex(pointIndex); } QDataStream inStream(&in); //Closing state (dataVersion>=28) inStream >> m_isClosed; //RGB Color (dataVersion>=28) inStream >> m_rgbColor[0]; inStream >> m_rgbColor[1]; inStream >> m_rgbColor[2]; //2D mode (dataVersion>=28) inStream >> m_mode2D; //Foreground mode (dataVersion>=28) inStream >> m_foreground; //Width of the line (dataVersion>=31) if (dataVersion >= 31) ccSerializationHelper::CoordsFromDataStream(inStream,flags,&m_width,1); else m_width = 0; return true; }
bool ccGenericPointCloud::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; if (dataVersion < 20) return CorruptError(); if (dataVersion < 33) { //'coordinates shift' (dataVersion>=20) if (in.read((char*)m_globalShift.u,sizeof(double)*3) < 0) return ReadError(); m_globalScale = 1.0; } else { //'global shift & scale' (dataVersion>=33) if (!loadShiftInfoFromFile(in)) return ReadError(); } //'visibility' array (dataVersion>=20) bool hasVisibilityArray = false; if (in.read((char*)&hasVisibilityArray,sizeof(bool)) < 0) return ReadError(); if (hasVisibilityArray) { if (!m_pointsVisibility) { m_pointsVisibility = new VisibilityTableType(); m_pointsVisibility->link(); } if (!ccSerializationHelper::GenericArrayFromFile(*m_pointsVisibility,in,dataVersion)) { unallocateVisibilityArray(); return false; } } //'point size' (dataVersion>=24) if (dataVersion >= 24) { if (in.read((char*)&m_pointSize,1) < 0) return WriteError(); } else { m_pointSize = 0; //= follows default setting } return true; }
bool ccShiftedObject::loadShiftInfoFromFile(QFile& in) { //'coordinates shift' if (in.read((char*)m_globalShift.u,sizeof(double)*3) < 0) return ccSerializableObject::ReadError(); //'global scale' if (in.read((char*)&m_globalScale,sizeof(double)) < 0) return ccSerializableObject::ReadError(); return true; }
bool ccColorScale::fromFile(QFile& in, short dataVersion, int flags) { if (dataVersion < 27) //structure appeared at version 27! return false; QDataStream inStream(&in); //name (dataVersion>=27) inStream >> m_name; //UUID (dataVersion>=27) inStream >> m_uuid; //relative state (dataVersion>=27) if (in.read((char*)&m_relative,sizeof(bool)) < 0) return ReadError(); //Absolute min value (dataVersion>=27) if (in.read((char*)&m_absoluteMinValue,sizeof(double)) < 0) return ReadError(); //Absolute range (dataVersion>=27) if (in.read((char*)&m_absoluteRange,sizeof(double)) < 0) return ReadError(); //locked state (dataVersion>=27) if (in.read((char*)&m_locked,sizeof(bool)) < 0) return ReadError(); //steps list (dataVersion>=27) { //steps count uint32_t stepCount = 0; if (in.read((char*)&stepCount,4) < 0) return ReadError(); //read each step m_steps.clear(); for (uint32_t i=0; i<stepCount; ++i) { double relativePos = 0.0; QColor color(Qt::white); inStream >> relativePos; inStream >> color; m_steps.push_back(ccColorScaleElement(relativePos,color)); } update(); } return true; }
bool Matrix::readMatrix(QFile &file) { releaseData(); file.read((char *)&nRow,sizeof(int)); file.read((char *)&nCol,sizeof(int)); if(nRow*nCol>0) { allocate(nRow,nCol); if(file.read((char *)pData,sizeof(double)*nRow*nCol)!=sizeof(double)*nRow*nCol) return false; } return true; }
void skipUselessChucks( WavFileHeader& header, QFile& file ) { // We only care about the 'data' chuck while ( memcmp( header.dataChuckID, "data", 4 ) != 0 ) { int skipByteCount = header.dataSize; std::vector<char> skipData( skipByteCount ); file.read( skipData.data(), skipByteCount ); file.read( (char*)&header.dataChuckID, 4 ); file.read( (char*)&header.dataSize, 4 ); } }
bool Vector::readVector(QFile &file) { releaseData(); file.read((char *)&nDim,sizeof(int)); if(nDim<0) return false; if(nDim>0) { allocate(nDim); if(file.read((char *)pData,sizeof(double)*nDim)!=sizeof(double)*nDim) return false; } return true; }
QString read_MAT_MAPNAME_chunk( QFile &src ) { TA3D_3DS_CHUNK_DATA chunk; src.read( (char*)&chunk.ID, 2 ); src.read( (char*)&chunk.length, 4 ); switch( chunk.ID ) { case MAT_MAPNAME: return read_ASCIIZ( src ); default: src.read( chunk.length - 6 ); }; return NULL; }
bool FileContentsChecksum(const QString &name, unsigned int *sum) { QFile *file = new QFile(name); if (!file->open(QIODevice::ReadOnly)) { delete file; return false; } // compute the checksum char buf[80]; *sum = 0; while (!file->atEnd()) { qint64 len = file->read(buf, 80); *sum = BJHash::Hash((unsigned char *) buf, (unsigned int)len, *sum); } file->close(); delete file; return true; }
QFile *getAudioLabelHeaderLen(const QString &audioName, int &len) { QFile *pFile = new QFile(audioName); if (!pFile->open(QIODevice::ReadOnly)) { qDebug() << "Can not open file"; return NULL; } pFile->seek(0); //读取标签头 ID3V2Header mp3ID3V2; memset(&mp3ID3V2, 0, 10); pFile->read((char *)&mp3ID3V2, 10); if (0 != strncmp(mp3ID3V2.identi, "ID3", 3)) { qDebug() << "No have ID3V2 label"; pFile->close(); return NULL; } len = (mp3ID3V2.size[0]&0x7f)*0x200000 +(mp3ID3V2.size[1]&0x7f)*0x4000 +(mp3ID3V2.size[2]&0x7f)*0x80 +(mp3ID3V2.size[3]&0x7f); return pFile; }
inline int KBufferedFileReaderPrivate::next() { ++m_bufferPos; // Handle EOF Markers if ((*m_bufferPos) == static_cast<char>(EOF)) { // If they're not our markers, this is the end of the file if (m_bufferPos != &m_buffer[m_bufferSize] && m_bufferPos != &m_buffer[2 * m_bufferSize + 1]) { --m_bufferPos; return KBufferedFileReader::EndOfFile; } // Otherwise, we've simply read the current buffer. // Swap buffers, and start reading from the other buffer. m_bufferPos = m_nextBuffer; std::swap(m_currBuffer, m_nextBuffer); // Start Reading in the next chunk m_nextBuffer[m_file.read(m_nextBuffer, m_bufferSize)] = EOF; } return *m_bufferPos; }
bool ccImage::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; //as the associated sensor can't be saved directly (as it may be shared by multiple images) //we only store its unique ID (dataVersion >= 38) --> we hope we will find it at loading time (i.e. this //is the responsibility of the caller to make sure that all dependencies are saved together) uint32_t sensorUniqueID = 0; if (in.read((char*)&sensorUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the vertices unique ID in the 'm_associatedCloud' pointer!!! *(uint32_t*)(&m_associatedSensor) = sensorUniqueID; QDataStream inStream(&in); inStream >> m_width; inStream >> m_height; inStream >> m_aspectRatio; inStream >> m_texU; inStream >> m_texV; inStream >> m_texAlpha; inStream >> m_image; #ifdef INCLUDE_IMAGE_FILENAME inStream >> m_completeFileName; #else QString fakeString; inStream >> fakeString; #endif return true; }
qint64 StateImport::loadCTM5(State *state, QFile& file, struct CTMHeader5* v5header) { if (v5header->flags & 03) { state->setErrorMessage(QObject::tr("Error: CTM is not expanded")); qDebug() << "CTM is not expanded. Cannot load it"; return -1; } int num_chars = qFromLittleEndian(v5header->num_chars); int toRead = std::min(num_chars * 8, State::CHAR_BUFFER_SIZE); // clean previous memory in case not all the chars are loaded state->resetCharsetBuffer(); auto total = file.read((char*)state->getCharsetBuffer(), toRead); for (int i=0; i<4; i++) state->setColorForPen(i, v5header->colors[i]); state->setMulticolorMode(v5header->flags & 0b00000100); State::TileProperties tp; tp.interleaved = 1; // some files reports size == 0. Bug in CTMv5? tp.size.setWidth(qMax((int)v5header->tile_width,1)); tp.size.setHeight(qMax((int)v5header->tile_height,1)); state->setTileProperties(tp); return total; }
bool StreamMail::LoadFile(const QString file) { ////qFatal(" unable to read ... "); bool filled = false; if (clear()) { QFile *f = new QFile(file); if (f->exists()) { ///// if (f->open(QIODevice::ReadOnly)) { //// read line by line if (f->isReadable()) { linenr = -1; while (!f->atEnd()) { linenr++; QByteArray crk = f->read(76); d->write(crk); } f->close(); d->write(QByteArray("\n--\n--\n--\n--")); } } else { qDebug() << "######## file errors:" << f->errorString() << "\n"; } } } if (d->bytesAvailable() > 23) { filled = true; } d->seek(0); return filled; }
void janelaPrincipal::copiarAquivos(QFile &origem, QFile &destino) { qint64 nCopySize = origem.size(); ui->progressBarGeral->setMaximum(nCopySize); if(!(origem.open(QFile::ReadOnly) && destino.open(QFile::ReadWrite))){ return; } qDebug() << QString::number(nCopySize)+" o tamanho do arquivo"; //dialog->show(); for (qint64 i = 0; i < nCopySize; i += 1024*1024) { if(iscopy){ destino.write(origem.read(i)); // write a byte destino.seek(i); // move to next byte to read origem.seek(i); // move to next byte to write ui->progressBarGeral->setValue(i); }else { destino.remove(); break; } // ui->progressBarGeral->; } ui->progressBarGeral->setVisible(false); ui->progressBarGeral->setValue(0); modeldir->refresh(); }
qint64 StateImport::loadCTM(State *state, QFile& file) { struct CTMHeader5 header; auto size = file.size(); if ((std::size_t)size<sizeof(header)) { state->setErrorMessage(QObject::tr("Error: CTM file too small")); qDebug() << "Error. File size too small to be CTM (" << size << ")."; return -1; } size = file.read((char*)&header, sizeof(header)); if ((std::size_t)size<sizeof(header)) return -1; // check header if (header.id[0] != 'C' || header.id[1] != 'T' || header.id[2] != 'M') { state->setErrorMessage(QObject::tr("Error: invalid CTM file")); qDebug() << "Not a valid CTM file"; return -1; } // check version if (header.version == 4) { return loadCTM4(state, file, (struct CTMHeader4*)&header); } else if (header.version == 5) { return loadCTM5(state, file, &header); } state->setErrorMessage(QObject::tr("Error: CTM version not supported")); qDebug() << "Invalid CTM version: " << header.version; return -1; }
QString ZString::getFileCoding(const QString &filePath) { QFile *file = new QFile(filePath); if (!file->open(QFile::ReadOnly)) { return ""; } qint64 size = file->size(); char *buf = new char[size]; file->read(buf, size); file->close(); // 读取文件头 /// /// ANSI: 没有文件头(2字节/汉字,1字节/英文) /// UTF-8: 文件头[0xEF,0xBB,0xBF](3字节/汉字,1字节/英文) /// Unicode: 文件头[0xFF,0xFE](2字节/汉字,2字节/英文) /// Unicode big endian: 文件头[0xFE,0xFF](同Unicode,字节序相反) /// uchar *p = (uchar*)buf; if (0xEF == p[0] && 0xBB == p[1] && 0xBF == p[2]) { qDebug() << QString::fromUtf8(buf + 3, size -3); return "UFT-8"; } else if (0xFF == p[0] && 0xFE == p[1]) { qDebug() << QString::fromWCharArray((wchar_t*)(buf + 2), (size - 2) / 2); return "Unicode"; } else if (0xFE == p[0] && 0xFF == p[1]) { qDebug() << QString::fromWCharArray((wchar_t*)(buf + 2), (size - 2) / 2); return "Unicode big endian"; } else { qDebug() << QString::fromLocal8Bit(buf, size); return "ANSI"; } }
QByteArray Scanner::hashFile(QFile &f) { uchar *map; QCryptographicHash hasher(QCryptographicHash::Sha1); hasher.reset(); /* Try map first */ map = f.map( 0, f.size() ); if (NULL==map) { /* no mmap, read in chunks */ uchar buffer[512]; qint64 r; do { r = f.read((char*)buffer,sizeof(buffer)); if (r<0){ throw 1; } if (r<=0) break; hasher.addData( (const char*)buffer, r); } while (r>0); } else { hasher.addData((const char*)map,f.size()); f.unmap(map); } return hasher.result(); }
inline T readNum(char *num, QFile &file) { file.read(num, 4); T n = *((T*)num); n = qFromBigEndian(n); return n; }
// ==================================================================================================================== // readLayout(): Loads the binary layout from the given *open* file. // ==================================================================================================================== void MainWindow::readLayout(QFile& file) { uchar geo_size; QByteArray geo_data; QByteArray layout_data; bool ok = file.getChar((char*)&geo_size); if (ok) { geo_data = file.read(geo_size); ok = geo_data.size() == geo_size; } if (ok) { layout_data = file.readAll(); ok = layout_data.size() > 0; } if (ok) ok = restoreGeometry(geo_data); if (ok) ok = restoreState(layout_data); if (!ok) { QString msg = tr("Error reading %1").arg(file.fileName()); QMessageBox::warning(this, tr("Error"), msg); return; } }
void NetworkManager::handleVideo(QSharedPointer<MediaFile> mediaEntry, QHttpRequest *req, QHttpResponse *resp) { QFile *file = new QFile(mediaEntry->path(), resp); if(!file->open(QFile::OpenModeFlag::ReadOnly)) { sendError(QHttpResponse::STATUS_NOT_FOUND, resp); return; } resp->setHeader("Accept-Ranges", "bytes"); qint64 size = file->size(); qint64 offset = 0; if(req->headers().contains("range")) { QString range = req->headers()["range"]; offset = QStringRef(&range, 6, (range.indexOf('-') - 6)).toLongLong(); resp->setHeader("Content-Range", QString("bytes " + QString::number(offset) + "-" + QString::number(size) + "/" + QString::number(size)).toLatin1()); resp->setHeader("Content-Length", QString::number(size - offset).toLatin1()); resp->writeHead(QHttpResponse::STATUS_PARTIAL_CONTENT); } else { resp->setHeader("Content-Length", QString::number(file->size()).toLatin1()); resp->writeHead(QHttpResponse::STATUS_OK); } file->seek(offset); QObject::connect(resp, &QHttpResponse::allBytesWritten, [file,resp](){ QByteArray data = file->read(0x40000); if(data.size() > 0) { resp->write(data); } else { file->close(); resp->end(); delete file; } }); resp->write(file->read(0x40000)); }
//static int32_t SoundSourceWV::ReadBytesCallback(void* id, void* data, int bcount) { QFile* pFile = static_cast<QFile*>(id); if (!pFile) { return 0; } return pFile->read((char*)data, bcount); }
int ExifData::getch ( QFile &infile ) { QByteArray a = infile.read ( 1 ); uint r = 0; r = static_cast<uint> ( a[0] ); r &= 0x000000FF; return static_cast<int> ( r ); }