/** \file QTarDecode.cpp \brief To read a tar data block \author alpha_one_x86 \version 0.3 \date 2010 \licence GPL3, see the file COPYING */ #include "QTarDecode.h" #include QTarDecode::QTarDecode() { error="Unknow error"; } QString QTarDecode::errorString() { return error; } void QTarDecode::setErrorString(QString error) { this->error=error; fileList.clear(); dataList.clear(); } bool QTarDecode::decodeData(QByteArray data) { setErrorString("Unknow error"); if(data.size()<1024) return false; int offset=0; while(offsetdata.size()) { setErrorString("The tar file seem be too short"); return false; } if(fileType=="0") //this code manage only the file, then only the file is returned { QByteArray fileData=data.mid(512+offset,finalSize); fileList << fileName; dataList << fileData; } //calculate the offset for the next header bool retenu=((finalSize%512)!=0); //go to the next header offset+=512+(finalSize/512+retenu)*512; } if(fileList.size()>0) { QString baseDirToTest=fileList.at(0); baseDirToTest.remove(QRegExp("/.*$")); baseDirToTest+='/'; bool isFoundForAllEntries=true; for (int i = 0; i < fileList.size(); ++i) if(!fileList.at(i).startsWith(baseDirToTest)) isFoundForAllEntries=false; if(isFoundForAllEntries) for (int i = 0; i < fileList.size(); ++i) fileList[i].remove(0,baseDirToTest.size()); } return true; } QStringList QTarDecode::getFileList() { return fileList; } QList QTarDecode::getDataList() { return dataList; }