Skip to content

Commit

Permalink
Added virtual file metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Puxtril committed Oct 6, 2024
1 parent 3592f86 commit 39b0f8f
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 23 deletions.
11 changes: 8 additions & 3 deletions include/ui/MetadataPreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@

class MetdataPreview
{
QWidget* m_parentWidget;
QVBoxLayout* m_layout;
QPlainTextEdit* m_textWidget;
QLabel* m_labelCompressed;
QLabel* m_labelDecompressed;
QLabel* m_labelModified;

public:
MetdataPreview();

void setupUis(QWidget* parentWidget, QVBoxLayout* parentLayout);
void setupUis(QPlainTextEdit* textWidget, QLabel* compressed, QLabel* decompressed, QLabel* modified);
void setData(LotusLib::PackagesReader* pkgs, const std::string& pkgName, const LotusLib::LotusPath& internalPath);
void clearPreview();

private:
void setupCommonHeader(LotusLib::FileEntry& fileEntry);
void setFiledata(LotusLib::PackageReader& pkgs, LotusLib::FileEntry& fileEntry);
static QString timestampToQString(int64_t input);
static QString filesizeToQString(int input);
};
2 changes: 1 addition & 1 deletion lib/LotusLib
Submodule LotusLib updated 2 files
+13 −11 include/LotusLib.h
+12 −12 src/LotusLib.cpp
84 changes: 69 additions & 15 deletions src/ui/MetadataPreview.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
#include "ui/MetadataPreview.h"

MetdataPreview::MetdataPreview()
: m_parentWidget(nullptr), m_layout(nullptr)
: m_textWidget(nullptr)
{ }

void
MetdataPreview::setupUis(QWidget* parentWidget, QVBoxLayout* parentLayout)
MetdataPreview::setupUis(QPlainTextEdit* textWidget, QLabel* compressed, QLabel* decompressed, QLabel* modified)
{
m_parentWidget = parentWidget;
m_layout = parentLayout;
m_textWidget = textWidget;
m_labelCompressed = compressed;
m_labelDecompressed = decompressed;
m_labelModified = modified;
}

void
MetdataPreview::setData(LotusLib::PackagesReader* pkgs, const std::string& pkgName, const LotusLib::LotusPath& internalPath)
{
LotusLib::FileEntry fileEntry = pkgs->getPackage(pkgName).value().getFile(internalPath, LotusLib::READ_COMMON_HEADER);
setupCommonHeader(fileEntry);
auto pkg = pkgs->getPackage(pkgName).value();
setFiledata(pkg, fileEntry);
}

void
MetdataPreview::clearPreview()
{
for (QWidget* x : m_parentWidget->findChildren<QWidget*>(Qt::FindDirectChildrenOnly))
delete x;
m_textWidget->clear();
m_labelModified->clear();
m_labelCompressed->clear();
m_labelDecompressed->clear();
}

void
MetdataPreview::setupCommonHeader(LotusLib::FileEntry& fileEntry)
{
QLabel* label = new QLabel(m_parentWidget);
m_layout->addWidget(label);

label->setText("Common Header");

QPlainTextEdit* textEdit = new QPlainTextEdit(m_parentWidget);
m_layout->addWidget(textEdit);

std::stringstream outStr;

outStr << "Type Enum: ";
Expand All @@ -59,5 +57,61 @@ MetdataPreview::setupCommonHeader(LotusLib::FileEntry& fileEntry)


std::string outStrTmp = outStr.str();
textEdit->setPlainText(QString(outStrTmp.c_str()));
m_textWidget->setPlainText(QString(outStrTmp.c_str()));
}

void
MetdataPreview::setFiledata(LotusLib::PackageReader& pkgs, LotusLib::FileEntry& fileEntry)
{
m_labelModified->setText(timestampToQString(fileEntry.metadata->getTimeStamp()));
int totalCompressed = fileEntry.metadata->getCompLen();
int totalDecompressed = fileEntry.metadata->getLen();

try
{
const LotusLib::FileEntries::FileNode* bNode = pkgs.getFileNode(fileEntry.internalPath, LotusLib::PackageTrioType::B);
totalCompressed += bNode->getCompLen();
totalDecompressed += bNode->getLen();
}
catch (LotusLib::LotusException& ex) {}

try
{
const LotusLib::FileEntries::FileNode* fNode = pkgs.getFileNode(fileEntry.internalPath, LotusLib::PackageTrioType::F);
totalCompressed += fNode->getCompLen();
totalDecompressed += fNode->getLen();
}
catch (LotusLib::LotusException& ex) {}

m_labelCompressed->setText(filesizeToQString(totalCompressed));
m_labelDecompressed->setText(filesizeToQString(totalDecompressed));
}

QString
MetdataPreview::timestampToQString(int64_t input)
{
time_t epochTime = input / 10000000UL - 11644473600UL;
const tm* timeInfo = gmtime(&std::max((time_t)0, epochTime));

char s[16];
strftime(s, 16, "%b %d, %Y", timeInfo);
return QString(s);
}

QString
MetdataPreview::filesizeToQString(int input)
{
static std::array<std::string, 5> prefixes {"B", "KB", "MB", "GB", "TB"};

int prefixIndex = 0;
float sizedDown = input;

while (sizedDown > 1024 && prefixIndex < 4)
{
sizedDown /= 1024;
prefixIndex++;
}

std::string sizeStr = std::to_string((int)sizedDown) + " " + prefixes[prefixIndex];
return QString(sizeStr.c_str());
}
2 changes: 1 addition & 1 deletion src/ui/UIExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ UiExporter::setup(UiMainWindow *MainWindow)
connect(&m_exporterFileThread, &ExporterFileThread::extractComplete, this, &UiExporter::extractComplete);

m_previewManager.setupUis(this->Preview, this->verticalLayout_3, this->PreviewButtonsArea, this->horizontalLayout_5);
m_metadataPreview.setupUis(this->Metadata, this->verticalLayout);
m_metadataPreview.setupUis(this->MetadataCommonHeader, this->MetadataCompressedValue, this->MetadataDecompressedValue, this->MetadataModifiedValue);
m_formatPreview.setupUis(this->Format, this->verticalLayout_6);
}

Expand Down
74 changes: 71 additions & 3 deletions ui/Exporter.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>699</width>
<height>562</height>
<width>725</width>
<height>604</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -119,7 +119,75 @@
<attribute name="title">
<string>Metadata</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout"/>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="MetadataCommonHeader"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="MetadataModifiedLabel">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Modified</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="MetadataDecompressedValue">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="MetadataDecompressedLabel">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Decompressed</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="MetadataCompressedLabel">
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Compressed</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="MetadataCompressedValue">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="MetadataModifiedValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="Format">
<attribute name="title">
Expand Down

0 comments on commit 39b0f8f

Please sign in to comment.