extend setting to allow user chose between release or any

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-12-12 01:15:53 +02:00
parent b431dbd40e
commit 2582064323
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
8 changed files with 57 additions and 18 deletions

View file

@ -326,10 +326,11 @@ static const Meta::Version::Ptr& getLatestVersion(const Meta::Version::Ptr& a, c
return (a->rawTime() > b->rawTime() ? a : b);
}
Version::Ptr VersionList::getLatest()
Version::Ptr VersionList::getLatest(bool onlyRelease)
{
Version::Ptr latestCompat = nullptr;
for (auto ver : m_versions) {
if (!onlyRelease || ver->type() == "release")
latestCompat = getLatestVersion(latestCompat, ver);
}
return latestCompat;

View file

@ -45,7 +45,7 @@ class VersionList : public BaseVersionList, public BaseEntity {
BaseVersion::Ptr getRecommended() const override;
Version::Ptr getRecommendedForParent(const QString& uid, const QString& version);
Version::Ptr getLatestForParent(const QString& uid, const QString& version);
Version::Ptr getLatest();
Version::Ptr getLatest(bool onlyRelease = true);
QVariant data(const QModelIndex& index, int role) const override;
RoleList providesRoles() const override;

View file

@ -187,6 +187,7 @@ void MinecraftInstance::loadSpecificSettings()
auto argsOverride = m_settings->registerSetting("OverrideJavaArgs", false);
m_settings->registerSetting("AutomaticJava", false);
m_settings->registerSetting("UseLatestMinecraftVersion", false);
m_settings->registerSetting("UseLatestMinecraftVersionType", "release");
if (auto global_settings = globalSettings()) {
m_settings->registerOverride(global_settings->getSetting("JavaPath"), locationOverride);

View file

@ -10,12 +10,12 @@ void MinecraftLoadAndCheck::executeTask()
// add offline metadata load task
auto components = m_inst->getPackProfile();
if (m_inst->settings()->get("UseLatestMinecraftVersion").toBool()) {
if (APPLICATION->settings()->get("AutomaticJavaSwitch").toBool() && m_inst->settings()->get("AutomaticJava").toBool() &&
m_inst->settings()->get("OverrideJavaLocation").toBool()) {
auto releaseType = m_inst->settings()->get("UseLatestMinecraftVersionType").toString();
if (components->updateLatestMinecraft(releaseType == "release") && APPLICATION->settings()->get("AutomaticJavaSwitch").toBool() &&
m_inst->settings()->get("AutomaticJava").toBool() && m_inst->settings()->get("OverrideJavaLocation").toBool()) {
m_inst->settings()->set("OverrideJavaLocation", false);
m_inst->settings()->set("JavaPath", "");
}
components->updateLatestMinecraft();
}
if (auto result = components->reload(m_netmode); !result) {
emitFailed(result.error);

View file

@ -1072,19 +1072,23 @@ QList<ModPlatform::ModLoaderType> PackProfile::getModLoadersList()
return result;
}
void PackProfile::updateLatestMinecraft()
bool PackProfile::updateLatestMinecraft(bool onlyRelease)
{
const QString uid = "net.minecraft";
auto patch = getComponent(uid);
auto oldVersion = patch->getVersion();
patch->waitLoadMeta(); // make sure we have latest versions
auto list = patch->getVersionList();
if (!list) {
return;
return false;
}
auto latest = list->getLatest();
auto latest = list->getLatest(onlyRelease);
if (oldVersion != latest->descriptor()) {
qDebug() << "Change" << uid << "to" << latest.get();
setComponentVersion(uid, latest->descriptor(), true);
resolve(Net::Mode::Online);
}
return oldVersion != latest->descriptor();
}

View file

@ -164,7 +164,7 @@ class PackProfile : public QAbstractListModel {
/// apply the component patches. Catches all the errors and returns true/false for success/failure
void invalidateLaunchProfile();
void updateLatestMinecraft();
bool updateLatestMinecraft(bool onlyRelease = true);
private:
void scheduleSave();

View file

@ -61,7 +61,7 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstance* instance, QW
m_ui->serverJoinGroupBox->hide();
m_ui->globalDataPacksGroupBox->hide();
m_ui->loaderGroup->hide();
m_ui->latestMCVersionCheckBox->hide();
m_ui->latestMCVersionGroupBox->hide();
} else {
m_javaSettings = new JavaSettingsWidget(m_instance, this);
m_ui->javaScrollArea->setWidget(m_javaSettings);
@ -294,7 +294,11 @@ void MinecraftSettingsWidget::loadSettings()
for (auto c : blockSignalsCheckBoxes) {
c->blockSignals(false);
}
m_ui->latestMCVersionCheckBox->setChecked(settings->get("UseLatestMinecraftVersion").toBool());
m_ui->latestMCVersionGroupBox->setChecked(settings->get("UseLatestMinecraftVersion").toBool());
auto autoUpdateType = settings->get("UseLatestMinecraftVersionType").toString() == "release";
m_ui->releaseRadioButton->setChecked(autoUpdateType);
m_ui->anyRadioButton->setChecked(!autoUpdateType);
}
m_ui->legacySettingsGroupBox->setChecked(settings->get("OverrideLegacySettings").toBool());
@ -472,7 +476,8 @@ void MinecraftSettingsWidget::saveSettings()
settings->reset("InstanceAccountId");
}
settings->set("UseLatestMinecraftVersion", m_ui->latestMCVersionCheckBox->isChecked());
settings->set("UseLatestMinecraftVersion", m_ui->latestMCVersionGroupBox->isChecked());
settings->set("UseLatestMinecraftVersionType", m_ui->releaseRadioButton->isChecked() ? "release" : "any");
}
bool overrideLegacySettings = m_instance == nullptr || m_ui->legacySettingsGroupBox->isChecked();

View file

@ -555,10 +555,35 @@ It is most likely you will need to change the path - please refer to the mod's w
</widget>
</item>
<item>
<widget class="QCheckBox" name="latestMCVersionCheckBox">
<property name="text">
<widget class="QGroupBox" name="latestMCVersionGroupBox">
<property name="title">
<string>Always use the latest minecraft version</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QRadioButton" name="releaseRadioButton">
<property name="text">
<string>Release</string>
</property>
<attribute name="buttonGroup">
<string notr="true">latestVersionModeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="anyRadioButton">
<property name="text">
<string>Any</string>
</property>
<attribute name="buttonGroup">
<string notr="true">latestVersionModeGroup</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
@ -898,4 +923,7 @@ It is most likely you will need to change the path - please refer to the mod's w
</tabstops>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="latestVersionModeGroup"/>
</buttongroups>
</ui>