void MainWindow::read_pkm_data(QFile &romfile)
{
    QDataStream read(&romfile);

    for(short i=1;i<=total_pkm_name;i++){
        rom_offset = 0x71B8A + i*23;
        romfile.seek(rom_offset);
        read>>pkm_base_hp[i];
        read>>pkm_base_atk[i];
        read>>pkm_base_def[i];
        read>>pkm_base_speed[i];
        read>>pkm_base_spc[i];

        read>>pkm_type_1[i];
        read>>pkm_type_2[i];
        read>>pkm_catch_rate[i];
        read>>pkm_base_experience[i];

        read>>pkm_start_move_1[i];
        read>>pkm_start_move_2[i];
        read>>pkm_start_move_3[i];
        read>>pkm_start_move_4[i];

        read>>pkm_growth_rate[i];

        read>>pkm_tmhm_flags[i][0];
        read>>pkm_tmhm_flags[i][1];
        read>>pkm_tmhm_flags[i][2];
        read>>pkm_tmhm_flags[i][3];
        read>>pkm_tmhm_flags[i][4];
        read>>pkm_tmhm_flags[i][5];
        read>>pkm_tmhm_flags[i][6];

        if(pkm_type_1[i]>19) pkm_type_1[i] -= 11;
        if(pkm_type_2[i]>19) pkm_type_2[i] -= 11;
    }

    // RB Level-up moves
    for(short i=1;i<=total_pkm_name;i++){
        rom_offset = 0x77FB00+(i*32);
        romfile.seek(rom_offset);
        for(short j=0;j<10;j++){
            read>>pkm_rb_lvl[i][j];
        }
        for(short j=0;j<10;j++){
            read>>pkm_rb_move[i][j];
        }
    }
    // Y Level-up moves
    for(short i=1;i<=total_pkm_name;i++){
        rom_offset = 0x780DE0+(i*32);
        romfile.seek(rom_offset);
        for(short j=0;j<10;j++){
            read>>pkm_y_lvl[i][j];
        }
        for(short j=0;j<10;j++){
            read>>pkm_y_move[i][j];
        }
    }
}
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();
}
Beispiel #3
0
quint8 fileType(QFile &file) {
    file.seek(sizeof(quint32)*5);
    quint8 type;
    QDataStream fStr(&file);
    fStr >> type;
    file.seek(0);
    return type;
}
void MainWindow::read_pokedex_data(QFile &romfile)
{
    // ***** Initialize Pokédex entries *****
    for (short i=0;i<256;i++){
        pokedex_entry[i] = "";
        pokedex_entry_pointer[i] = 0;
    }

    // ***** Retrieve number of Pokédex entries *****
    QDataStream read(&romfile);
    romfile.seek(0x785843);
    read>>total_pokedex_entry;

    if(total_pokedex_entry == 255){
        this->romtype=INVALID;
        ui->label_rom_debug->setText("Corrupted ROM");

        QMessageBox messageBox;
        messageBox.setText("Too many Pokédex entries, 254 is the max.");
        messageBox.setWindowTitle("Pokédex entries");
        messageBox.exec();
    }
    else{
        // ***** Retrieve Pokédex entries *****
        for(short i=1;i<=total_pokedex_entry;i++){
            // Retrieve Pokédex entry pointer
            rom_offset = 0x785842 + i*4;
            romfile.seek(rom_offset);
            read>>buf16;

            if(buf16 > 0x44D0){
                this->romtype=INVALID;
                ui->label_rom_debug->setText("Corrupted ROM");

                QMessageBox messageBox;
                messageBox.setText("Pokédex entries pointers are corrupted.");
                messageBox.setWindowTitle("Pokédex entries pointers");
                messageBox.exec();
            }
            else{
                pokedex_entry_pointer[i] = buf16;
                // Retrieve string
                rom_offset = 0x785840 + buf16;
                romfile.seek(rom_offset);
                read>>buf8;

                while(buf8 != 0 && buf8 != 0xFF && pokedex_entry[i].size()<192){
                    pokedex_entry[i] += char_table[buf8];
                    rom_offset++;
                    romfile.seek(rom_offset);
                    read>>buf8;
                }
            }
        }
    }
}
Beispiel #5
0
unsigned int FileTrans::readTransPos(QFile &file)
{
    unsigned int postemp = file.pos();  //push file pos
    file.seek(file.size()-4);
    QDataStream str(&file);
    str.setByteOrder(QDataStream::LittleEndian);
    unsigned int pos ;
    str>>pos;
    file.seek(postemp);    //pop file pos
    if(pos<file.size())
        return pos;
    else
        return 0;
}
void MainWindow::read_pkm_names(QFile &romfile)
{
    // ***** Retrieve number of Pokémon names *****
    QDataStream read(&romfile);
    romfile.seek(0x7950B3);
    read>>total_pkm_name;

    if(total_pkm_name == 255){
        this->romtype=INVALID;
        ui->label_rom_debug->setText("Corrupted ROM");

        QMessageBox messageBox;
        messageBox.setText("Too many Pokémon names, 254 is the max.");
        messageBox.setWindowTitle("Pokémon names");
        messageBox.exec();
    }
    else{
        // ***** Retrieve Pokémon names *****
        for(short i=1;i<=total_pkm_name;i++){
            // Retrieve string pointer
            rom_offset = 0x7950B2 + i*4;
            romfile.seek(rom_offset);
            read>>buf16;

            if(buf16 > 0x750){
                this->romtype=INVALID;
                ui->label_rom_debug->setText("Corrupted ROM");

                QMessageBox messageBox;
                messageBox.setText("Pokémon names pointers are corrupted.");
                messageBox.setWindowTitle("Pokémon names pointers");
                messageBox.exec();
            }
            else{
                pkm_name_pointer[i] = buf16;
                // Retrieve string
                rom_offset = 0x7950B0 + buf16;
                romfile.seek(rom_offset);
                read>>buf8;

                while(buf8 != 0 && buf8 != 0xFF && pkm_name[i].size()<11){
                    pkm_name[i] += char_table[buf8];
                    rom_offset++;
                    romfile.seek(rom_offset);
                    read>>buf8;
                }
            }
        }
    }
}
Beispiel #7
0
//----------------------------------------------------------------------------------
void tst_QIODevice::constructing_QFile()
{
    QFile file;
    QIODevice *device = &file;

    QVERIFY(!device->isOpen());

    file.setFileName(SRCDIR "tst_qiodevice.cpp");
    QVERIFY(file.open(QFile::ReadOnly));
    QVERIFY(device->isOpen());
    QCOMPARE((int) device->openMode(), (int) QFile::ReadOnly);

    char buf[1024];
    memset(buf, 0, sizeof(buf));
    qlonglong lineLength = device->readLine(buf, sizeof(buf));
    QVERIFY(lineLength > 0);
    QCOMPARE(file.pos(), lineLength);

    file.seek(0);
    char buf2[1024];
    memset(buf2, 0, sizeof(buf2));
    QCOMPARE(file.readLine(buf2, sizeof(buf2)), lineLength);

    char *c1 = buf;
    char *c2 = buf2;
    while (*c1 && *c2) {
        QCOMPARE(*c1, *c2);
        ++c1;
        ++c2;
    }
    QCOMPARE(*c1, *c2);
}
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;
}
Beispiel #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
qint64 RifEclipseInputFileTools::findKeyword(const QString& keyword, QFile& file, qint64 startPos)
{
    QString line;

    file.seek(startPos);

    do 
    {
        line = file.readLine();
        line = line.trimmed();

        if (line.startsWith("--", Qt::CaseInsensitive))
        {
            continue;
        }

        if (line.startsWith(keyword, Qt::CaseInsensitive))
        {
            return file.pos();
        }

    } while (!file.atEnd());


    return -1;
}
Beispiel #10
0
bool GameBoard::readBoardSize( QFile & map ) {
  if ( ! map.seek( 0 ) ) {
    return false;
  }

  this->width = 0;
  this->height = 0;

  QTextStream in( &map );

  QString line = in.readLine();
  while ( ! line.isNull() ) {
    int length = line.length();

    if ( length > this->width ) {
      this->width = length;
    }

    line = in.readLine();
    ++this->height;
  }

  if ( 5 > this->height || 5 > this->width ) {
    return false;
  }

  this->width += 2;
  this->height += 2;

  return true;
}
Beispiel #11
0
void WavSound::play() {
    QFile *file = new QFile(fileName);
    file->open(QIODevice::ReadOnly);
    QAudioFormat f;
    readHeader(&f, file);

    QAudioFormat format = f;

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Raw audio format not supported by backend, cannot play audio.";
        return;
    }

    //seek(0x4e*4); //...avoiding clicks from the wav files

    file->seek(0x4e);

    QAudioOutput *audio = new QAudioOutput(format, NULL);
    if(file->size()<30000)
        audio->setBufferSize(10000);

    audio->setVolume(0.5);
    connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));
    audio->start(file);
}
Beispiel #12
0
//static
int SoundSourceWV::SetPosAbsCallback(void* id, unsigned int pos)
{
    QFile* pFile = static_cast<QFile*>(id);
    if (!pFile) {
        return 0;
    }
    return pFile->seek(pos) ? 0 : -1;
}
Beispiel #13
0
void Robotino::readFileHeader(QFile& file)
{
  unsigned buflen = 20;
  char buffer[buflen];

  recordSize = 0;
  file.seek(0);
  file.readLine(buffer, buflen);
  while(!file.atEnd() && strncmp(buffer,"end", strlen("end"))!=0)
  {
    if(strncmp(buffer,"action:", strlen("action:"))==0)
    {
      actionOffset = recordSize;
      actionSize = atoi(buffer+strlen("action:"));
      recordSize += actionSize;
    }
    else if(strncmp(buffer,"distance:", strlen("distance:"))==0)
    {
      distanceOffset = recordSize;
      distanceSize = atoi(buffer+strlen("distance:"));
      recordSize += distanceSize;
    }
    else if(strncmp(buffer,"accel:", strlen("accel:"))==0)
    {
      accelOffset = recordSize;
      accelSize = atoi(buffer+strlen("accel:"));
      recordSize += accelSize;
    }
    else if(strncmp(buffer,"current:", strlen("current:"))==0)
    {
      currentOffset = recordSize;
      currentSize = atoi(buffer+strlen("current:"));
      recordSize += currentSize;
    }
    else if(strncmp(buffer,"power:", strlen("power:"))==0)
    {
      powerOffset = recordSize;
      powerSize = atoi(buffer+strlen("power:"));
      recordSize += powerSize;
    }
    else if(strncmp(buffer,"bumper:", strlen("bumper:"))==0)
    {
      bumperOffset = recordSize;
      bumperSize = atoi(buffer+strlen("bumper:"));
      recordSize += bumperSize;
    }
    else if(strncmp(buffer,"audio:", strlen("audio:"))==0)
    {
      audioOffset = recordSize;
      audioSize = atoi(buffer+strlen("audio:"));
      recordSize += audioSize;
    }
    file.readLine(buffer, buflen);
  }
  headerSize = file.pos();
  //std::cout << "Fertig" << std::endl;
}
Beispiel #14
0
//static
int SoundSourceWV::SetPosRelCallback(void *id, int delta, int mode)
{
    QFile* pFile = static_cast<QFile*>(id);
    if (!pFile) {
        return 0;
    }

    switch(mode) {
    case SEEK_SET:
        return pFile->seek(delta) ? 0 : -1;
    case SEEK_CUR:
        return pFile->seek(pFile->pos() + delta) ? 0 : -1;
    case SEEK_END:
        return pFile->seek(pFile->size() + delta) ? 0 : -1;
    default:
        return -1;
    }
}
Beispiel #15
0
int qfileSeekCallback( void * _udata, ogg_int64_t _offset, int _whence )
{
	QFile * f = static_cast<QFile *>( _udata );

	if( _whence == SEEK_CUR )
	{
		f->seek( f->pos() + _offset );
	}
	else if( _whence == SEEK_END )
	{
		f->seek( f->size() + _offset );
	}
	else
	{
		f->seek( _offset );
	}
	return 0;
}
Beispiel #16
0
//static
int SoundSourceOggVorbis::SeekCallback(void *datasource, ogg_int64_t offset,
       int whence) {
   QFile* pFile = static_cast<QFile*>(datasource);
   if (!pFile) {
       return 0;
   }

   switch(whence) {
   case SEEK_SET:
       return pFile->seek(offset) ? 0 : -1;
   case SEEK_CUR:
       return pFile->seek(pFile->pos() + offset) ? 0 : -1;
   case SEEK_END:
       return pFile->seek(pFile->size() + offset) ? 0 : -1;
   default:
       return -1;
   }
}
bool extractLoaderAndSecondaryFromMtd()
{
#ifdef Q_WS_MAEMO_5
    QProcess *shell = new QProcess;
    QString command = "sh -c \"echo dd if=/dev/mtd0 of=%1 | root\"";
    command = command.arg(mtdOutPath);
    shell->start(command);
    shell->waitForFinished();
    shell->close();
    delete shell;
    shell = 0;
#endif
    // get xloader and secondary
    // xloader size = 14848 bytes, from 0
    // secondary size = 109440 bytes, from xloader + 0x600

    QFile mtd (mtdOutPath);
    QFile xloader (xloaderPath);
    QFile secondary (secondaryPath);

    if (mtd.open(QIODevice::ReadOnly) == false)
    {
        // error
        return false;
    }
    if (xloader.open(QIODevice::WriteOnly) == false)
    {
        // error
        mtd.close();
        return false;
    }
    if (secondary.open(QIODevice::WriteOnly) == false)
    {
        // error
        mtd.close();
        xloader.close();
        return false;
    }

    QDataStream xloaderStream(&xloader);
    QDataStream secondaryStream(&secondary);

    QByteArray mtdArray = mtd.readAll();
    xloaderStream.writeRawData(mtdArray, 0x3A00); // 14848 bytes

    mtd.seek(0x3A00 + 0x600);
    mtdArray = mtd.readAll();
    secondaryStream.writeRawData(mtdArray, 0x1AB80); // 109440 bytes

    mtd.close();
    xloader.close();
    secondary.close();

    return true;
}
Beispiel #18
0
Frame::ptr SERImagerWorker::shoot()
{
  QElapsedTimer elapsed;
  elapsed.start();
  auto frame = make_shared<Frame>(pixel_depth, color_format, resolution);
  file.seek(sizeof(header) + (frame_size * current_frame++) );
  file.read(reinterpret_cast<char*>(frame->data()), frame_size);
  if(current_frame >= header.frames)
    current_frame = 0;
  QThread::currentThread()->msleep( (1.0 / fps * 1000.) - elapsed.elapsed() );
  return frame;
}
Beispiel #19
0
void DecodeAudioFile::WriteWavHeadToFile(QFile &f,int outLen, int sampleRate, int sampleSize, int channel)
{
    WAVFMT wavHeader ;
    wavHeader.RIFF[0] = 'R';
    wavHeader.RIFF[1] = 'I';
    wavHeader.RIFF[2] = 'F';
    wavHeader.RIFF[3] = 'F';

    wavHeader.totalSize = 44 + outLen;

    wavHeader.WAVE[0] = 'W';
    wavHeader.WAVE[1] = 'A';
    wavHeader.WAVE[2] = 'V';
    wavHeader.WAVE[3] = 'E';

    wavHeader.FMT[0] = 'f';
    wavHeader.FMT[1] = 'm';
    wavHeader.FMT[2] = 't';
    wavHeader.FMT[3] = ' ';

    wavHeader.FILTER = 0x00000010;
    wavHeader.formatTag = 1;
    wavHeader.channels = channel;
    wavHeader.sampleRate = sampleRate;
    wavHeader.bytesPerSec = sampleRate*sampleSize*channel/8;
    wavHeader.bytesInSample = sampleSize/8;
    wavHeader.bitsDepth = sampleSize;

    wavHeader.DATA[0] = 'd';
    wavHeader.DATA[1] = 'a';
    wavHeader.DATA[2] = 't';
    wavHeader.DATA[3] = 'a';

    wavHeader.dataSize = outLen;
    int pos = f.pos();
    f.seek(0);
    f.write((char*)&wavHeader,sizeof(WAVFMT));
    f.seek(pos);
    f.flush();
}
Beispiel #20
0
void Lib_dialog::open(){


    QString Name = QFileDialog::getOpenFileName(NULL,tr("Open function"), ".",tr("Project files (*.txt)"));
    if (Name.isEmpty()){
        return;
    }
    QFile * file = new QFile (Name);
    if (!file->open(QIODevice::ReadOnly)) {
        return;

    }

    { /*fseek ( file ,0 , SEEK_END );*/
        size_t size;
        size_t count;
        int i=0;
        char *ptr;
        ptr = new char [10];
        size=10;
        count=1;
        int lastseek=0;
        bool ok=true;
        StructXY lol;
        fx.free();
        bool ok1=false;
        while (!file->atEnd()) {
            ok=!ok;
            file->read(ptr,size);
            // fread (ptr,  size,  count,file);
            float sx=atof(ptr);
            if (ok) {
                lol.y=sx;
                fx+lol;
            } else {lol.x=sx;}

            i=0;
            while( !((ptr[i] ==' ') || (ptr[i]=='\n')) )
            {i++;
                if (ptr[i]=='_') break;
            }
            if (ok1) {file->close(); draw();}
            if (ptr[i]=='\n') {i++;}
            if (ptr[i]=='_') break;
            lastseek=lastseek+i+1;
            file->seek(lastseek);
        }


        file->close();}
    return;
}
void MainWindow::write_type_chart(QFile &romfile)
{
    QDataStream write(&romfile);

    rom_offset = 0x3755B0;
    romfile.seek(rom_offset);

    for(short i=0;i<82;i++){
        write<<type_chart[i].getType1();
        write<<type_chart[i].getType2();
        write<<type_chart[i].getMultiplier();
    }
}
Beispiel #22
0
bool ReaderDataBlockHeader::find(DataBlockHeader* outHeader, QFile& fin) {
    unsigned char buffer[BUFFER_SIZE];

    unsigned int nReadBytes;

    while ((nReadBytes = fin.read(reinterpret_cast<char*>(buffer), BUFFER_SIZE)) >
            HEADER_SIZE) {
        unsigned char* findPos =
            std::search(buffer, buffer + nReadBytes + 1, JAA::ARCHIVER_ID,
                        JAA::ARCHIVER_ID + JAA::ARCHIVER_ID_SIZE);

        if (findPos == buffer + nReadBytes + 1) {
            fin.seek(-(std::streamoff)(HEADER_SIZE - 1) + fin.pos());
        } else {
            // found at findPos

            if ((BUFFER_SIZE - (findPos - buffer)) > HEADER_SIZE) {
                // enough space in buffer

                outHeader->setData(findPos);

                if (!outHeader->checkCRC()) {
                    // valid CRC
                    fin.seek(-(std::streamoff)(nReadBytes - (findPos - buffer) - HEADER_SIZE) + fin.pos());
                    return false;
                } else {
                    // not valid CRC may be not header?
                    fin.seek(-static_cast<std::streamoff>(nReadBytes - (findPos - buffer) - 2) + fin.pos());
                    // try again with offset
                }
            } else {
                // not enough space
                fin.seek(-(nReadBytes - (findPos - buffer) - 1) + fin.pos());
            }
        }
    }

    return true;
}
Beispiel #23
0
/*
 * If we have created a temporary file, we have
 * to decompress the original file now and write
 * the contents to the temporary file.
 */
bool KTar::KTarPrivate::fillTempFile( const QString & fileName) {
    if ( ! tmpFile )
        return true;

    //qDebug() << "filling tmpFile of mimetype" << mimetype;

    KCompressionDevice::CompressionType compressionType = KFilterDev::compressionTypeForMimeType(mimetype);
    KCompressionDevice filterDev(fileName, compressionType);

    QFile* file = tmpFile;
    Q_ASSERT(file->isOpen());
    Q_ASSERT(file->openMode() & QIODevice::WriteOnly);
    file->seek(0);
    QByteArray buffer;
    buffer.resize(8*1024);
    if ( ! filterDev.open( QIODevice::ReadOnly ) )
    {
        return false;
    }
    qint64 len = -1;
    while ( !filterDev.atEnd() && len != 0 ) {
        len = filterDev.read(buffer.data(),buffer.size());
        if ( len < 0 ) { // corrupted archive
            return false;
        }
        if ( file->write(buffer.data(), len) != len ) { // disk full
            return false;
        }
    }
    filterDev.close();

    file->flush();
    file->seek(0);
    Q_ASSERT(file->isOpen());
    Q_ASSERT(file->openMode() & QIODevice::ReadOnly);

    //qDebug() << "filling tmpFile finished.";
    return true;
}
void MainWindow::read_experience_data(QFile &romfile)
{
    QDataStream read(&romfile);
    romfile.seek(0x7DE453);

    for(uint8_t i=0;i<6;i++){
        read>>experience_param_1[i];
        if(i<4){
            read>>experience_param_2[i];
            read>>experience_param_3[i];
            read>>experience_param_4[i];
        }
        else{
Beispiel #25
0
void FileWriter::writeHeader(QDataStream & dataStream, QFile & file, AssetInformation & info)
{
    if (info.properties().empty())
        return;

    dataStream << static_cast<quint16>(RawFile::s_signature);

    quint64 rawDataOffsetPosition = file.pos();
    dataStream << static_cast<quint64>(0);

    QMapIterator<QVariantMap::key_type, QVariantMap::mapped_type> iterator(info.properties());

    while (iterator.hasNext())
    {
        iterator.next();

        QString key = iterator.key();
        QVariant value = iterator.value();

		RawFile::PropertyType type = propertyType(value.type());

        if (type == RawFile::PropertyType::Unknown)
            continue;

        dataStream << static_cast<uint8_t>(type);
        writeString(dataStream, key);

        writeValue(dataStream, value);
    }

    quint64 rawDataOffset = file.pos();

    file.seek(rawDataOffsetPosition);
    dataStream << rawDataOffset;
    file.seek(rawDataOffset);
}
Beispiel #26
0
//-------------------------------------------------------------------------------------------
void AsciiDataReader::detectLineEndingType(QFile& file)
{
  QByteArray line;
  int line_size = 0;
  while (line_size < 2 && !file.atEnd()) {
    line = file.readLine();
    line_size = line.size();
  }
  file.seek(0);
  if (line_size < 2) {
    _lineending = LineEndingType();
  } else {
    _lineending.is_crlf = line[line_size - 2] == '\r' && line[line_size - 1] == '\n' ;
    _lineending.character =  _lineending.is_crlf ? line[line_size - 2] : line[line_size - 1];
  }
}
Beispiel #27
0
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));
}
Beispiel #28
0
void Table_Control::saveTablesInfo(QFile &archivo, int sizeBlock, int HeadSize){
    for(int i=0;i<this->metaData.count();i++){
        archivo.write(reinterpret_cast<char*>(&this->metaData[i]),sizeof(MetaDataTable));
    }
    qDebug()<<"Cantidad campo to save:"<<this->campos.count();
    QMap<int,Table_Fields>::ConstIterator it;
    for(it=this->campos.constBegin();it!=this->campos.constEnd();it++){
        Table_Fields tempField=it.value();
        archivo.seek(HeadSize+this->metaData.at(it.key()).pointerToFields*sizeBlock);
        qDebug()<<archivo.pos();
        for(int i=0;i<tempField.campos.count();i++){
            qDebug()<<tempField.campos[i].name<<i<<HeadSize+this->metaData.at(it.key()).pointerToFields*sizeBlock+(i*sizeof(Field))<<it.key()<<this->metaData.at(it.key()).pointerToFields*sizeBlock;
            archivo.write(reinterpret_cast<char*>(&tempField.campos[i]),sizeof(Field));
        }
    }
    this->campos.clear();
}
Beispiel #29
0
bool
TrackFileReader::_readXml(QFile &theFile,
                          QList<Track*> *tracks,
                          std::string *whyNot) const
{
    QString error;
    theFile.open(QIODevice::ReadOnly);
    TrackFileType fileType = getXmlType(&theFile, &error);
    theFile.seek(0);
    switch (fileType) {
    case TrackFileType_Gpx:
        {
        GpxHandler gpxHandler(tracks);
        bool ok = gpxHandler.parse(&theFile);
        if (!ok && whyNot) {
            whyNot->assign(gpxHandler.getError().toStdString());
        }
        return ok;
        break;
        }
    case TrackFileType_Tcx:
        {
        TcxHandler tcxHandler(tracks);
        bool ok = tcxHandler.parse(&theFile);
        if (!ok && whyNot) {
            whyNot->assign(tcxHandler.getError().toStdString());
        }
        return ok;
        break;
        }
    default:
        {
        if (whyNot) {
            if (!error.isEmpty()) {
                *whyNot = error.toStdString();
            } else {
                *whyNot = "Unrecognized file type";
            }
        }
        return false;
        break;
        }
    }
    return true;
}
void PeerObject::readSocketDescriptor()
{
	int	fd	=	m_socket->read().toSocketDescriptor();

// 	qDebug(">>> readSocketDescriptor() : %x", fd);

	QFile		file;

	// Try to open file
	if(!file.open(fd, QIODevice::ReadOnly))
	{
		file.seek(0);
		qDebug("Peer: PeerObject::readSocketDescriptor() - coudl not open file");

		m_peerSocket->write(QStringLiteral("fReceived invalid file descriptor").toLatin1());
// 		m_peerSocket->flush();

		if(m_close)
			close(1);

		return;
	}

	// Get filename
	QString	filename(QString::fromUtf8(file.readAll().trimmed()));

// 	qDebug("File is: %s (size: %lld)", qPrintable(filename), file.size());

	// Save filename
	QWriteLocker		writeLocker(&m_dataFDLock);
	m_dataFD.append(filename);

	// Close file
	file.close();

	static int totalReadFDCount	=	0;
	totalReadFDCount++;
	Logger::log("Handled file descriptors", totalReadFDCount);

	callSlotQueued(this, "checkReadData");
}