clang-format

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-06-25 11:13:15 +03:00 committed by Rachel Powers
parent cf319649f9
commit 474effe7c7
No known key found for this signature in database
GPG Key ID: E10E321EB160949B
6 changed files with 74 additions and 52 deletions

View File

@ -254,8 +254,9 @@ void VersionList::setupAddedVersion(const int row, const Version::Ptr& version)
connect(version.get(), &Version::requiresChanged, this, connect(version.get(), &Version::requiresChanged, this,
[this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); }); [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
connect(version.get(), &Version::timeChanged, this, connect(version.get(), &Version::timeChanged, this, [this, row]() {
[this, row]() { emit dataChanged(index(row), index(row), { TimeRole, SortRole }); }); emit dataChanged(index(row), index(row), { TimeRole, SortRole });
});
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), { TypeRole }); }); connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), { TypeRole }); });
} }

View File

@ -46,7 +46,6 @@ class VersionList : public BaseVersionList, public BaseEntity {
Version::Ptr getRecommendedForParent(const QString& uid, const QString& version); Version::Ptr getRecommendedForParent(const QString& uid, const QString& version);
Version::Ptr getLatestForParent(const QString& uid, const QString& version); Version::Ptr getLatestForParent(const QString& uid, const QString& version);
QVariant data(const QModelIndex& index, int role) const override; QVariant data(const QModelIndex& index, int role) const override;
RoleList providesRoles() const override; RoleList providesRoles() const override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;

View File

@ -403,8 +403,8 @@ void Component::updateCachedData()
} }
} }
void Component::waitLoadMeta() { void Component::waitLoadMeta()
{
if (!m_loaded) { if (!m_loaded) {
if (!m_metaVersion || !m_metaVersion->isLoaded()) { if (!m_metaVersion || !m_metaVersion->isLoaded()) {
// wait for the loaded version from meta // wait for the loaded version from meta
@ -415,7 +415,8 @@ void Component::waitLoadMeta() {
} }
} }
QDebug operator<<(QDebug d, const Component& comp) { QDebug operator<<(QDebug d, const Component& comp)
{
d << "Component(" << comp.m_uid << " : " << comp.m_cachedVersion << ")"; d << "Component(" << comp.m_uid << " : " << comp.m_cachedVersion << ")";
return d; return d;
} }

View File

@ -178,7 +178,8 @@ void ComponentUpdateTask::loadComponents()
} }
result = composeLoadResult(result, singleResult); result = composeLoadResult(result, singleResult);
if (loadTask) { if (loadTask) {
qCDebug(instanceProfileResolveC) << d->m_profile->d->m_instance->name() << "|" << "Remote loading is being run for" << component->getName(); qCDebug(instanceProfileResolveC) << d->m_profile->d->m_instance->name() << "|"
<< "Remote loading is being run for" << component->getName();
connect(loadTask.get(), &Task::succeeded, this, [this, taskIndex]() { remoteLoadSucceeded(taskIndex); }); connect(loadTask.get(), &Task::succeeded, this, [this, taskIndex]() { remoteLoadSucceeded(taskIndex); });
connect(loadTask.get(), &Task::failed, this, [this, taskIndex](const QString& error) { remoteLoadFailed(taskIndex, error); }); connect(loadTask.get(), &Task::failed, this, [this, taskIndex](const QString& error) { remoteLoadFailed(taskIndex, error); });
connect(loadTask.get(), &Task::aborted, this, [this, taskIndex]() { remoteLoadFailed(taskIndex, tr("Aborted")); }); connect(loadTask.get(), &Task::aborted, this, [this, taskIndex]() { remoteLoadFailed(taskIndex, tr("Aborted")); });
@ -273,8 +274,8 @@ static bool gatherRequirementsFromComponents(const ComponentContainer& input, Re
output.erase(componenRequireEx); output.erase(componenRequireEx);
output.insert(result.outcome); output.insert(result.outcome);
} else { } else {
qCCritical(instanceProfileResolveC) << "Conflicting requirements:" << componentRequire.uid << "versions:" << componentRequire.equalsVersion qCCritical(instanceProfileResolveC) << "Conflicting requirements:" << componentRequire.uid
<< ";" << (*found).equalsVersion; << "versions:" << componentRequire.equalsVersion << ";" << (*found).equalsVersion;
} }
succeeded &= result.ok; succeeded &= result.ok;
} else { } else {
@ -440,7 +441,8 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly)
auto component = makeShared<Component>(d->m_profile, add.uid); auto component = makeShared<Component>(d->m_profile, add.uid);
if (!add.equalsVersion.isEmpty()) { if (!add.equalsVersion.isEmpty()) {
// exact version // exact version
qCDebug(instanceProfileResolveC) << "Adding" << add.uid << "version" << add.equalsVersion << "at position" << add.indexOfFirstDependee; qCDebug(instanceProfileResolveC)
<< "Adding" << add.uid << "version" << add.equalsVersion << "at position" << add.indexOfFirstDependee;
component->m_version = add.equalsVersion; component->m_version = add.equalsVersion;
} else { } else {
// version needs to be decided // version needs to be decided

View File

@ -247,12 +247,14 @@ void PackProfile::buildingFromScratch()
void PackProfile::scheduleSave() void PackProfile::scheduleSave()
{ {
if (!d->loaded) { if (!d->loaded) {
qDebug() << d->m_instance->name() << "|" << "Component list should never save if it didn't successfully load"; qDebug() << d->m_instance->name() << "|"
<< "Component list should never save if it didn't successfully load";
return; return;
} }
if (!d->dirty) { if (!d->dirty) {
d->dirty = true; d->dirty = true;
qDebug() << d->m_instance->name() << "|" << "Component list save is scheduled"; qDebug() << d->m_instance->name() << "|"
<< "Component list save is scheduled";
} }
d->m_saveTimer.start(); d->m_saveTimer.start();
} }
@ -279,7 +281,8 @@ QString PackProfile::patchFilePathForUid(const QString& uid) const
void PackProfile::save_internal() void PackProfile::save_internal()
{ {
qDebug() << d->m_instance->name() << "|" << "Component list save performed now"; qDebug() << d->m_instance->name() << "|"
<< "Component list save performed now";
auto filename = componentsFilePath(); auto filename = componentsFilePath();
savePackProfile(filename, d->components); savePackProfile(filename, d->components);
d->dirty = false; d->dirty = false;
@ -292,7 +295,8 @@ bool PackProfile::load()
// load the new component list and swap it with the current one... // load the new component list and swap it with the current one...
ComponentContainer newComponents; ComponentContainer newComponents;
if (!loadPackProfile(this, filename, patchesPattern(), newComponents)) { if (!loadPackProfile(this, filename, patchesPattern(), newComponents)) {
qCritical() << d->m_instance->name() << "|" << "Failed to load the component config"; qCritical() << d->m_instance->name() << "|"
<< "Failed to load the component config";
return false; return false;
} else { } else {
// FIXME: actually use fine-grained updates, not this... // FIXME: actually use fine-grained updates, not this...
@ -305,7 +309,8 @@ bool PackProfile::load()
d->componentIndex.clear(); d->componentIndex.clear();
for (auto component : newComponents) { for (auto component : newComponents) {
if (d->componentIndex.contains(component->m_uid)) { if (d->componentIndex.contains(component->m_uid)) {
qWarning() << d->m_instance->name() << "|" << "Ignoring duplicate component entry" << component->m_uid; qWarning() << d->m_instance->name() << "|"
<< "Ignoring duplicate component entry" << component->m_uid;
continue; continue;
} }
connect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged); connect(component.get(), &Component::dataChanged, this, &PackProfile::componentDataChanged);
@ -353,14 +358,17 @@ void PackProfile::resolve(Net::Mode netmode)
void PackProfile::updateSucceeded() void PackProfile::updateSucceeded()
{ {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "Component list update/resolve task succeeded"; qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "Component list update/resolve task succeeded";
d->m_updateTask.reset(); d->m_updateTask.reset();
invalidateLaunchProfile(); invalidateLaunchProfile();
} }
void PackProfile::updateFailed(const QString& error) void PackProfile::updateFailed(const QString& error)
{ {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "Component list update/resolve task failed " << "Reason:" << error; qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "Component list update/resolve task failed "
<< "Reason:" << error;
d->m_updateTask.reset(); d->m_updateTask.reset();
invalidateLaunchProfile(); invalidateLaunchProfile();
} }
@ -376,11 +384,13 @@ void PackProfile::insertComponent(size_t index, ComponentPtr component)
{ {
auto id = component->getID(); auto id = component->getID();
if (id.isEmpty()) { if (id.isEmpty()) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "Attempt to add a component with empty ID!"; qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< "Attempt to add a component with empty ID!";
return; return;
} }
if (d->componentIndex.contains(id)) { if (d->componentIndex.contains(id)) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "Attempt to add a component that is already present!"; qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< "Attempt to add a component that is already present!";
return; return;
} }
beginInsertRows(QModelIndex(), static_cast<int>(index), static_cast<int>(index)); beginInsertRows(QModelIndex(), static_cast<int>(index), static_cast<int>(index));
@ -395,7 +405,8 @@ void PackProfile::componentDataChanged()
{ {
auto objPtr = qobject_cast<Component*>(sender()); auto objPtr = qobject_cast<Component*>(sender());
if (!objPtr) { if (!objPtr) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "PackProfile got dataChanged signal from a non-Component!"; qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< "PackProfile got dataChanged signal from a non-Component!";
return; return;
} }
if (objPtr->getID() == "net.minecraft") { if (objPtr->getID() == "net.minecraft") {
@ -419,12 +430,14 @@ bool PackProfile::remove(const int index)
{ {
auto patch = getComponent(index); auto patch = getComponent(index);
if (!patch->isRemovable()) { if (!patch->isRemovable()) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "is non-removable"; qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "is non-removable";
return false; return false;
} }
if (!removeComponent_internal(patch)) { if (!removeComponent_internal(patch)) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "could not be removed"; qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "could not be removed";
return false; return false;
} }
@ -453,11 +466,13 @@ bool PackProfile::customize(int index)
{ {
auto patch = getComponent(index); auto patch = getComponent(index);
if (!patch->isCustomizable()) { if (!patch->isCustomizable()) {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "is not customizable"; qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "is not customizable";
return false; return false;
} }
if (!patch->customize()) { if (!patch->customize()) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "could not be customized"; qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "could not be customized";
return false; return false;
} }
invalidateLaunchProfile(); invalidateLaunchProfile();
@ -469,11 +484,13 @@ bool PackProfile::revertToBase(int index)
{ {
auto patch = getComponent(index); auto patch = getComponent(index);
if (!patch->isRevertible()) { if (!patch->isRevertible()) {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "is not revertible"; qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "is not revertible";
return false; return false;
} }
if (!patch->revert()) { if (!patch->revert()) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Patch" << patch->getID() << "could not be reverted"; qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "Patch" << patch->getID() << "could not be reverted";
return false; return false;
} }
invalidateLaunchProfile(); invalidateLaunchProfile();
@ -686,8 +703,8 @@ bool PackProfile::installComponents(QStringList selectedFiles)
const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json"); const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json");
if (!QFile::copy(source, target)) { if (!QFile::copy(source, target)) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "Component" << source << "could not be copied to target" qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< target; << "Component" << source << "could not be copied to target" << target;
result = false; result = false;
continue; continue;
} }
@ -720,8 +737,8 @@ bool PackProfile::installEmpty(const QString& uid, const QString& name)
QString patchFileName = FS::PathCombine(patchDir, uid + ".json"); QString patchFileName = FS::PathCombine(patchDir, uid + ".json");
QFile file(patchFileName); QFile file(patchFileName);
if (!file.open(QFile::WriteOnly)) { if (!file.open(QFile::WriteOnly)) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Error opening" << file.fileName() qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "for reading:" << file.errorString(); << "Error opening" << file.fileName() << "for reading:" << file.errorString();
return false; return false;
} }
file.write(OneSixVersionFormat::versionFileToJson(f).toJson()); file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
@ -741,8 +758,8 @@ bool PackProfile::removeComponent_internal(ComponentPtr patch)
if (fileName.size()) { if (fileName.size()) {
QFile patchFile(fileName); QFile patchFile(fileName);
if (patchFile.exists() && !patchFile.remove()) { if (patchFile.exists() && !patchFile.remove()) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "File" << fileName qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "could not be removed because:" << patchFile.errorString(); << "File" << fileName << "could not be removed because:" << patchFile.errorString();
return false; return false;
} }
} }
@ -758,8 +775,8 @@ bool PackProfile::removeComponent_internal(ComponentPtr patch)
if (finfo.exists()) { if (finfo.exists()) {
QFile jarModFile(jar[0]); QFile jarModFile(jar[0]);
if (!jarModFile.remove()) { if (!jarModFile.remove()) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "File" << jar[0] qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "could not be removed because:" << jarModFile.errorString(); << "File" << jar[0] << "could not be removed because:" << jarModFile.errorString();
return false; return false;
} }
return true; return true;
@ -816,8 +833,8 @@ bool PackProfile::installJarMods_internal(QStringList filepaths)
QFile file(patchFileName); QFile file(patchFileName);
if (!file.open(QFile::WriteOnly)) { if (!file.open(QFile::WriteOnly)) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Error opening" << file.fileName() qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "for reading:" << file.errorString(); << "Error opening" << file.fileName() << "for reading:" << file.errorString();
return false; return false;
} }
file.write(OneSixVersionFormat::versionFileToJson(f).toJson()); file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
@ -871,8 +888,8 @@ bool PackProfile::installCustomJar_internal(QString filepath)
QFile file(patchFileName); QFile file(patchFileName);
if (!file.open(QFile::WriteOnly)) { if (!file.open(QFile::WriteOnly)) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Error opening" << file.fileName() qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "for reading:" << file.errorString(); << "Error opening" << file.fileName() << "for reading:" << file.errorString();
return false; return false;
} }
file.write(OneSixVersionFormat::versionFileToJson(f).toJson()); file.write(OneSixVersionFormat::versionFileToJson(f).toJson());
@ -927,8 +944,8 @@ bool PackProfile::installAgents_internal(QStringList filepaths)
QFile patchFile(FS::PathCombine(patchDir, targetId + ".json")); QFile patchFile(FS::PathCombine(patchDir, targetId + ".json"));
if (!patchFile.open(QFile::WriteOnly)) { if (!patchFile.open(QFile::WriteOnly)) {
qCCritical(instanceProfileC) << d->m_instance->name() << "|" << "Error opening" << patchFile.fileName() qCCritical(instanceProfileC) << d->m_instance->name() << "|"
<< "for reading:" << patchFile.errorString(); << "Error opening" << patchFile.fileName() << "for reading:" << patchFile.errorString();
return false; return false;
} }
@ -950,13 +967,15 @@ std::shared_ptr<LaunchProfile> PackProfile::getProfile() const
try { try {
auto profile = std::make_shared<LaunchProfile>(); auto profile = std::make_shared<LaunchProfile>();
for (auto file : d->components) { for (auto file : d->components) {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "Applying" << file->getID() qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "Applying" << file->getID()
<< (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD"); << (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD");
file->applyTo(profile.get()); file->applyTo(profile.get());
} }
d->m_profile = profile; d->m_profile = profile;
} catch (const Exception& error) { } catch (const Exception& error) {
qCWarning(instanceProfileC) << d->m_instance->name() << "|" << "Couldn't apply profile patches because: " << error.cause(); qCWarning(instanceProfileC) << d->m_instance->name() << "|"
<< "Couldn't apply profile patches because: " << error.cause();
} }
} }
return d->m_profile; return d->m_profile;
@ -986,9 +1005,9 @@ bool PackProfile::setComponentVersion(const QString& uid, const QString& version
if (versionList) { if (versionList) {
auto recommended = versionList->getRecommendedForParent(uid, version); auto recommended = versionList->getRecommendedForParent(uid, version);
if (recommended) { if (recommended) {
qCDebug(instanceProfileC) qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< d->m_instance->name() << "|" << "setting updated loader to recommended version: " << comp->getID() << "setting updated loader to recommended version: " << comp->getID() << " = "
<< " = " << recommended->version(); << recommended->version();
comp->setVersion(recommended->version()); comp->setVersion(recommended->version());
} else { } else {
auto latest = versionList->getLatestForParent(uid, version); auto latest = versionList->getLatestForParent(uid, version);
@ -998,14 +1017,14 @@ bool PackProfile::setComponentVersion(const QString& uid, const QString& version
<< " = " << latest->version(); << " = " << latest->version();
comp->setVersion(latest->version()); comp->setVersion(latest->version());
} else { } else {
qCDebug(instanceProfileC) qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< d->m_instance->name() << "|" << "no compatible version for" << comp->getID() << "removing"; << "no compatible version for" << comp->getID() << "removing";
remove(comp->getID()); remove(comp->getID());
} }
} }
} else { } else {
qCDebug(instanceProfileC) qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< d->m_instance->name() << "|" << "no version list in metadata index for" << comp->getID(); << "no version list in metadata index for" << comp->getID();
} }
} else { } else {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << comp->getID() << ":" << comp->getVersion() qCDebug(instanceProfileC) << d->m_instance->name() << "|" << comp->getID() << ":" << comp->getVersion()
@ -1038,8 +1057,8 @@ ComponentContainer PackProfile::collectTreeLinked(const QString& uid)
{ {
ComponentContainer linked; ComponentContainer linked;
for (auto comp : d->components) { for (auto comp : d->components) {
qCDebug(instanceProfileC) << d->m_instance->name() << "|" << "scanning" << comp->getID() << ":" << comp->getVersion() qCDebug(instanceProfileC) << d->m_instance->name() << "|"
<< "for tree link"; << "scanning" << comp->getID() << ":" << comp->getVersion() << "for tree link";
auto dep = std::find_if(comp->m_cachedRequires.cbegin(), comp->m_cachedRequires.cend(), auto dep = std::find_if(comp->m_cachedRequires.cbegin(), comp->m_cachedRequires.cend(),
[uid](const Meta::Require& req) -> bool { return req.uid == uid; }); [uid](const Meta::Require& req) -> bool { return req.uid == uid; });
if (dep != comp->m_cachedRequires.cend()) { if (dep != comp->m_cachedRequires.cend()) {