2008-05-11 17:21:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Dominik Wenger
|
2008-06-30 22:09:45 +00:00
|
|
|
* $Id$
|
2008-05-11 17:21:14 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "rbzip.h"
|
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
|
2008-05-11 18:22:42 +00:00
|
|
|
Zip::ErrorCode RbZip::createZip(QString zip,QString dir)
|
2008-05-11 17:21:14 +00:00
|
|
|
{
|
|
|
|
Zip::ErrorCode error = Ok;
|
|
|
|
m_curEntry = 1;
|
2008-05-11 18:22:42 +00:00
|
|
|
m_numEntrys=0;
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 17:21:14 +00:00
|
|
|
QCoreApplication::processEvents();
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 17:21:14 +00:00
|
|
|
// get number of entrys in dir
|
|
|
|
QDirIterator it(dir, QDirIterator::Subdirectories);
|
2009-03-30 22:05:21 +00:00
|
|
|
while (it.hasNext())
|
2008-05-11 17:21:14 +00:00
|
|
|
{
|
|
|
|
it.next();
|
2008-05-11 18:22:42 +00:00
|
|
|
m_numEntrys++;
|
2008-05-11 17:21:14 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
}
|
2008-05-11 18:22:42 +00:00
|
|
|
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 17:21:14 +00:00
|
|
|
//! create zip
|
|
|
|
error = Zip::createArchive(zip);
|
|
|
|
if(error != Ok)
|
|
|
|
return error;
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 17:21:14 +00:00
|
|
|
//! add the content
|
|
|
|
error = Zip::addDirectory(dir);
|
|
|
|
if(error != Ok)
|
|
|
|
return error;
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 17:21:14 +00:00
|
|
|
//! close zip
|
|
|
|
error = Zip::closeArchive();
|
2009-03-30 22:05:21 +00:00
|
|
|
|
2008-05-11 18:22:42 +00:00
|
|
|
return error;
|
2008-05-11 17:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RbZip::progress()
|
|
|
|
{
|
|
|
|
m_curEntry++;
|
2008-05-11 18:22:42 +00:00
|
|
|
emit zipProgress(m_curEntry,m_numEntrys);
|
2008-05-11 17:21:14 +00:00
|
|
|
QCoreApplication::processEvents(); // update UI
|
|
|
|
}
|
|
|
|
|
|
|
|
|