2017-12-05 19:31:43 -08:00
|
|
|
#include "MainWindow.hpp"
|
|
|
|
#include "ui_MainWindow.h"
|
|
|
|
#include <QFontDatabase>
|
2018-01-02 16:24:45 -08:00
|
|
|
#include "EscapeSequenceParser.hpp"
|
2017-12-05 19:31:43 -08:00
|
|
|
#include "FileDirDialog.hpp"
|
|
|
|
|
2018-01-01 21:56:25 -08:00
|
|
|
#if _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
#endif
|
|
|
|
|
2017-12-05 19:31:43 -08:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
m_ui(new Ui::MainWindow)
|
|
|
|
, m_heclProc(this)
|
2017-12-25 20:27:18 -08:00
|
|
|
, m_dlManager(this)
|
2017-12-26 16:48:34 -08:00
|
|
|
, m_settings("AxioDL", "HECL", this)
|
2017-12-05 19:31:43 -08:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
m_ui->heclTabs->setCurrentIndex(0);
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->splitter->setSizes({0,100});
|
2017-12-25 20:27:18 -08:00
|
|
|
|
2017-12-25 13:53:37 -08:00
|
|
|
m_ui->aboutIcon->setPixmap(QApplication::windowIcon().pixmap(256, 256));
|
2017-12-25 20:27:18 -08:00
|
|
|
|
|
|
|
QFont mFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
|
|
|
mFont.setPointSize(m_ui->currentBinaryLabel->font().pointSize());
|
|
|
|
m_ui->currentBinaryLabel->setFont(mFont);
|
|
|
|
m_ui->recommendedBinaryLabel->setFont(mFont);
|
2018-01-01 16:58:38 -08:00
|
|
|
mFont.setPointSize(10);
|
|
|
|
m_ui->processOutput->setFont(mFont);
|
2017-12-25 20:27:18 -08:00
|
|
|
|
2017-12-26 16:48:34 -08:00
|
|
|
m_updateURDEButton = new QPushButton(QStringLiteral("Update URDE"), m_ui->centralwidget);
|
|
|
|
m_ui->gridLayout->addWidget(m_updateURDEButton, 2, 3, 1, 1);
|
|
|
|
m_updateURDEButton->hide();
|
|
|
|
QPalette pal = m_updateURDEButton->palette();
|
|
|
|
pal.setColor(QPalette::Button, QColor(53,53,72));
|
|
|
|
m_updateURDEButton->setPalette(pal);
|
|
|
|
connect(m_updateURDEButton, SIGNAL(clicked()), this, SLOT(onUpdateURDEPressed()));
|
|
|
|
|
2017-12-25 20:27:18 -08:00
|
|
|
m_dlManager.connectWidgets(m_ui->downloadProgressBar, m_ui->downloadErrorLabel,
|
|
|
|
std::bind(&MainWindow::onIndexDownloaded, this, std::placeholders::_1),
|
2018-01-01 16:58:38 -08:00
|
|
|
std::bind(&MainWindow::onBinaryDownloaded, this, std::placeholders::_1),
|
|
|
|
std::bind(&MainWindow::onBinaryFailed, this, std::placeholders::_1));
|
2017-12-25 20:27:18 -08:00
|
|
|
|
2017-12-05 19:31:43 -08:00
|
|
|
initSlots();
|
2017-12-25 20:27:18 -08:00
|
|
|
|
|
|
|
m_dlManager.fetchIndex();
|
2018-01-01 20:21:45 -08:00
|
|
|
|
|
|
|
setPath(m_settings.value(QStringLiteral("working_dir")).toString());
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
m_heclProc.close();
|
|
|
|
m_heclProc.terminate();
|
|
|
|
delete m_ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onExtract()
|
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
if (m_path.isEmpty())
|
|
|
|
return;
|
|
|
|
QString imgPath = QFileDialog::getOpenFileName(this, QStringLiteral("Extract Image"), {},
|
|
|
|
QStringLiteral("Images (*.iso *.wbfs *.gcm)"));
|
|
|
|
m_ansiString.clear();
|
|
|
|
m_ui->processOutput->clear();
|
|
|
|
m_heclProc.close();
|
|
|
|
m_heclProc.terminate();
|
|
|
|
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
|
|
|
m_heclProc.setWorkingDirectory(m_path);
|
|
|
|
m_heclProc.start(m_heclPath, {"extract", "-y", imgPath, m_path});
|
|
|
|
|
|
|
|
m_ui->heclTabs->setCurrentIndex(0);
|
|
|
|
|
|
|
|
disableOperations();
|
|
|
|
m_ui->extractBtn->setText(QStringLiteral("Cancel"));
|
|
|
|
m_ui->extractBtn->setEnabled(true);
|
|
|
|
disconnect(m_ui->extractBtn, SIGNAL(clicked()), nullptr, nullptr);
|
|
|
|
connect(m_ui->extractBtn, SIGNAL(clicked()), this, SLOT(doHECLTerminate()));
|
|
|
|
|
|
|
|
disconnect(&m_heclProc, SIGNAL(finished(int)), nullptr, nullptr);
|
|
|
|
connect(&m_heclProc, SIGNAL(finished(int)), this, SLOT(onExtractFinished(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onExtractFinished(int returnCode)
|
|
|
|
{
|
|
|
|
disconnect(m_ui->extractBtn, SIGNAL(clicked()), nullptr, nullptr);
|
|
|
|
connect(m_ui->extractBtn, SIGNAL(clicked()), this, SLOT(onExtract()));
|
|
|
|
checkDownloadedBinary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onPackage()
|
|
|
|
{
|
|
|
|
if (m_path.isEmpty())
|
|
|
|
return;
|
|
|
|
m_ansiString.clear();
|
|
|
|
m_ui->processOutput->clear();
|
|
|
|
m_heclProc.close();
|
|
|
|
m_heclProc.terminate();
|
|
|
|
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
|
|
|
m_heclProc.setWorkingDirectory(m_path);
|
|
|
|
m_heclProc.start(m_heclPath, {"package", "-y"});
|
2017-12-05 19:31:43 -08:00
|
|
|
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->heclTabs->setCurrentIndex(0);
|
|
|
|
|
|
|
|
disableOperations();
|
|
|
|
m_ui->packageBtn->setText(QStringLiteral("Cancel"));
|
|
|
|
m_ui->packageBtn->setEnabled(true);
|
|
|
|
disconnect(m_ui->packageBtn, SIGNAL(clicked()), nullptr, nullptr);
|
|
|
|
connect(m_ui->packageBtn, SIGNAL(clicked()), this, SLOT(doHECLTerminate()));
|
|
|
|
|
|
|
|
disconnect(&m_heclProc, SIGNAL(finished(int)), nullptr, nullptr);
|
|
|
|
connect(&m_heclProc, SIGNAL(finished(int)), this, SLOT(onPackageFinished(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onPackageFinished(int returnCode)
|
|
|
|
{
|
|
|
|
disconnect(m_ui->packageBtn, SIGNAL(clicked()), nullptr, nullptr);
|
|
|
|
connect(m_ui->packageBtn, SIGNAL(clicked()), this, SLOT(onPackage()));
|
|
|
|
checkDownloadedBinary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onLaunch()
|
|
|
|
{
|
|
|
|
if (m_path.isEmpty())
|
|
|
|
return;
|
|
|
|
m_ansiString.clear();
|
|
|
|
m_ui->processOutput->clear();
|
|
|
|
m_heclProc.close();
|
|
|
|
m_heclProc.terminate();
|
|
|
|
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
|
|
|
m_heclProc.setWorkingDirectory(m_path);
|
|
|
|
m_heclProc.start(m_urdePath, {"--no-shader-warmup", m_path + "/out"});
|
|
|
|
|
|
|
|
m_ui->heclTabs->setCurrentIndex(0);
|
|
|
|
|
|
|
|
disableOperations();
|
|
|
|
|
|
|
|
disconnect(&m_heclProc, SIGNAL(finished(int)), nullptr, nullptr);
|
|
|
|
connect(&m_heclProc, SIGNAL(finished(int)), this, SLOT(onLaunchFinished(int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onLaunchFinished(int returnCode)
|
|
|
|
{
|
|
|
|
checkDownloadedBinary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::doHECLTerminate()
|
|
|
|
{
|
|
|
|
m_heclProc.terminate();
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onReturnPressed()
|
|
|
|
{
|
2018-01-02 16:24:45 -08:00
|
|
|
if (sender() == m_ui->pathEdit)
|
2017-12-26 16:48:34 -08:00
|
|
|
setPath(m_ui->pathEdit->text());
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
|
2017-12-25 20:27:18 -08:00
|
|
|
void MainWindow::onIndexDownloaded(const QStringList& index)
|
|
|
|
{
|
2017-12-26 16:48:34 -08:00
|
|
|
int bestVersion = 0;
|
2017-12-25 20:27:18 -08:00
|
|
|
m_ui->binaryComboBox->clear();
|
|
|
|
for (const QString& str : index)
|
2017-12-26 16:48:34 -08:00
|
|
|
{
|
|
|
|
URDEVersion version(str);
|
|
|
|
if (m_ui->sysReqTable->willRun(version))
|
|
|
|
bestVersion = m_ui->binaryComboBox->count();
|
|
|
|
m_ui->binaryComboBox->addItem(version.fileString(false), QVariant::fromValue(version));
|
|
|
|
}
|
|
|
|
m_ui->binaryComboBox->setCurrentIndex(bestVersion);
|
|
|
|
m_recommendedVersion = m_ui->binaryComboBox->itemData(bestVersion).value<URDEVersion>();
|
|
|
|
m_ui->recommendedBinaryLabel->setText(m_recommendedVersion.fileString(false));
|
2017-12-25 20:27:18 -08:00
|
|
|
m_ui->binaryComboBox->setEnabled(true);
|
2017-12-26 16:48:34 -08:00
|
|
|
|
|
|
|
if (!m_path.isEmpty())
|
|
|
|
{
|
|
|
|
checkDownloadedBinary();
|
|
|
|
m_ui->downloadButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onDownloadPressed()
|
|
|
|
{
|
|
|
|
m_updateURDEButton->hide();
|
|
|
|
QString filename = m_ui->binaryComboBox->currentData().value<URDEVersion>().fileString(true);
|
2018-01-01 16:58:38 -08:00
|
|
|
disableOperations();
|
|
|
|
m_ui->downloadButton->setEnabled(false);
|
2017-12-26 16:48:34 -08:00
|
|
|
m_dlManager.fetchBinary(filename, m_path + '/' + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onUpdateURDEPressed()
|
|
|
|
{
|
|
|
|
m_ui->heclTabs->setCurrentIndex(1);
|
|
|
|
onDownloadPressed();
|
2017-12-25 20:27:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onBinaryDownloaded(const QString& file)
|
|
|
|
{
|
2017-12-26 16:48:34 -08:00
|
|
|
QFileInfo path(file);
|
|
|
|
#ifndef _WIN32
|
2018-01-01 16:58:38 -08:00
|
|
|
QProcess unzip;
|
|
|
|
unzip.setWorkingDirectory(path.dir().absolutePath());
|
|
|
|
unzip.start("unzip", {"-o", path.fileName()});
|
|
|
|
unzip.waitForFinished();
|
|
|
|
int err = unzip.exitCode();
|
2017-12-26 16:48:34 -08:00
|
|
|
#else
|
2018-01-01 16:58:38 -08:00
|
|
|
SHFILEOPSTRUCT fileOp = {};
|
|
|
|
fileOp.wFunc = FO_COPY;
|
2018-01-02 16:24:45 -08:00
|
|
|
fileOp.pFrom = (path.absoluteFilePath().toStdWString() + L"\\*.*\0\0").c_str();
|
|
|
|
fileOp.pTo = (path.absolutePath().toStdWString() + L"\0\0").c_str();
|
2018-01-01 16:58:38 -08:00
|
|
|
fileOp.fFlags |= FOF_NOCONFIRMATION;
|
|
|
|
int err = SHFileOperationW(&fileOp);
|
|
|
|
if (fileOp.fAnyOperationsAborted)
|
|
|
|
err = 1;
|
2017-12-26 16:48:34 -08:00
|
|
|
#endif
|
|
|
|
QFile::remove(file);
|
2018-01-01 16:58:38 -08:00
|
|
|
if (err)
|
|
|
|
m_ui->downloadErrorLabel->setText(QStringLiteral("Error extracting ") + path.fileName());
|
|
|
|
else
|
|
|
|
m_ui->downloadErrorLabel->setText(QStringLiteral("Download successful"), true);
|
|
|
|
m_ui->downloadButton->setEnabled(true);
|
2017-12-26 16:48:34 -08:00
|
|
|
checkDownloadedBinary();
|
2018-01-01 16:58:38 -08:00
|
|
|
if (!err && m_ui->extractBtn->isEnabled())
|
|
|
|
m_ui->downloadErrorLabel->setText(QStringLiteral("Download successful - Press 'Extract' to continue."), true);
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
|
|
|
|
2018-01-01 16:58:38 -08:00
|
|
|
void MainWindow::onBinaryFailed(const QString& file)
|
2017-12-26 16:48:34 -08:00
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->downloadButton->setEnabled(true);
|
|
|
|
checkDownloadedBinary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::disableOperations()
|
|
|
|
{
|
|
|
|
m_ui->extractBtn->setEnabled(false);
|
|
|
|
m_ui->packageBtn->setEnabled(false);
|
|
|
|
m_ui->launchBtn->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::enableOperations()
|
|
|
|
{
|
|
|
|
disableOperations();
|
|
|
|
if (m_path.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_ui->extractBtn->setText(QStringLiteral("Extract"));
|
|
|
|
m_ui->packageBtn->setText(QStringLiteral("Package"));
|
|
|
|
m_ui->launchBtn->setText(QStringLiteral("Launch"));
|
|
|
|
|
|
|
|
m_ui->extractBtn->setEnabled(true);
|
|
|
|
if (QFile::exists(m_path + "/MP1/!original_ids.yaml"))
|
|
|
|
{
|
|
|
|
m_ui->packageBtn->setEnabled(true);
|
|
|
|
if (QFile::exists(m_path + "/out/MP1/!original_ids.upak"))
|
|
|
|
m_ui->launchBtn->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ui->launchBtn->isEnabled())
|
|
|
|
insertContinueNote("Package complete - Press 'Launch' to start URDE.");
|
|
|
|
else if (m_ui->packageBtn->isEnabled())
|
|
|
|
insertContinueNote("Extract complete - Press 'Package' to continue.");
|
|
|
|
else if (m_ui->extractBtn->isEnabled())
|
|
|
|
insertContinueNote("Press 'Extract' to begin.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool GetDLPackage(const QString& path, QString& dlPackage)
|
|
|
|
{
|
|
|
|
QProcess proc;
|
|
|
|
proc.start(path, {"--dlpackage"}, QIODevice::ReadOnly);
|
|
|
|
if (proc.waitForStarted())
|
|
|
|
{
|
|
|
|
proc.waitForFinished();
|
|
|
|
if (proc.exitCode() == 100)
|
|
|
|
dlPackage = QString::fromUtf8(proc.readLine()).trimmed();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::checkDownloadedBinary()
|
|
|
|
{
|
|
|
|
disableOperations();
|
2017-12-26 16:48:34 -08:00
|
|
|
m_updateURDEButton->hide();
|
|
|
|
|
2018-01-01 16:58:38 -08:00
|
|
|
m_urdePath = QString();
|
|
|
|
m_heclPath = QString();
|
|
|
|
|
|
|
|
if (m_path.isEmpty())
|
2018-01-01 20:21:45 -08:00
|
|
|
{
|
|
|
|
m_ui->heclTabs->setCurrentIndex(1);
|
|
|
|
m_ui->downloadErrorLabel->setText(QStringLiteral("Set working directory to continue."), true);
|
2018-01-01 16:58:38 -08:00
|
|
|
return false;
|
2018-01-01 20:21:45 -08:00
|
|
|
}
|
2018-01-01 16:58:38 -08:00
|
|
|
|
2017-12-26 16:48:34 -08:00
|
|
|
#if __APPLE__
|
2018-01-01 16:58:38 -08:00
|
|
|
QString urdePath = m_path + "/URDE.app/Contents/MacOS/urde";
|
|
|
|
QString heclPath = m_path + "/URDE.app/Contents/MacOS/hecl";
|
|
|
|
QString visigenPath = m_path + "/URDE.app/Contents/MacOS/visigen";
|
2017-12-26 16:48:34 -08:00
|
|
|
#elif _WIN32
|
2018-01-01 16:58:38 -08:00
|
|
|
QString urdePath = m_path + "/urde.exe";
|
|
|
|
QString heclPath = m_path + "/hecl.exe";
|
|
|
|
QString visigenPath = m_path + "/visigen.exe";
|
2017-12-26 16:48:34 -08:00
|
|
|
#else
|
2018-01-01 16:58:38 -08:00
|
|
|
QString urdePath = m_path + "/urde";
|
|
|
|
QString heclPath = m_path + "/hecl";
|
|
|
|
QString visigenPath = m_path + "/visigen";
|
2017-12-26 16:48:34 -08:00
|
|
|
#endif
|
2018-01-01 16:58:38 -08:00
|
|
|
urdePath = QFileInfo(urdePath).absoluteFilePath();
|
|
|
|
heclPath = QFileInfo(heclPath).absoluteFilePath();
|
2018-01-01 17:12:45 -08:00
|
|
|
visigenPath = QFileInfo(visigenPath).absoluteFilePath();
|
2018-01-01 16:58:38 -08:00
|
|
|
|
|
|
|
QString urdeDlPackage, heclDlPackage, visigenDlPackage;
|
|
|
|
if (GetDLPackage(urdePath, urdeDlPackage) &&
|
|
|
|
GetDLPackage(heclPath, heclDlPackage) &&
|
|
|
|
GetDLPackage(visigenPath, visigenDlPackage))
|
2017-12-26 16:48:34 -08:00
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
if (!urdeDlPackage.isEmpty() &&
|
|
|
|
urdeDlPackage == heclDlPackage &&
|
|
|
|
urdeDlPackage == visigenDlPackage)
|
2017-12-26 16:48:34 -08:00
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
URDEVersion v(urdeDlPackage);
|
|
|
|
m_ui->currentBinaryLabel->setText(v.fileString(false));
|
|
|
|
if (m_recommendedVersion.isValid() && v.isValid() &&
|
|
|
|
m_recommendedVersion.getVersion() > v.getVersion())
|
2017-12-26 16:48:34 -08:00
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
m_updateURDEButton->show();
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->currentBinaryLabel->setText(QStringLiteral("unknown... re-download recommended"));
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
2018-01-01 16:58:38 -08:00
|
|
|
|
|
|
|
enableOperations();
|
|
|
|
m_urdePath = urdePath;
|
|
|
|
m_heclPath = heclPath;
|
|
|
|
return true;
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->currentBinaryLabel->setText(QStringLiteral("none"));
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->heclTabs->setCurrentIndex(1);
|
|
|
|
m_ui->downloadErrorLabel->setText(QStringLiteral("Press 'Download' to fetch latest URDE binary."), true);
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
2018-01-01 16:58:38 -08:00
|
|
|
|
|
|
|
return false;
|
2017-12-26 16:48:34 -08:00
|
|
|
}
|
2017-12-25 20:27:18 -08:00
|
|
|
|
2017-12-26 16:48:34 -08:00
|
|
|
void MainWindow::setPath(const QString& path)
|
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
m_path = path;
|
|
|
|
m_settings.setValue(QStringLiteral("working_dir"), m_path);
|
|
|
|
|
2017-12-26 16:48:34 -08:00
|
|
|
if (!path.isEmpty())
|
|
|
|
{
|
|
|
|
m_ui->pathEdit->setText(m_path);
|
|
|
|
m_ui->downloadButton->setToolTip(QString());
|
|
|
|
m_ui->downloadButton->setEnabled(m_ui->binaryComboBox->isEnabled());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ui->downloadButton->setToolTip(QStringLiteral("Working directory must be set"));
|
|
|
|
m_ui->downloadButton->setEnabled(false);
|
|
|
|
m_ui->currentBinaryLabel->setText(QStringLiteral("none"));
|
|
|
|
}
|
2018-01-01 16:58:38 -08:00
|
|
|
|
|
|
|
checkDownloadedBinary();
|
2017-12-25 20:27:18 -08:00
|
|
|
}
|
|
|
|
|
2017-12-05 19:31:43 -08:00
|
|
|
void MainWindow::initSlots()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
m_heclProc.setEnvironment(QProcessEnvironment::systemEnvironment().toStringList() + QStringList("ConEmuANSI=ON"));
|
|
|
|
#endif
|
|
|
|
connect(&m_heclProc, &QProcess::readyRead, [=](){
|
|
|
|
m_ansiString = m_heclProc.readAll();
|
2018-01-01 16:58:38 -08:00
|
|
|
setTextTermFormatting(m_ansiString);
|
2017-12-05 19:31:43 -08:00
|
|
|
m_ui->processOutput->ensureCursorVisible();
|
|
|
|
});
|
|
|
|
|
2018-01-01 16:58:38 -08:00
|
|
|
connect(m_ui->extractBtn, SIGNAL(clicked()), this, SLOT(onExtract()));
|
|
|
|
connect(m_ui->packageBtn, SIGNAL(clicked()), this, SLOT(onPackage()));
|
|
|
|
connect(m_ui->launchBtn, SIGNAL(clicked()), this, SLOT(onLaunch()));
|
2017-12-05 19:31:43 -08:00
|
|
|
|
|
|
|
connect(m_ui->browseBtn, &QPushButton::clicked, [=]() {
|
|
|
|
FileDirDialog dialog(this);
|
2017-12-26 20:10:44 -08:00
|
|
|
dialog.setWindowTitle("Select Working Directory");
|
2017-12-05 19:31:43 -08:00
|
|
|
int res = dialog.exec();//QFileDialog::getOpenFileName(this, "Select ISO or Directory");
|
|
|
|
if (res == QFileDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dialog.selectedFiles().size() <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* TODO: Add beacon detection */
|
2017-12-26 16:48:34 -08:00
|
|
|
setPath(dialog.selectedFiles().at(0));
|
2017-12-05 19:31:43 -08:00
|
|
|
});
|
|
|
|
|
2017-12-26 16:48:34 -08:00
|
|
|
connect(m_ui->downloadButton, SIGNAL(clicked()), this, SLOT(onDownloadPressed()));
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
|
2018-01-01 16:58:38 -08:00
|
|
|
static void ReturnInsert(QTextCursor& cur, const QString& text)
|
2017-12-05 19:31:43 -08:00
|
|
|
{
|
2018-01-01 16:58:38 -08:00
|
|
|
QStringList list = text.split('\r');
|
|
|
|
if (!list.front().isEmpty())
|
|
|
|
cur.insertText(list.front());
|
|
|
|
if (list.size() > 1)
|
|
|
|
{
|
|
|
|
for (auto it = list.begin() + 1; it != list.end(); ++it)
|
|
|
|
{
|
|
|
|
cur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
|
|
|
if (!it->isEmpty())
|
|
|
|
cur.insertText(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format)
|
|
|
|
{
|
|
|
|
QStringList list = text.split('\r');
|
|
|
|
if (!list.front().isEmpty())
|
|
|
|
cur.insertText(list.front(), format);
|
|
|
|
if (list.size() > 1)
|
|
|
|
{
|
|
|
|
for (auto it = list.begin() + 1; it != list.end(); ++it)
|
|
|
|
{
|
|
|
|
cur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
|
|
|
|
if (!it->isEmpty())
|
|
|
|
cur.insertText(*it, format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setTextTermFormatting(const QString& text)
|
|
|
|
{
|
|
|
|
m_inContinueNote = false;
|
|
|
|
|
|
|
|
QTextDocument* document = m_ui->processOutput->document();
|
2017-12-05 19:31:43 -08:00
|
|
|
QRegExp const escapeSequenceExpression(R"(\x1B\[([\d;]+)m)");
|
|
|
|
QTextCursor cursor(document);
|
2018-01-01 16:58:38 -08:00
|
|
|
cursor.movePosition(QTextCursor::End);
|
2017-12-05 19:31:43 -08:00
|
|
|
QTextCharFormat defaultTextCharFormat = cursor.charFormat();
|
|
|
|
cursor.beginEditBlock();
|
|
|
|
int offset = escapeSequenceExpression.indexIn(text);
|
2018-01-01 16:58:38 -08:00
|
|
|
ReturnInsert(cursor, text.mid(0, offset));
|
2017-12-05 19:31:43 -08:00
|
|
|
QTextCharFormat textCharFormat = defaultTextCharFormat;
|
|
|
|
while (!(offset < 0)) {
|
|
|
|
int previousOffset = offset + escapeSequenceExpression.matchedLength();
|
|
|
|
QStringList capturedTexts = escapeSequenceExpression.capturedTexts().back().split(';');
|
|
|
|
QListIterator< QString > i(capturedTexts);
|
|
|
|
while (i.hasNext()) {
|
|
|
|
bool ok = false;
|
|
|
|
int attribute = i.next().toInt(&ok);
|
|
|
|
Q_ASSERT(ok);
|
2018-01-02 16:24:45 -08:00
|
|
|
ParseEscapeSequence(attribute, i, textCharFormat, defaultTextCharFormat);
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
offset = escapeSequenceExpression.indexIn(text, previousOffset);
|
|
|
|
if (offset < 0) {
|
2018-01-01 16:58:38 -08:00
|
|
|
ReturnInsert(cursor, text.mid(previousOffset), textCharFormat);
|
2017-12-05 19:31:43 -08:00
|
|
|
} else {
|
2018-01-01 16:58:38 -08:00
|
|
|
ReturnInsert(cursor, text.mid(previousOffset, offset - previousOffset), textCharFormat);
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor.setCharFormat(defaultTextCharFormat);
|
|
|
|
cursor.endEditBlock();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
2018-01-01 16:58:38 -08:00
|
|
|
m_ui->processOutput->setTextCursor(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::insertContinueNote(const QString& text)
|
|
|
|
{
|
|
|
|
if (m_inContinueNote)
|
|
|
|
return;
|
|
|
|
m_inContinueNote = true;
|
|
|
|
|
|
|
|
QTextDocument* document = m_ui->processOutput->document();
|
|
|
|
QTextCursor cursor(document);
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
QTextCharFormat textCharFormat = cursor.charFormat();
|
|
|
|
textCharFormat.setForeground(QColor(0,255,0));
|
|
|
|
cursor.beginEditBlock();
|
|
|
|
cursor.insertText(text + '\n', textCharFormat);
|
|
|
|
cursor.endEditBlock();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
m_ui->processOutput->setTextCursor(cursor);
|
2017-12-05 19:31:43 -08:00
|
|
|
}
|