Beispiel #1
0
int get4(QFile& file) {
	char ch;
	file.getChar(&ch);
	int res = ch & 0xff;
	file.getChar(&ch);
	res |= (ch << 8);
	file.getChar(&ch);
	res |= (ch << 16);
	file.getChar(&ch);
	res |= (ch << 24);
	return res;
}
Beispiel #2
0
/**OK
 * Comprime il file fileName, nell'oggetto zip, con il nome fileDest.
 *
 * La funzione fallisce se:
 * * zip==NULL;
 * * l'oggetto zip è stato aperto in una modalità non compatibile con l'aggiunta di file;
 * * non è possibile aprire il file d'origine;
 * * non è possibile creare il file all'interno dell'oggetto zip;
 * * si è rilevato un errore nella copia dei dati;
 * * non è stato possibile chiudere il file all'interno dell'oggetto zip;
 */
bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) {
    // zip: oggetto dove aggiungere il file
    // fileName: nome del file reale
    // fileDest: nome del file all'interno del file compresso

    // Controllo l'apertura dello zip
    if (!zip) return false;
    if (zip->getMode()!=QuaZip::mdCreate &&
        zip->getMode()!=QuaZip::mdAppend &&
        zip->getMode()!=QuaZip::mdAdd) return false;

    // Apro il file originale
    QFile inFile;
    inFile.setFileName(fileName);
    if(!inFile.open(QIODevice::ReadOnly)) return false;

    // Apro il file risulato
    QuaZipFile outFile(zip);
    if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName()))) return false;

    // Copio i dati
    char c;
    while(inFile.getChar(&c)&&outFile.putChar(c));
    if(outFile.getZipError()!=UNZ_OK) return false;

    // Chiudo i file
    outFile.close();
    if (outFile.getZipError()!=UNZ_OK) return false;
    inFile.close();

    return true;
}
// ====================================================================================================================
// 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;
    }
}
Replayer::Replayer(QObject *parent, const QString &filename)
    : QThread(parent), m_commandSeriesCounter(1),
    filename(filename), speed(1.0), playing(true)
{
    QIODevice *device = NULL;
    if (filename.endsWith(".png")) {
        QByteArray *data = new QByteArray(PNG2TXT(filename));
        device = new QBuffer(data);
    } else if (filename.endsWith(".qsgs")) {
        QFile *file = new QFile(filename);
        if (file->open(QFile::ReadOnly)) {
            char header;
            file->getChar(&header);
            if (header == '\0') {
                QByteArray content = file->readAll();
                delete file;

                QByteArray *data = new QByteArray(qUncompress(content));
                device = new QBuffer(data);
            } else {
                file->close();
                device = file;
            }
        } else {
            return;
        }
    }

    if (device == NULL)
        return;

    if (!device->open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    while (!device->atEnd()) {
        QByteArray line = device->readLine();
        int split = line.indexOf(' ');

        Pair pair;
        pair.elapsed = line.left(split).toInt();
        pair.cmd = line.mid(split + 1);

        pairs << pair;
    }

    delete device;

    int time_offset = 0;
    pair_offset = 0;
    foreach (const Pair &pair, pairs) {
        Packet packet;
        if (packet.parse(pair.cmd)) {
            if (packet.getCommandType() == S_COMMAND_START_IN_X_SECONDS) {
                time_offset = pair.elapsed;
                break;
            }
        }
        pair_offset++;
    }
Beispiel #5
0
QString read_ASCIIZ( QFile &src)
{
    char name[1000];
    int i = 0;
	unsigned char c = 0;
	while (src.getChar((char*)&c) && c != 0)
        name[ i++ ] = c;
    name[ i ] = 0;
    return QString(name);
}
Beispiel #6
0
bool Project::save()
{
    saveOpenTexts();
    serializeConfigurationXml();

    // indebted to: http://stackoverflow.com/questions/2598117/zipping-a-folder-file-using-qt
    QuaZip zip(mProjectPath);
    QuaZipFile outFile(&zip);

    if (!zip.open(QuaZip::mdCreate))
    {
        qWarning() << "zip.open()" << zip.getZipError();
        return false;
    }
    char c;
    QFile inFile;
    QDir tempDir = getTempDir();
    tempDir.setNameFilters(QStringList("*"));
    QStringList files = tempDir.entryList(QDir::Files,QDir::Name);
    for(int i=0; i<files.count(); i++)
    {
        inFile.setFileName( tempDir.absoluteFilePath(files.at(i)) );
        if( !inFile.open(QIODevice::ReadOnly))
        {
            qWarning() << inFile.errorString();
            return false;
        }
        if( !outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(files.at(i) , tempDir.absoluteFilePath(files.at(i)) )))
        {
            qWarning() << outFile.errorString();
            return false;
        }
        while (inFile.getChar(&c) && outFile.putChar(c));

        if (outFile.getZipError() != UNZ_OK)
        {
            qWarning() << outFile.getZipError();
            return false;
        }

        outFile.close();

        if (outFile.getZipError() != UNZ_OK)
        {
            qWarning() << outFile.getZipError();
            return false;
        }

        inFile.close();
    }

    mChanged = false;

    return true;
}
bool KTPackageHandler::compress(QuaZip *zip, const QString &path)
{
	QFile inFile;
	QuaZipFile outFile(zip);
	char c;
	
	QFileInfoList files= QDir(path).entryInfoList();
	
	foreach(QFileInfo file, files)
	{
		QString filePath = path+"/"+file.fileName();
		
		
		if ( file.fileName().startsWith(".") ) continue;
		
		if ( file.isDir() )
		{
			compress(zip, file.path()+"/"+file.fileName());
			continue;
		}
		
		inFile.setFileName(filePath);
		if(!inFile.open(QIODevice::ReadOnly)) 
		{
			dError() << "Error opening file " << inFile.fileName() << " : " << inFile.errorString();
			return false;
		}
		
		if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(stripRepositoryFromPath(filePath), stripRepositoryFromPath(filePath) ))) 
		{
			return false;
		}
		while(inFile.getChar(&c) && outFile.putChar(c));
		
		if(outFile.getZipError()!=UNZ_OK)
		{
			return false;
		}
		outFile.close();
		if(outFile.getZipError()!=UNZ_OK)
		{
			return false;
		}
		inFile.close();
	}
Beispiel #8
0
void QZip::zipDir(QuaZipFile &outFile,const QString &zipPath,const QString &zipTPath){
    QDir dir(zipPath);
    dir.setCurrent(zipPath);
    QFileInfoList files=dir.entryInfoList();

    QFile inFile;
    char c;
    foreach(QFileInfo file, files) {
        if(file.isDir()){
            if(!file.absoluteFilePath().endsWith(".")){
                QString zipDirecName = zipTPath==""?file.fileName():zipTPath+"\\"+file.fileName();
                zipDir(outFile,file.absoluteFilePath(),zipDirecName);
                dir.setCurrent(zipPath);
            }
            continue;//
        }
        inFile.setFileName(file.fileName());
        if(!inFile.open(QIODevice::ReadOnly)) {
            qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
            return;
        }
        QString zipDirName = zipTPath==""?inFile.fileName():zipTPath+"\\"+inFile.fileName();
        if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(zipDirName, inFile.fileName()))) {
            qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
            return;
        }
        while(inFile.getChar(&c)&&outFile.putChar(c));
        if(outFile.getZipError()!=UNZ_OK) {
            qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
            return;
        }
        outFile.close();
        if(outFile.getZipError()!=UNZ_OK) {
            qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
            return;
        }
        inFile.close();
    }
}
Beispiel #9
0
void read_color_chunk( float color[], QFile &src )
{
    TA3D_3DS_CHUNK_DATA chunk;
	src.read( (char*)&chunk.ID, 2 );
	src.read( (char*)&chunk.length, 4 );
    switch( chunk.ID )
    {
    case COL_RGB:
    case COL_RGB2:
		src.read( (char*)color, sizeof( float ) * 3 );
        break;
    case COL_TRU:
    case COL_TRU2:
        for( int i = 0 ; i < 3 ;i++ )
		{
			unsigned char c;
			src.getChar((char*)&c);
			color[ i ] = c / 255.0f;
		}
        break;
    default:
		src.read( chunk.length - 6 );
    };
}
Beispiel #10
0
inline int KFileReaderPrivate::next()
{
  if (!m_file.getChar(&m_currChar))
    return KFileReader::EndOfFile;
 return m_currChar;
}