file size of folders and extract compressed files.

This commit is contained in:
mrbesen 2023-01-12 21:01:14 +01:00
parent 268b6f6622
commit 329f6561f2
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 28 additions and 4 deletions

View File

@ -51,6 +51,7 @@ private:
bool isDir() const;
bool isCompressed() const;
uint64_t getByteSize() const;
};
using data = const unsigned char*;

View File

@ -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::MemoryMap> 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 ) {