From 329f6561f24b56fb684795184d2d688a6bf60f4e Mon Sep 17 00:00:00 2001 From: mrbesen Date: Thu, 12 Jan 2023 21:01:14 +0100 Subject: [PATCH] file size of folders and extract compressed files. --- include/resourceexplorer.h | 1 + src/resourceexplorer.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/resourceexplorer.h b/include/resourceexplorer.h index aed06c2..3064cb5 100644 --- a/include/resourceexplorer.h +++ b/include/resourceexplorer.h @@ -51,6 +51,7 @@ private: bool isDir() const; bool isCompressed() const; + uint64_t getByteSize() const; }; using data = const unsigned char*; diff --git a/src/resourceexplorer.cpp b/src/resourceexplorer.cpp index 1aec571..a90ce1b 100644 --- a/src/resourceexplorer.cpp +++ b/src/resourceexplorer.cpp @@ -75,6 +75,11 @@ void ResourceExplorer::extractButtonPressed() { if( !fileOut.open( QIODevice::WriteOnly | QIODevice::Truncate )) return; QByteArray data = QByteArray::fromRawData( (const char*) node->start, node->size ); + + if ( node->isCompressed() ) { + data = qUncompress(data); + } + fileOut.write(data); } @@ -84,7 +89,7 @@ void ResourceExplorer::itemSelected(QTreeWidgetItem* newItem) { ResourceNode* node = (ResourceNode*) newItem->data(0, Qt::UserRole).toULongLong(); if ( node ) { - if ( !node->isDir() && !node->isCompressed() ) { + if ( !node->isDir() ) { this->ui->extractButton->setEnabled( true ); return; } @@ -106,6 +111,13 @@ bool ResourceExplorer::ResourceNode::isCompressed() const { return this->flags & ResourceFlags::Compressed; } +uint64_t ResourceExplorer::ResourceNode::getByteSize() const { + if ( this->isDir() ) { + return std::accumulate( children.begin(), children.end(), 0, [](uint64_t v, const ResourceNode* b) { return v + b->getByteSize(); } ); + } + return size; +} + void ResourceExplorer::rebuild() { this->ui->treeWidget->clear(); this->ui->extractButton->setEnabled(false); @@ -183,6 +195,9 @@ std::vector ResourceExplorer::readMemoryMaps() { return out; } +// reads an UTF-16 String into a QString +// the problem is that the input string is in bigendian. +// this function makes a copy and swaps every two bytes if required static QString readUTF16String(const char16_t* ptr, uint32_t size) { char16_t* newptr = new char16_t[size]; @@ -267,16 +282,24 @@ QTreeWidgetItem* ResourceExplorer::resourceNodeToItem( ResourceNode* node, const const QString ownPath = path + node->name; item->setText( 0, node->isDir() ? (node->name + "/" ) : node->name); - item->setToolTip(0, ownPath); if ( node->isDir() ) { std::size_t size = node->children.size(); - item->setText( 1, QString::number( size ) ); - item->setToolTip( 1, QString::number( size ) ); + item->setText(1, QString::number( size )); + uint64_t filesize = node->getByteSize(); + item->setToolTip(1, QString("TotalSize: %1 (%2 Bytes)").arg(approxFileSize(filesize)).arg( filesize )); + item->setToolTip(0, ownPath); } else { std::size_t size = node->size; item->setText( 1, approxFileSize( size ) ); item->setToolTip( 1, QString::number( size ) ); + QString tooltip = ownPath; + QLocale::Language lang = (QLocale::Language) node->language; + QLocale::Country country = (QLocale::Country) node->country; + QLocale fileLocale(lang, country); + tooltip += (node->isCompressed() ? "\nCompressed" : "\nUncompressed") + + ((fileLocale != QLocale()) ? ("\nLocale: " + fileLocale.name() ) : "" ); + item->setToolTip(0, tooltip); } if( node->lastModTimeMS ) {