From 02301e5b0d9485cb3b53d5299a0d078c13dcfba0 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 23 Feb 2022 21:28:56 -0500 Subject: [PATCH] Query installed dalamud version at startup This also shows the dalamud version in your settings --- src/assetupdater.cpp | 27 +++++---------------------- src/launchercore.cpp | 21 +++++++++++++++++++++ src/launchercore.h | 2 ++ src/settingswindow.cpp | 13 +++++++++++-- src/settingswindow.h | 5 ++++- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/assetupdater.cpp b/src/assetupdater.cpp index 0b2f721..505940d 100644 --- a/src/assetupdater.cpp +++ b/src/assetupdater.cpp @@ -45,28 +45,11 @@ void AssetUpdater::update(const ProfileSettings& profile) { return; } else { - if (QFile::exists(dataDir + "/Dalamud/Dalamud.deps.json")) { - QFile depsJson(dataDir + "/Dalamud/Dalamud.deps.json"); - depsJson.open(QFile::ReadOnly); - QJsonDocument doc = QJsonDocument::fromJson(depsJson.readAll()); - - // TODO: UGLY - QString versionString = - doc["targets"] - .toObject()[".NETCoreApp,Version=v5.0"] - .toObject() - .keys() - .filter("Dalamud")[0]; - versionString = versionString.remove("Dalamud/"); - - qInfo() << "Dalamud version installed: " << versionString; - - if (versionString != remoteDalamudVersion) { - isDalamudUpdated = false; - } else { - qInfo() << "No need to update Dalamud."; - isDalamudUpdated = true; - } + if (profile.dalamudVersion != remoteDalamudVersion) { + isDalamudUpdated = false; + } else { + qInfo() << "No need to update Dalamud."; + isDalamudUpdated = true; } } } diff --git a/src/launchercore.cpp b/src/launchercore.cpp index f08c181..33fb0f3 100755 --- a/src/launchercore.cpp +++ b/src/launchercore.cpp @@ -289,6 +289,27 @@ void LauncherCore::readInitialInformation() { #endif readWineInfo(profile); + const QString dataDir = + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + + const bool hasDalamud = QFile::exists(dataDir + "/Dalamud"); + if (hasDalamud) { + if (QFile::exists(dataDir + "/Dalamud/Dalamud.deps.json")) { + QFile depsJson(dataDir + "/Dalamud/Dalamud.deps.json"); + depsJson.open(QFile::ReadOnly); + QJsonDocument doc = QJsonDocument::fromJson(depsJson.readAll()); + + // TODO: UGLY + QString versionString = + doc["targets"] + .toObject()[".NETCoreApp,Version=v5.0"] + .toObject() + .keys() + .filter("Dalamud")[0]; + profile.dalamudVersion = versionString.remove("Dalamud/"); + } + } + if(settings.contains("gamePath") && settings.value("gamePath").canConvert() && !settings.value("gamePath").toString().isEmpty()) { profile.gamePath = settings.value("gamePath").toString(); } else { diff --git a/src/launchercore.h b/src/launchercore.h index ce78ebb..140255f 100755 --- a/src/launchercore.h +++ b/src/launchercore.h @@ -47,6 +47,8 @@ struct ProfileSettings { int refreshRate = 0; } gamescope; + QString dalamudVersion; // TODO: move out of profile settings + // login bool encryptArguments = true; bool isSapphire = false; diff --git a/src/settingswindow.cpp b/src/settingswindow.cpp index 467adfd..75f26e9 100644 --- a/src/settingswindow.cpp +++ b/src/settingswindow.cpp @@ -105,7 +105,7 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg #endif expansionVersionLabel = new QLabel(); - gameBoxLayout->addRow("Version Info", expansionVersionLabel); + gameBoxLayout->addRow("Game Version", expansionVersionLabel); auto loginBox = new QGroupBox("Login Options"); auto loginBoxLayout = new QFormLayout(); @@ -291,6 +291,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg auto dalamudBoxLayout = new QFormLayout(); dalamudBox->setLayout(dalamudBoxLayout); + mainLayout->addWidget(dalamudBox, 2, 2, 1, 1); + enableDalamudBox = new QCheckBox(); connect(enableDalamudBox, &QCheckBox::stateChanged, [=](int) { getCurrentProfile().enableDalamud = enableDalamudBox->isChecked(); @@ -299,7 +301,8 @@ SettingsWindow::SettingsWindow(LauncherWindow& window, LauncherCore& core, QWidg }); dalamudBoxLayout->addRow("Enable Dalamud Injection", enableDalamudBox); - mainLayout->addWidget(dalamudBox, 2, 2, 1, 1); + dalamudVersionLabel = new QLabel(); + dalamudBoxLayout->addRow("Dalamud Version", dalamudVersionLabel); reloadControls(); } @@ -390,7 +393,13 @@ void SettingsWindow::reloadControls() { rememberPasswordBox->setChecked(profile.rememberPassword); useSteamBox->setChecked(profile.useSteam); + // dalamud enableDalamudBox->setChecked(profile.enableDalamud); + if(profile.dalamudVersion.isEmpty()) { + dalamudVersionLabel->setText("Dalamud is not installed."); + } else { + dalamudVersionLabel->setText(profile.dalamudVersion); + } window.reloadControls(); diff --git a/src/settingswindow.h b/src/settingswindow.h index 03a443f..16ce27c 100644 --- a/src/settingswindow.h +++ b/src/settingswindow.h @@ -43,12 +43,15 @@ private: // login QCheckBox* encryptArgumentsBox = nullptr; - QCheckBox* enableDalamudBox = nullptr; QComboBox* serverType = nullptr; QLineEdit* lobbyServerURL = nullptr; QCheckBox* rememberUsernameBox = nullptr, *rememberPasswordBox = nullptr; QCheckBox* useSteamBox = nullptr; + // dalamud + QCheckBox* enableDalamudBox = nullptr; + QLabel* dalamudVersionLabel = nullptr; + bool currentlyReloadingControls = false; LauncherWindow& window;