diff --git a/tools/zentry/main.cpp b/tools/zentry/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/tools/zentry/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/tools/zentry/mainwindow.cpp b/tools/zentry/mainwindow.cpp new file mode 100644 index 0000000..f56395d --- /dev/null +++ b/tools/zentry/mainwindow.cpp @@ -0,0 +1,120 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include "compression.h" +#include "qfiledialog.h" + +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow{parent} { + setWindowTitle("Zentry Tool"); + setMinimumSize(250, 150); + setMaximumSize(250, 150); + setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + + QLabel *dragLabel = new QLabel(this); + dragLabel->setText("Drop file here..."); + dragLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + dragLabel->setStyleSheet("QLabel {" + " color: white;" + " background-color: grey;" + "}" + "QLabel::hover " + "{" + " background-color: black;" + "}"); + + setCentralWidget(dragLabel); +} + +MainWindow::~MainWindow() { + +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) { + const QMimeData *mimeData = event->mimeData(); + bool goodDrag = true; + if (mimeData->hasUrls()) { + qDebug() << mimeData->urls(); + } else { + goodDrag = false; + } + if (goodDrag) { + event->acceptProposedAction(); + } +} + +void MainWindow::dragMoveEvent(QDragMoveEvent *event) { + Q_UNUSED(event); +} + +void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) { + Q_UNUSED(event); +} + +void MainWindow::dropEvent(QDropEvent *event) { + const QMimeData *mimeData = event->mimeData(); + if (mimeData->hasUrls()) { + foreach (const QUrl &url, mimeData->urls()) { + const QString fileName = url.toString().split('/').last(); + QMessageBox msgBox; + msgBox.setWindowTitle("Handle File"); + msgBox.setText("Choose how to handle " + fileName); + + QPushButton *compressButton = msgBox.addButton(tr("Compress"), QMessageBox::AcceptRole); + QPushButton *decompressButton = msgBox.addButton(tr("Decompress"), QMessageBox::RejectRole); + QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole); + msgBox.exec(); + + if ((QPushButton*)msgBox.clickedButton() == compressButton) { + // Compress + } else if ((QPushButton*)msgBox.clickedButton() == decompressButton) { + // Decompress + QFile compressedFile(url.toLocalFile()); + if (!compressedFile.open(QIODevice::ReadOnly)) { + qDebug() << QString("Failed to open %1!").arg(fileName); + continue; + } + + const QByteArray compressedData = compressedFile.readAll(); + QByteArray decompressedData; + if (compressedData.left(2).toHex() == "7801") { + qDebug() << "Detected zlib data! (No Compression/low)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "785e") { + qDebug() << "Detected zlib data! (Fast Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "789c") { + qDebug() << "Detected zlib data! (Default Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "78da") { + qDebug() << "Detected zlib data! (Best Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else { + qDebug() << "Invalid zlib header!"; + continue; + } + + if (decompressedData.isEmpty()) { + qDebug() << "Zlib output was empty!"; + continue; + } + + const QString decompressedPath = QFileDialog::getSaveFileName(this, "Choose save name"); + QFile decompressedFile(decompressedPath); + if (!decompressedFile.open(QIODevice::WriteOnly)) { + qDebug() << QString("Failed to open %1!").arg(decompressedPath.split('/').last()); + continue; + } + decompressedFile.write(decompressedData); + decompressedFile.close(); + } else if ((QPushButton*)msgBox.clickedButton() == cancelButton) { + // Cancel + } + } + } +} diff --git a/tools/zentry/mainwindow.h b/tools/zentry/mainwindow.h new file mode 100644 index 0000000..4995cf5 --- /dev/null +++ b/tools/zentry/mainwindow.h @@ -0,0 +1,32 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +protected: + void dragEnterEvent(QDragEnterEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; + void dropEvent(QDropEvent *event) override; + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/tools/zentry/mainwindow.ui b/tools/zentry/mainwindow.ui new file mode 100644 index 0000000..6a8c885 --- /dev/null +++ b/tools/zentry/mainwindow.ui @@ -0,0 +1,22 @@ + + + MainWindow + + + + 0 + 0 + 1006 + 600 + + + + MainWindow + + + + + + + + diff --git a/tools/zentry/zentry.pro b/tools/zentry/zentry.pro index 68b8e1e..aaee86d 100644 --- a/tools/zentry/zentry.pro +++ b/tools/zentry/zentry.pro @@ -2,26 +2,29 @@ QT += core widgets gui multimedia RC_ICONS = zentry.ico -SUBDIRS += zentry - CONFIG += c++17 SOURCES += \ - zentrymain.cpp \ - zentrywindow.cpp + main.cpp \ + mainwindow.cpp HEADERS += \ - zentrywindow.h + mainwindow.h + +FORMS += \ + mainwindow.ui LIBS += \ + -L$$OUT_PWD/../../libs/ -lcore \ -L$$OUT_PWD/../../libs/ -lcompression \ -L$$PWD/../../third_party/xbox_sdk/lib -lxcompress64 INCLUDEPATH += \ + $$PWD/../../libs/core \ $$PWD/../../libs/compression \ $$PWD/../../third_party/xbox_sdk/include DEPENDPATH += \ + $$PWD/../../libs/core \ $$PWD/../../libs/compression \ $$PWD/../../third_party/xbox_sdk/include -