/*------------------------------------------------------------------------------ -- This file is a part of the SocExplorer Software -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ #include "binaryfile.h" binaryFile::binaryFile() { } binaryFile::binaryFile(const QString &File) { openFile(File); } binaryFile::binaryFile(const QStringList &Files) { openFiles(Files); } binaryFile::~binaryFile() { } bool binaryFile::openFile(const QString &File) { return openFiles(QStringList()<p_fileNames.clear(); this->p_fileNames.append(Files); for(int i=0;ip_files.clear(); for(int i=0;ip_files.append(new QFile(Files.at(i))); this->p_files.at(i)->open(QIODevice::ReadOnly); loadFile(this->p_files.at(i)); } return true; } bool binaryFile::isopened() { bool opened = true; for(int i=0;ip_files.count();i++) { opened &= p_files.at(i)->isOpen(); } return opened; } int binaryFile::closeFile() { for(int i=0;iheader == p_files.at(i)->fileName()) { codeFragment* fragment = p_fragments.at(j); p_fragments.removeAt(j); free(fragment->data); delete fragment; } } } p_files.clear(); p_fileName.clear(); return 0; } QList binaryFile::getFragments() { return p_fragments; } int binaryFile::getFragmentsCount() { return p_fragments.count(); } int binaryFile::getFragmentAddress(int index) { if((index>=0)&&(indexaddress; return 0; } int binaryFile::getFragmentSize(int index) { if((index>=0)&&(indexsize; return 0; } QString binaryFile::getFragmentHeader(int index) { if((index>=0)&&(indexheader; return ""; } bool binaryFile::getFragmentData(int index, char **buffer) { if((index>=0)&&(indexdata; return true; } return false; } void binaryFile::loadFile(QFile *file) { if (file->isOpen()) { codeFragment* fragment = new codeFragment(); fragment->header = file->fileName(); fragment->address = 0; fragment->size = file->size(); fragment->data = (char*)malloc(file->size()); file->read(fragment->data,file->size()); p_fragments.append(fragment); } }