1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XGUI_CompressFiles.h"
25 #include <QDataStream>
30 bool XGUI_CompressFiles::compress(const QString& theFile, std::list<std::string> theFiles)
32 QFile aOutFile(theFile);
33 if (aOutFile.open(QIODevice::WriteOnly)) {
34 QDataStream aOutStream(&aOutFile);
36 std::list<std::string>::const_iterator aIt;
37 for (aIt = theFiles.cbegin(); aIt != theFiles.cend(); ++aIt) {
38 QString aPathName((*aIt).c_str());
39 QFile aSrcFile(aPathName);
40 QFileInfo aInfo(aSrcFile);
41 quint64 aSize = aInfo.size();
42 if (aSrcFile.open(QIODevice::ReadOnly)) {
44 aPathName.right(aPathName.length() - aPathName.lastIndexOf(QDir::separator()) - 1);
46 aOutStream << aName << aSize << qCompress(aSrcFile.readAll());
63 bool XGUI_CompressFiles::uncompress(const QString& theFile, const QString& theDir)
65 QFile aInFile(theFile);
69 if (!aDir.isEmpty()) {
70 if (!aDir.removeRecursively())
75 if (aInFile.open(QIODevice::ReadOnly)) {
76 QDataStream aInStream(&aInFile);
80 aInStream >> aFileName;
83 QFile aOutFile(theDir + QDir::separator() + aFileName);
84 if (aOutFile.open(QIODevice::WriteOnly)) {
86 aContent.resize(aSize);
87 aInStream >> aContent;
88 aOutFile.write(qUncompress(aContent));
91 } while (!aInStream.atEnd());