From d7dc13e3b9ac2932531d9518c9d303cd302e1539 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 14 Jun 2019 21:28:40 -0400 Subject: fixes plugin executables having empty fields when upgrading from 2.2.0 --- src/executableslist.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 8 deletions(-) (limited to 'src/executableslist.cpp') diff --git a/src/executableslist.cpp b/src/executableslist.cpp index daf200a6..077d2a93 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -69,6 +69,10 @@ void ExecutablesList::load(const MOBase::IPluginGame* game, QSettings& settings) m_Executables.clear(); + // whether the executable list in the .ini is still using the old custom + // executables from 2.2.0, see upgradeFromCustom() + bool needsUpgrade = false; + int numCustomExecutables = settings.beginReadArray("customExecutables"); for (int i = 0; i < numCustomExecutables; ++i) { settings.setArrayIndex(i); @@ -79,6 +83,11 @@ void ExecutablesList::load(const MOBase::IPluginGame* game, QSettings& settings) if (settings.value("ownicon", false).toBool()) flags |= Executable::UseApplicationIcon; + if (settings.contains("custom")) { + // the "custom" setting only exists in older versions + needsUpgrade = true; + } + setExecutable(Executable() .title(settings.value("title").toString()) .binaryInfo(settings.value("binary").toString()) @@ -91,6 +100,9 @@ void ExecutablesList::load(const MOBase::IPluginGame* game, QSettings& settings) settings.endArray(); addFromPlugin(game, IgnoreExisting); + + if (needsUpgrade) + upgradeFromCustom(game); } void ExecutablesList::store(QSettings& settings) @@ -115,22 +127,19 @@ void ExecutablesList::store(QSettings& settings) settings.endArray(); } -void ExecutablesList::resetFromPlugin(MOBase::IPluginGame const *game) -{ - qDebug("resetting plugin executables"); - addFromPlugin(game, MoveExisting); -} - -void ExecutablesList::addFromPlugin(IPluginGame const *game, SetFlags flags) +std::vector ExecutablesList::getPluginExecutables( + MOBase::IPluginGame const *game) const { Q_ASSERT(game != nullptr); + std::vector v; + for (const ExecutableInfo &info : game->executables()) { if (!info.isValid()) { continue; } - setExecutable({info, Executable::UseApplicationIcon}, flags); + v.push_back({info, Executable::UseApplicationIcon}); } const QFileInfo eppBin(QCoreApplication::applicationDirPath() + "/explorer++/Explorer++.exe"); @@ -146,6 +155,28 @@ void ExecutablesList::addFromPlugin(IPluginGame const *game, SetFlags flags) .workingDirectory(eppBin.absolutePath()) .flags(Executable::UseApplicationIcon); + v.push_back(exe); + } + + return v; +} + +void ExecutablesList::resetFromPlugin(MOBase::IPluginGame const *game) +{ + qDebug("resetting plugin executables"); + + Q_ASSERT(game != nullptr); + + for (const auto& exe : getPluginExecutables(game)) { + setExecutable(exe, MoveExisting); + } +} + +void ExecutablesList::addFromPlugin(IPluginGame const *game, SetFlags flags) +{ + Q_ASSERT(game != nullptr); + + for (const auto& exe : getPluginExecutables(game)) { setExecutable(exe, flags); } } @@ -261,6 +292,46 @@ std::optional ExecutablesList::makeNonConflictingTitle( return {}; } +void ExecutablesList::upgradeFromCustom(MOBase::IPluginGame const *game) +{ + qDebug() << "upgrading executables list"; + + Q_ASSERT(game != nullptr); + + // prior to 2.2.1, plugin executables were special in the sense that they + // did not store certain settings, like the binary info and working directory; + // those were filled in when MO started, but never saved + // + // this interferes with the new executables list, which is completely + // customizable, because plugin executables are only added to the list when + // they don't exist at all and are ignored otherwise, leaving some of the + // fields completely blank + // + // when the "custom" setting is found in the .ini file (see load()), it is + // assumed that the older scheme is still present; in that case, the plugin + // executables force their binary info and working directory into the existing + // executables one last time + // + // from that point on, plugin executables are ignored unless they're + // completely missing from the list, allowing users to customize them as they + // want + + for (const auto& exe : getPluginExecutables(game)) { + auto itor = find(exe.title()); + if (itor == end()){ + continue; + } + + if (!itor->binaryInfo().exists()) { + itor->binaryInfo(exe.binaryInfo()); + } + + if (itor->workingDirectory().isEmpty()) { + itor->workingDirectory(exe.workingDirectory()); + } + } +} + Executable::Executable(QString title) : m_title(title) -- cgit v1.3.1