From 4f01b94f01180989abbdf0407cdf95483970dba8 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Fri, 7 Jun 2019 17:53:42 -0400
Subject: replaced ExecutablesList::getExecutables() by a standard container
interface renamed ExecutablesList::init() to addFromPlugin() renamed
ExecutablesList::find() to get() and added a find() that returns an iterator
changed some calls from get() to find() so they can handle failure because
they didn't seem to handle std::runtime_error at all
---
src/executableslist.cpp | 84 ++++++++++++++++++++++++-------------------------
1 file changed, 41 insertions(+), 43 deletions(-)
(limited to 'src/executableslist.cpp')
diff --git a/src/executableslist.cpp b/src/executableslist.cpp
index 79b17f5b..2ea9c3d9 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -33,19 +33,40 @@ along with Mod Organizer. If not, see .
using namespace MOBase;
+ExecutablesList::iterator ExecutablesList::begin()
+{
+ return m_Executables.begin();
+}
+
+ExecutablesList::const_iterator ExecutablesList::begin() const
+{
+ return m_Executables.begin();
+}
+
+ExecutablesList::iterator ExecutablesList::end()
+{
+ return m_Executables.end();
+}
+
+ExecutablesList::const_iterator ExecutablesList::end() const
+{
+ return m_Executables.end();
+}
-ExecutablesList::ExecutablesList()
+std::size_t ExecutablesList::size() const
{
+ return m_Executables.size();
}
-ExecutablesList::~ExecutablesList()
+bool ExecutablesList::empty() const
{
+ return m_Executables.empty();
}
-void ExecutablesList::init(IPluginGame const *game)
+void ExecutablesList::addFromPlugin(IPluginGame const *game)
{
Q_ASSERT(game != nullptr);
- m_Executables.clear();
+
for (const ExecutableInfo &info : game->executables()) {
if (info.isValid()) {
addExecutableInternal(info.title(),
@@ -55,6 +76,7 @@ void ExecutablesList::init(IPluginGame const *game)
info.steamAppID());
}
}
+
ExecutableInfo explorerpp = ExecutableInfo("Explore Virtual Folder", QFileInfo(QCoreApplication::applicationDirPath() + "/explorer++/Explorer++.exe" ))
.withArgument(QString("\"%1\"").arg(QDir::toNativeSeparators(game->dataDirectory().absolutePath())));
@@ -65,45 +87,25 @@ void ExecutablesList::init(IPluginGame const *game)
explorerpp.workingDirectory().absolutePath(),
explorerpp.steamAppID());
}
-
}
-void ExecutablesList::getExecutables(std::vector::iterator &begin, std::vector::iterator &end)
+const Executable &ExecutablesList::get(const QString &title) const
{
- begin = m_Executables.begin();
- end = m_Executables.end();
-}
-
-void ExecutablesList::getExecutables(std::vector::const_iterator &begin,
- std::vector::const_iterator &end) const
-{
- begin = m_Executables.begin();
- end = m_Executables.end();
-}
-
-const Executable &ExecutablesList::find(const QString &title) const
-{
- for (Executable const &exe : m_Executables) {
+ for (const auto& exe : m_Executables) {
if (exe.title() == title) {
return exe;
}
}
- throw std::runtime_error(QString("invalid executable name: %1").arg(title).toLocal8Bit().constData());
-}
+ throw std::runtime_error(QString("executable not found: %1").arg(title).toLocal8Bit().constData());
+}
-Executable &ExecutablesList::find(const QString &title)
+Executable &ExecutablesList::get(const QString &title)
{
- for (Executable &exe : m_Executables) {
- if (exe.title() == title) {
- return exe;
- }
- }
- throw std::runtime_error(QString("invalid executable name: %1").arg(title).toLocal8Bit().constData());
+ return const_cast(std::as_const(*this).get(title));
}
-
-Executable &ExecutablesList::findByBinary(const QFileInfo &info)
+Executable &ExecutablesList::getByBinary(const QFileInfo &info)
{
for (Executable &exe : m_Executables) {
if (exe.binaryInfo() == info) {
@@ -113,17 +115,15 @@ Executable &ExecutablesList::findByBinary(const QFileInfo &info)
throw std::runtime_error("invalid info");
}
-
-std::vector::iterator ExecutablesList::findExe(const QString &title)
+ExecutablesList::iterator ExecutablesList::find(const QString &title)
{
- for (std::vector::iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) {
- if (iter->title() == title) {
- return iter;
- }
- }
- return m_Executables.end();
+ return std::find_if(begin(), end(), [&](auto&& e) { return e.title() == title; });
}
+ExecutablesList::const_iterator ExecutablesList::find(const QString &title) const
+{
+ return std::find_if(begin(), end(), [&](auto&& e) { return e.title() == title; });
+}
bool ExecutablesList::titleExists(const QString &title) const
{
@@ -131,10 +131,9 @@ bool ExecutablesList::titleExists(const QString &title) const
return std::find_if(m_Executables.begin(), m_Executables.end(), test) != m_Executables.end();
}
-
void ExecutablesList::addExecutable(const Executable &executable)
{
- auto existingExe = findExe(executable.title());
+ auto existingExe = find(executable.title());
if (existingExe != m_Executables.end()) {
*existingExe = executable;
} else {
@@ -142,7 +141,6 @@ void ExecutablesList::addExecutable(const Executable &executable)
}
}
-
void ExecutablesList::updateExecutable(const QString &title,
const QString &executableName,
const QString &arguments,
@@ -153,7 +151,7 @@ void ExecutablesList::updateExecutable(const QString &title,
{
QFileInfo file(executableName);
QDir dir(workingDirectory);
- auto existingExe = findExe(title);
+ auto existingExe = find(title);
flags &= mask;
if (existingExe != m_Executables.end()) {
--
cgit v1.3.1