Take cluster size into account when calculating zip extracted size.

Allow passing an (optional) cluster size to round up all file sizes when
calculating the total size of an extracted zip archive. This allows to check if
the space on disk is actually sufficient without relying on an arbitrary
headroom value which might be wrong. Addresses FS#12195.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30214 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2011-07-26 20:54:44 +00:00
parent 3bb0fed345
commit 743308e882
5 changed files with 51 additions and 10 deletions

View file

@ -205,7 +205,7 @@ bool ZipUtil::appendFileToArchive(QString& file, QString& basedir)
//! @brief calculate total size of extracted files
qint64 ZipUtil::totalUncompressedSize(void)
qint64 ZipUtil::totalUncompressedSize(unsigned int clustersize)
{
qint64 uncompressed = 0;
@ -214,10 +214,23 @@ qint64 ZipUtil::totalUncompressedSize(void)
return -1;
}
int max = items.size();
for(int i = 0; i < max; ++i) {
uncompressed += items.at(i).uncompressedSize;
if(clustersize > 0) {
for(int i = 0; i < max; ++i) {
qint64 item = items.at(i).uncompressedSize;
uncompressed += (item + clustersize - (item % clustersize));
}
}
qDebug() << "[ZipUtil] size of archive files uncompressed:" << uncompressed;
else {
for(int i = 0; i < max; ++i) {
uncompressed += items.at(i).uncompressedSize;
}
}
if(clustersize > 0) {
qDebug() << "[ZipUtil] calculation rounded to cluster size for each file:"
<< clustersize;
}
qDebug() << "[ZipUtil] size of archive files uncompressed:"
<< uncompressed;
return uncompressed;
}