CMakeLists: Add Qt 5 type-safety compile definitions

Migrates the Qt compile definitions that were added to amuse over to the
hecl GUI.
This commit is contained in:
Lioncash 2019-08-27 21:35:51 -04:00
parent a86b98837d
commit 79e522a03e
11 changed files with 216 additions and 147 deletions

View File

@ -8,7 +8,7 @@ ArgumentEditor::ArgumentEditor(QWidget* parent)
: QDialog(parent)
, m_ui(std::make_unique<Ui::ArgumentEditor>()) {
m_ui->setupUi(this);
m_model.setStringList(QSettings().value("urde_arguments").toStringList());
m_model.setStringList(QSettings().value(QStringLiteral("urde_arguments")).toStringList());
m_ui->argumentEditor->setModel(&m_model);
}
@ -48,7 +48,7 @@ void ArgumentEditor::on_deleteButton_clicked() {
void ArgumentEditor::on_buttonBox_clicked(QAbstractButton* button) {
QDialogButtonBox* buttonBox = qobject_cast<QDialogButtonBox*>(sender());
if (button == buttonBox->button(QDialogButtonBox::Ok)) {
QSettings().setValue("urde_arguments", m_model.stringList());
QSettings().setValue(QStringLiteral("urde_arguments"), m_model.stringList());
accept();
} else {
reject();

View File

@ -48,6 +48,27 @@ add_executable(hecl-gui WIN32 MACOSX_BUNDLE
${QUAZIP_SRCS}
)
target_compile_definitions(hecl-gui PRIVATE
# Disable implicit conversions from ASCII to QString.
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
# Disable implicit conversions of QByteArray to const char* or const void*
-DQT_NO_CAST_FROM_BYTEARRAY
# Disable narrowing conversions in signal/slot connect() calls.
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
# Disable unsafe overloads of QProcess' start() function.
-DQT_NO_PROCESS_COMBINED_ARGUMENT_START
# Disable implicit QString->QUrl conversions to enforce use of proper resolving functions.
-DQT_NO_URL_CAST_FROM_STRING
# Allows for more efficient string concatenation, resulting in less temporaries.
-DQT_USE_QSTRINGBUILDER
)
target_link_libraries(hecl-gui PRIVATE
Qt5::Network
Qt5::Widgets

View File

@ -92,32 +92,40 @@ VectorISA StringToVectorISA(const QString& str) {
URDEVersion::URDEVersion(const QString& filename) {
int idx;
QString useFilename = filename;
if ((idx = filename.indexOf('.')) >= 0) {
if ((idx = filename.indexOf(QLatin1Char{'.'})) >= 0) {
m_extension = QString(filename).remove(0, idx);
useFilename.truncate(idx);
}
QStringList list = useFilename.split('-');
if (list.size() >= 2)
const QStringList list = useFilename.split(QLatin1Char{'-'});
if (list.size() >= 2) {
m_version = list[1].toInt();
if (list.size() >= 3)
}
if (list.size() >= 3) {
m_platform = StringToPlatform(list[2]);
if (list.size() >= 4)
}
if (list.size() >= 4) {
m_architecture = StringToArchitecture(list[3]);
if (list.size() >= 5)
}
if (list.size() >= 5) {
m_vectorISA = StringToVectorISA(list[4]);
}
}
QString URDEVersion::fileString(bool withExtension) const {
if (m_version < 0)
if (m_version < 0) {
return {};
if (withExtension && !m_extension.isEmpty())
return QString("urde-%1-%2-%3-%4%5")
}
if (withExtension && !m_extension.isEmpty()) {
return QStringLiteral("urde-%1-%2-%3-%4%5")
.arg(QString::number(m_version), PlatformToString(m_platform), ArchitectureToString(m_architecture),
VectorISAToString(m_vectorISA), m_extension);
else
return QString("urde-%1-%2-%3-%4")
} else {
return QStringLiteral("urde-%1-%2-%3-%4")
.arg(QString::number(m_version), PlatformToString(m_platform), ArchitectureToString(m_architecture),
VectorISAToString(m_vectorISA));
}
}
#ifndef _WIN32

View File

@ -32,12 +32,12 @@ void DownloadManager::_validateCert(QNetworkReply* reply) {
QSslCertificate peerCert = reply->sslConfiguration().peerCertificate();
QSslKey peerKey = peerCert.publicKey();
if (peerKey != AxioDLPublicKey && peerKey != AxioDLEdgePublicKey) {
auto cn = peerCert.subjectInfo(QSslCertificate::CommonName);
if (!cn.empty())
setError(QNetworkReply::SslHandshakeFailedError,
QStringLiteral("Certificate pinning mismatch \"") + cn.first() + "\"");
else
setError(QNetworkReply::SslHandshakeFailedError, QStringLiteral("Certificate pinning mismatch"));
const auto cn = peerCert.subjectInfo(QSslCertificate::CommonName);
if (cn.empty()) {
setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch"));
} else {
setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch \"%1\"").arg(cn.first()));
}
reply->abort();
}
#endif
@ -47,12 +47,15 @@ static const QString Domain = QStringLiteral("https://releases.axiodl.com/");
static const QString Index = QStringLiteral("index.txt");
void DownloadManager::fetchIndex() {
if (m_indexInProgress)
if (m_indexInProgress) {
return;
}
resetError();
QString track = QSettings().value("update_track").toString();
QString url = Domain + track + '/' + CurPlatformString + '/' + Index;
const QString track = QSettings().value(QStringLiteral("update_track")).toString();
const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, Index));
m_indexInProgress = m_netManager.get(QNetworkRequest(url));
connect(m_indexInProgress, &QNetworkReply::finished, this, &DownloadManager::indexFinished);
connect(m_indexInProgress, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error), this,
@ -61,14 +64,15 @@ void DownloadManager::fetchIndex() {
}
void DownloadManager::fetchBinary(const QString& str, const QString& outPath) {
if (m_binaryInProgress)
if (m_binaryInProgress) {
return;
}
resetError();
m_outPath = outPath;
const QString track = QSettings().value("update_track").toString();
const QString url = Domain + track + '/' + CurPlatformString + '/' + str;
const QString track = QSettings().value(QStringLiteral("update_track")).toString();
const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, str));
m_binaryInProgress = m_netManager.get(QNetworkRequest(url));
connect(m_binaryInProgress, &QNetworkReply::finished, this, &DownloadManager::binaryFinished);
connect(m_binaryInProgress, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error), this,
@ -121,7 +125,7 @@ void DownloadManager::binaryFinished() {
QBuffer buff(&all);
QuaZip zip(&buff);
if (!zip.open(QuaZip::mdUnzip)) {
setError(QNetworkReply::UnknownContentError, "Unable to open zip archive.");
setError(QNetworkReply::UnknownContentError, tr("Unable to open zip archive."));
m_binaryInProgress->deleteLater();
m_binaryInProgress = nullptr;
return;

View File

@ -485,14 +485,14 @@ void ParseEscapeSequence(int attribute, QListIterator<QString>& i, QTextCharForm
}
void ReturnInsert(QTextCursor& cur, const QString& text) {
auto DoLine = [&](const QString& line) {
auto DoReturn = [&](const QString& ret) {
const auto DoLine = [&](const QString& line) {
const auto DoReturn = [&](const QString& ret) {
if (!ret.isEmpty()) {
cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size());
cur.insertText(ret);
}
};
QStringList list = line.split('\r');
const QStringList list = line.split(QLatin1Char{'\r'});
DoReturn(list.front());
if (list.size() > 1) {
for (auto it = list.begin() + 1; it != list.end(); ++it) {
@ -503,9 +503,9 @@ void ReturnInsert(QTextCursor& cur, const QString& text) {
};
#if _WIN32
QStringList lineSplit = text.split("\r\n");
const QStringList lineSplit = text.split(QStringLiteral("\r\n"));
#else
QStringList lineSplit = text.split('\n');
const QStringList lineSplit = text.split(QLatin1Char{'\n'});
#endif
DoLine(lineSplit.front());
if (lineSplit.size() > 1) {
@ -518,14 +518,14 @@ void ReturnInsert(QTextCursor& cur, const QString& text) {
}
void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format) {
auto DoLine = [&](const QString& line) {
auto DoReturn = [&](const QString& ret) {
const auto DoLine = [&](const QString& line) {
const auto DoReturn = [&](const QString& ret) {
if (!ret.isEmpty()) {
cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size());
cur.insertText(ret, format);
}
};
QStringList list = line.split('\r');
const QStringList list = line.split(QLatin1Char{'\r'});
DoReturn(list.front());
if (list.size() > 1) {
for (auto it = list.begin() + 1; it != list.end(); ++it) {
@ -536,9 +536,9 @@ void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat&
};
#if _WIN32
QStringList lineSplit = text.split("\r\n");
const QStringList lineSplit = text.split(QStringLiteral("\r\n"));
#else
QStringList lineSplit = text.split('\n');
const QStringList lineSplit = text.split(QLatin1Char{'\n'});
#endif
DoLine(lineSplit.front());
if (lineSplit.size() > 1) {

View File

@ -66,7 +66,7 @@ bool ExtractZip::extractFile(QuaZip& zip, QString fileName, QString fileDest) {
// Controllo esistenza cartella file risultato
QDir curDir;
if (fileDest.endsWith('/')) {
if (fileDest.endsWith(QLatin1Char{'/'})) {
if (!curDir.mkpath(fileDest)) {
return false;
}
@ -81,7 +81,7 @@ bool ExtractZip::extractFile(QuaZip& zip, QString fileName, QString fileDest) {
return false;
QFile::Permissions srcPerm = info.getPermissions();
if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir()) {
if (fileDest.endsWith(QLatin1Char{'/'}) && QFileInfo(fileDest).isDir()) {
if (srcPerm != 0) {
QFile(fileDest).setPermissions(srcPerm);
}
@ -125,15 +125,16 @@ bool ExtractZip::extractFile(QuaZip& zip, QString fileName, QString fileDest) {
* * non si riesce a chiudere l'oggetto zip;
*/
bool ExtractZip::extractDir(QuaZip& zip, QString dir) {
QDir directory(dir);
const QDir directory(dir);
if (!zip.goToFirstFile()) {
return false;
}
do {
QString name = zip.getCurrentFileName();
QString absFilePath = directory.absoluteFilePath(name);
if (!extractFile(zip, "", absFilePath))
const QString name = zip.getCurrentFileName();
const QString absFilePath = directory.absoluteFilePath(name);
if (!extractFile(zip, {}, absFilePath)) {
return false;
}
} while (zip.goToNextFile());
return true;

View File

@ -6,11 +6,11 @@
extern hecl::CVar* hecl::com_developer;
LaunchMenu::LaunchMenu(hecl::CVarCommons& commons, QWidget* parent)
: QMenu("Launch Menu", parent)
: QMenu(tr("Launch Menu"), parent)
, m_commons(commons)
, m_apiMenu("Graphics API", this)
, m_msaaMenu("Anti-Aliasing", this)
, m_anisoMenu("Anisotropic Filtering", this)
, m_apiMenu(tr("Graphics API"), this)
, m_msaaMenu(tr("Anti-Aliasing"), this)
, m_anisoMenu(tr("Anisotropic Filtering"), this)
, m_apiGroup(this)
, m_msaaGroup(this)
, m_anisoGroup(this) {
@ -42,16 +42,18 @@ LaunchMenu::LaunchMenu(hecl::CVarCommons& commons, QWidget* parent)
m_apiMenu.addActions(m_apiGroup.actions());
m_msaaMenu.addActions(m_msaaGroup.actions());
m_anisoMenu.addActions(m_anisoGroup.actions());
addMenu(&m_apiMenu)->setToolTip(m_commons.m_graphicsApi->rawHelp().data());
addMenu(&m_msaaMenu)->setToolTip(m_commons.m_drawSamples->rawHelp().data());
addMenu(&m_anisoMenu)->setToolTip(m_commons.m_texAnisotropy->rawHelp().data());
QAction* argumentEditor = addAction("Edit Runtime Arguments");
addMenu(&m_apiMenu)->setToolTip(QString::fromUtf8(m_commons.m_graphicsApi->rawHelp().data()));
addMenu(&m_msaaMenu)->setToolTip(QString::fromUtf8(m_commons.m_drawSamples->rawHelp().data()));
addMenu(&m_anisoMenu)->setToolTip(QString::fromUtf8(m_commons.m_texAnisotropy->rawHelp().data()));
const QAction* argumentEditor = addAction(tr("Edit Runtime Arguments"));
connect(argumentEditor, &QAction::triggered, this, &LaunchMenu::editRuntimeArgs);
initDeepColor();
initDeveloperMode();
initCheats();
}
LaunchMenu::~LaunchMenu() = default;
void LaunchMenu::initApiAction(const QString& action) {
QAction* act = m_apiGroup.addAction(action);
connect(act, &QAction::triggered, this, &LaunchMenu::apiTriggered);
@ -77,32 +79,32 @@ void LaunchMenu::initAnisoAction(const QString& action) {
}
void LaunchMenu::initDeepColor() {
QAction* act = addAction("Deep Color");
act->setToolTip(m_commons.m_deepColor->rawHelp().data());
QAction* act = addAction(tr("Deep Color"));
act->setToolTip(QString::fromUtf8(m_commons.m_deepColor->rawHelp().data()));
act->setCheckable(true);
act->setChecked(m_commons.getDeepColor());
connect(act, &QAction::triggered, this, &LaunchMenu::deepColorTriggered);
}
void LaunchMenu::initDeveloperMode() {
QAction* act = addAction("Developer Mode");
act->setToolTip(hecl::com_developer->rawHelp().data());
act->setCheckable(true);
act->setChecked(hecl::com_developer->toBoolean());
connect(act, &QAction::triggered, this, &LaunchMenu::developerModeTriggered);
m_developerMode = addAction(tr("Developer Mode"));
m_developerMode->setToolTip(QString::fromUtf8(hecl::com_developer->rawHelp().data()));
m_developerMode->setCheckable(true);
m_developerMode->setChecked(hecl::com_developer->toBoolean());
connect(m_developerMode, &QAction::triggered, this, &LaunchMenu::developerModeTriggered);
}
void LaunchMenu::initCheats() {
QAction* act = addAction("Enable Cheats");
act->setToolTip(hecl::com_enableCheats->rawHelp().data());
act->setCheckable(true);
act->setChecked(hecl::com_enableCheats->toBoolean());
connect(act, &QAction::triggered, this, &LaunchMenu::cheatsTriggered);
m_enableCheats = addAction(tr("Enable Cheats"));
m_enableCheats->setToolTip(QString::fromUtf8(hecl::com_enableCheats->rawHelp().data()));
m_enableCheats->setCheckable(true);
m_enableCheats->setChecked(hecl::com_enableCheats->toBoolean());
connect(m_enableCheats, &QAction::triggered, this, &LaunchMenu::cheatsTriggered);
}
void LaunchMenu::apiTriggered() {
QString apiStr = qobject_cast<QAction*>(sender())->text();
apiStr = apiStr.remove('&');
apiStr = apiStr.remove(QLatin1Char{'&'});
m_commons.setGraphicsApi(apiStr.toStdString());
m_commons.serialize();
}
@ -123,13 +125,10 @@ void LaunchMenu::deepColorTriggered() {
}
void LaunchMenu::developerModeTriggered() {
bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
const bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
if (hecl::com_enableCheats->toBoolean() && !isChecked) {
for (QAction* action : actions()) {
QString text = action->text().remove('&');
if (text == "Enable Cheats" && action->isChecked())
action->setChecked(false);
}
m_enableCheats->setChecked(false);
}
hecl::CVarManager::instance()->setDeveloperMode(isChecked, true);
@ -137,13 +136,10 @@ void LaunchMenu::developerModeTriggered() {
}
void LaunchMenu::cheatsTriggered() {
bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
const bool isChecked = qobject_cast<QAction*>(sender())->isChecked();
if (!hecl::com_developer->toBoolean() && isChecked) {
for (QAction* action : actions()) {
QString text = action->text().remove('&');
if (text == "Developer Mode" && !action->isChecked())
action->setChecked(true);
}
m_developerMode->setChecked(false);
}
hecl::CVarManager::instance()->setCheatsEnabled(isChecked, true);

View File

@ -1,10 +1,13 @@
#pragma once
#include <QMenu>
namespace hecl {
struct CVarCommons;
}
class QAction;
class LaunchMenu : public QMenu {
Q_OBJECT
hecl::CVarCommons& m_commons;
@ -17,6 +20,9 @@ class LaunchMenu : public QMenu {
QActionGroup m_msaaGroup;
QActionGroup m_anisoGroup;
QAction* m_developerMode = nullptr;
QAction* m_enableCheats = nullptr;
void initApiAction(const QString& action);
void initMsaaAction(const QString& action);
void initAnisoAction(const QString& action);
@ -25,7 +31,8 @@ class LaunchMenu : public QMenu {
void initCheats();
public:
LaunchMenu(hecl::CVarCommons& commons, QWidget* parent = Q_NULLPTR);
explicit LaunchMenu(hecl::CVarCommons& commons, QWidget* parent = Q_NULLPTR);
~LaunchMenu() override;
public slots:
void apiTriggered();

View File

@ -53,7 +53,7 @@ static void KillProcessTree(QProcess& proc) {
}
#endif
const QStringList MainWindow::skUpdateTracks = QStringList() << "stable" << "dev";
const QStringList MainWindow::skUpdateTracks = {QStringLiteral("stable"), QStringLiteral("dev")};
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
@ -64,10 +64,12 @@ MainWindow::MainWindow(QWidget* parent)
, m_heclProc(this)
, m_dlManager(this)
, m_launchMenu(m_cvarCommons, this) {
if (m_settings.value("urde_arguments").isNull())
m_settings.setValue("urde_arguments", QStringList() << "--no-shader-warmup");
if (m_settings.value("update_track").isNull())
m_settings.setValue("update_track", "stable");
if (m_settings.value(QStringLiteral("urde_arguments")).isNull()) {
m_settings.setValue(QStringLiteral("urde_arguments"), QStringList{QStringLiteral("--no-shader-warmup")});
}
if (m_settings.value(QStringLiteral("update_track")).isNull()) {
m_settings.setValue(QStringLiteral("update_track"), QStringLiteral("stable"));
}
m_ui->setupUi(this);
m_ui->heclTabs->setCurrentIndex(0);
@ -89,8 +91,8 @@ MainWindow::MainWindow(QWidget* parent)
pal.setColor(QPalette::Button, QColor(53, 53, 72));
m_updateURDEButton->setPalette(pal);
connect(m_updateURDEButton, &QPushButton::clicked, this, &MainWindow::onUpdateURDEPressed);
qDebug() << "Stored track " << m_settings.value("update_track");
const int index = skUpdateTracks.indexOf(m_settings.value("update_track").toString());
qDebug() << "Stored track " << m_settings.value(QStringLiteral("update_track"));
const int index = skUpdateTracks.indexOf(m_settings.value(QStringLiteral("update_track")).toString());
m_ui->devTrackWarning->setVisible(index == 1);
m_ui->updateTrackComboBox->setCurrentIndex(index);
connect(m_ui->updateTrackComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
@ -125,13 +127,15 @@ void MainWindow::onExtract() {
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
m_heclProc.setWorkingDirectory(m_path);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TERM", "xterm-color");
env.insert("ConEmuANSI", "ON");
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
m_heclProc.setProcessEnvironment(env);
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onExtractFinished);
m_heclProc.start(m_heclPath, {"extract", "-y", "-g", "-o", m_path, imgPath},
QIODevice::ReadOnly | QIODevice::Unbuffered);
const QStringList heclProcArguments{
QStringLiteral("extract"), QStringLiteral("-y"), QStringLiteral("-g"), QStringLiteral("-o"), m_path, imgPath};
m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
m_ui->heclTabs->setCurrentIndex(0);
@ -158,12 +162,14 @@ void MainWindow::onPackage() {
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
m_heclProc.setWorkingDirectory(m_path);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TERM", "xterm-color");
env.insert("ConEmuANSI", "ON");
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
m_heclProc.setProcessEnvironment(env);
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onPackageFinished);
m_heclProc.start(m_heclPath, {"package", "-y", "-g"}, QIODevice::ReadOnly | QIODevice::Unbuffered);
const QStringList heclProcArguments{QStringLiteral("package"), QStringLiteral("-y"), QStringLiteral("-g")};
m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
m_ui->heclTabs->setCurrentIndex(0);
@ -195,14 +201,18 @@ void MainWindow::onLaunch() {
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
m_heclProc.setWorkingDirectory(m_path);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TERM", "xterm-color");
env.insert("ConEmuANSI", "ON");
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
m_heclProc.setProcessEnvironment(env);
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onLaunchFinished);
m_heclProc.start(m_urdePath, QStringList() << (m_path + "/out")
<< m_settings.value("urde_arguments").toStringList().join(' ').split(' '),
QIODevice::ReadOnly | QIODevice::Unbuffered);
const auto heclProcArguments = QStringList{m_path + QStringLiteral("/out")}
<< m_settings.value(QStringLiteral("urde_arguments"))
.toStringList()
.join(QLatin1Char{' '})
.split(QLatin1Char{' '});
m_heclProc.start(m_urdePath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
m_ui->heclTabs->setCurrentIndex(0);
@ -247,7 +257,7 @@ void MainWindow::onDownloadPressed() {
QString filename = m_ui->binaryComboBox->currentData().value<URDEVersion>().fileString(true);
disableOperations();
m_ui->downloadButton->setEnabled(false);
m_dlManager.fetchBinary(filename, m_path + '/' + filename);
m_dlManager.fetchBinary(filename, m_path + QLatin1Char{'/'} + filename);
}
void MainWindow::onUpdateURDEPressed() {
@ -305,41 +315,50 @@ void MainWindow::enableOperations() {
m_ui->launchBtn->setText(QStringLiteral("Launch"));
m_ui->extractBtn->setEnabled(true);
if (QFile::exists(m_path + "/MP1/!original_ids.yaml")) {
if (QFile::exists(m_path + QStringLiteral("/MP1/!original_ids.yaml"))) {
m_ui->packageBtn->setEnabled(true);
if (isPackageComplete())
m_ui->launchBtn->setEnabled(true);
}
if (!m_ui->sysReqTable->isBlenderVersionOk())
insertContinueNote("Blender 2.78+ must be installed. Please download via Steam or blender.org.");
insertContinueNote(tr("Blender 2.78+ must be installed. Please download via Steam or blender.org."));
else if (m_ui->launchBtn->isEnabled())
insertContinueNote("Package complete - Press 'Launch' to start URDE.");
insertContinueNote(tr("Package complete - Press 'Launch' to start URDE."));
else if (m_ui->packageBtn->isEnabled())
insertContinueNote("Extract complete - Press 'Package' to continue.");
insertContinueNote(tr("Extract complete - Press 'Package' to continue."));
else if (m_ui->extractBtn->isEnabled())
insertContinueNote("Press 'Extract' to begin.");
insertContinueNote(tr("Press 'Extract' to begin."));
}
bool MainWindow::isPackageComplete() const {
return
#if RUNTIME_ORIGINAL_IDS
QFile::exists(m_path + "/out/files/!original_ids.upak") &&
QFile::exists(m_path + QStringLiteral("/out/files/!original_ids.upak")) &&
#endif
QFile::exists(m_path + "/out/files/AudioGrp.upak") && QFile::exists(m_path + "/out/files/GGuiSys.upak") &&
QFile::exists(m_path + "/out/files/Metroid1.upak") && QFile::exists(m_path + "/out/files/Metroid2.upak") &&
QFile::exists(m_path + "/out/files/Metroid3.upak") && QFile::exists(m_path + "/out/files/Metroid4.upak") &&
QFile::exists(m_path + "/out/files/metroid5.upak") && QFile::exists(m_path + "/out/files/Metroid6.upak") &&
QFile::exists(m_path + "/out/files/Metroid7.upak") && QFile::exists(m_path + "/out/files/Metroid8.upak") &&
QFile::exists(m_path + "/out/files/MidiData.upak") && QFile::exists(m_path + "/out/files/MiscData.upak") &&
QFile::exists(m_path + "/out/files/NoARAM.upak") && QFile::exists(m_path + "/out/files/SamGunFx.upak") &&
QFile::exists(m_path + "/out/files/SamusGun.upak") && QFile::exists(m_path + "/out/files/SlideShow.upak") &&
QFile::exists(m_path + "/out/files/TestAnim.upak") && QFile::exists(m_path + "/out/files/Tweaks.upak");
QFile::exists(m_path + QStringLiteral("/out/files/AudioGrp.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/GGuiSys.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid1.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid2.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid3.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid4.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/metroid5.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid6.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid7.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Metroid8.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/MidiData.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/MiscData.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/NoARAM.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/SamGunFx.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/SamusGun.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/SlideShow.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/TestAnim.upak")) &&
QFile::exists(m_path + QStringLiteral("/out/files/Tweaks.upak"));
}
static bool GetDLPackage(const QString& path, QString& dlPackage) {
QProcess proc;
proc.start(path, {"--dlpackage"}, QIODevice::ReadOnly);
proc.start(path, {QStringLiteral("--dlpackage")}, QIODevice::ReadOnly);
if (proc.waitForStarted()) {
proc.waitForFinished();
if (proc.exitCode() == 100)
@ -363,17 +382,17 @@ bool MainWindow::checkDownloadedBinary() {
}
#if __APPLE__
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";
QString urdePath = m_path + QStringLiteral("/URDE.app/Contents/MacOS/urde");
QString heclPath = m_path + QStringLiteral("/URDE.app/Contents/MacOS/hecl");
QString visigenPath = m_path + QStringLiteral("/URDE.app/Contents/MacOS/visigen");
#elif _WIN32
QString urdePath = m_path + "/urde.exe";
QString heclPath = m_path + "/hecl.exe";
QString visigenPath = m_path + "/visigen.exe";
QString urdePath = m_path + QStringLiteral("/urde.exe");
QString heclPath = m_path + QStringLiteral("/hecl.exe");
QString visigenPath = m_path + QStringLiteral("/visigen.exe");
#else
QString urdePath = m_path + "/urde";
QString heclPath = m_path + "/hecl";
QString visigenPath = m_path + "/visigen";
QString urdePath = m_path + QStringLiteral("/urde");
QString heclPath = m_path + QStringLiteral("/hecl");
QString visigenPath = m_path + QStringLiteral("/visigen");
#endif
urdePath = QFileInfo(urdePath).absoluteFilePath();
heclPath = QFileInfo(heclPath).absoluteFilePath();
@ -445,8 +464,8 @@ void MainWindow::setPath(const QString& path) {
void MainWindow::initSlots() {
connect(&m_heclProc, &QProcess::readyRead, [=]() {
QByteArray bytes = m_heclProc.readAll();
setTextTermFormatting(bytes);
const QByteArray bytes = m_heclProc.readAll();
setTextTermFormatting(QString::fromUtf8(bytes));
});
connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::onExtract);
@ -457,7 +476,7 @@ void MainWindow::initSlots() {
connect(m_ui->browseBtn, &QPushButton::clicked, [=]() {
FileDirDialog dialog(this);
dialog.setDirectory(m_path);
dialog.setWindowTitle("Select Working Directory");
dialog.setWindowTitle(tr("Select Working Directory"));
int res = dialog.exec();
if (res == QFileDialog::Rejected)
return;
@ -474,7 +493,7 @@ void MainWindow::initSlots() {
void MainWindow::setTextTermFormatting(const QString& text) {
m_inContinueNote = false;
QRegExp const escapeSequenceExpression(R"(\x1B\[([\d;\?FA]+)([mlh]?))");
QRegExp const escapeSequenceExpression(QStringLiteral(R"(\x1B\[([\d;\?FA]+)([mlh]?))"));
QTextCharFormat defaultTextCharFormat = m_cursor.charFormat();
int offset = escapeSequenceExpression.indexIn(text);
ReturnInsert(m_cursor, text.mid(0, offset));
@ -482,8 +501,8 @@ void MainWindow::setTextTermFormatting(const QString& text) {
while (offset >= 0) {
int previousOffset = offset + escapeSequenceExpression.matchedLength();
QStringList captures = escapeSequenceExpression.capturedTexts();
if (captures.size() >= 3 && captures[2] == "m") {
QStringList capturedTexts = captures[1].split(';');
if (captures.size() >= 3 && captures[2] == QStringLiteral("m")) {
QStringList capturedTexts = captures[1].split(QLatin1Char{';'});
QListIterator<QString> i(capturedTexts);
while (i.hasNext()) {
bool ok = false;
@ -491,7 +510,8 @@ void MainWindow::setTextTermFormatting(const QString& text) {
Q_ASSERT(ok);
ParseEscapeSequence(attribute, i, textCharFormat, defaultTextCharFormat);
}
} else if (captures.size() >= 2 && (captures[1].endsWith('F') || captures[1].endsWith('A'))) {
} else if (captures.size() >= 2 &&
(captures[1].endsWith(QLatin1Char{'F'}) || captures[1].endsWith(QLatin1Char{'A'}))) {
int lineCount = captures[1].chopped(1).toInt();
if (!lineCount)
lineCount = 1;
@ -526,8 +546,9 @@ void MainWindow::insertContinueNote(const QString& text) {
m_ui->processOutput->ensureCursorVisible();
}
void MainWindow::onUpdateTrackChanged(int index) {
qDebug() << "Track changed from " << m_settings.value("update_track") << " to " << skUpdateTracks[index];
m_settings.setValue("update_track", skUpdateTracks[index]);
qDebug() << "Track changed from " << m_settings.value(QStringLiteral("update_track")) << " to "
<< skUpdateTracks[index];
m_settings.setValue(QStringLiteral("update_track"), skUpdateTracks[index]);
m_dlManager.fetchIndex();
m_ui->devTrackWarning->setVisible(index == 1);
}

View File

@ -43,29 +43,39 @@ static QString GetWindowsVersionString() {
SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent) {
#ifdef __linux__
QFile file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
QFile file(QStringLiteral("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"));
if (file.open(QFile::ReadOnly)) {
QString str(file.readAll());
const QString str(QString::fromUtf8(file.readAll()));
m_cpuSpeed = str.toInt() / 1000;
m_cpuSpeedStr.sprintf("%g GHz", m_cpuSpeed / 1000.0);
}
#elif defined(__APPLE__)
QProcess spProc;
spProc.start("system_profiler", {"-xml", "SPHardwareDataType"}, QProcess::ReadOnly);
spProc.start(QStringLiteral("system_profiler"), {QStringLiteral("-xml"), QStringLiteral("SPHardwareDataType")},
QProcess::ReadOnly);
spProc.waitForFinished();
QDomDocument spDoc;
spDoc.setContent(spProc.readAll());
QDomElement spDocElem = spDoc.documentElement();
QDomElement n = spDocElem.firstChildElement("array").firstChildElement("dict").firstChildElement("key");
while (!n.isNull() && n.text() != "_items")
n = n.nextSiblingElement("key");
QDomElement n = spDocElem.firstChildElement(QStringLiteral("array"))
.firstChildElement(QStringLiteral("dict"))
.firstChildElement(QStringLiteral("key"));
while (!n.isNull() && n.text() != QStringLiteral("_items")) {
n = n.nextSiblingElement(QStringLiteral("key"));
}
if (!n.isNull()) {
n = n.nextSiblingElement("array").firstChildElement("dict").firstChildElement("key");
while (!n.isNull() && n.text() != "current_processor_speed")
n = n.nextSiblingElement("key");
n = n.nextSiblingElement(QStringLiteral("array"))
.firstChildElement(QStringLiteral("dict"))
.firstChildElement(QStringLiteral("key"));
while (!n.isNull() && n.text() != QStringLiteral("current_processor_speed")) {
n = n.nextSiblingElement(QStringLiteral("key"));
}
if (!n.isNull()) {
n = n.nextSiblingElement("string");
double speed = n.text().split(' ').front().toDouble();
n = n.nextSiblingElement(QStringLiteral("string"));
const double speed = n.text().split(QLatin1Char{' '}).front().toDouble();
m_cpuSpeed = uint64_t(speed * 1000.0);
m_cpuSpeedStr.sprintf("%g GHz", speed);
}
@ -113,11 +123,12 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
m_osVersion = QStringLiteral("Linux");
#endif
hecl::blender::FindBlender(m_blendMajor, m_blendMinor);
if (m_blendMajor)
if (m_blendMajor) {
m_blendVersionStr =
QStringLiteral("Blender ") + QString::number(m_blendMajor) + '.' + QString::number(m_blendMinor);
else
QStringLiteral("Blender ") + QString::number(m_blendMajor) + QLatin1Char{'.'} + QString::number(m_blendMinor);
} else {
m_blendVersionStr = QStringLiteral("Not Found");
}
}
void SysReqTableModel::updateFreeDiskSpace(const QString& path) {

View File

@ -25,14 +25,14 @@ static QIcon MakeAppIcon() {
int main(int argc, char* argv[]) {
InitializePlatform();
QApplication::setOrganizationName("AxioDL");
QApplication::setApplicationName("HECL");
QApplication::setOrganizationName(QStringLiteral("AxioDL"));
QApplication::setApplicationName(QStringLiteral("HECL"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
QApplication::setStyle(QStyleFactory::create("Fusion"));
QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
QApplication a(argc, argv);
QApplication::setWindowIcon(MakeAppIcon());