From b54e479a3f9e973a083c643905f21c59fadd63bb Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Sun, 12 Apr 2026 03:00:11 -0500 Subject: Remove LOOT integration entirely The sort button was already hidden on Linux (setVisible(false)) and the LOOT feedback path (LootDialog -> addLootReport) has always been Windows-only, meaning the dirty/incompatibilities/missingMasters/messages tooltip bullets and the dirty-plugin icon could never fire on Linux. MO2 shipped lootcli + libloot for a load-order sort mechanism that was unreachable from the UI. Users who want LOOT can download it from https://github.com/loot/loot and run it against their instance directly. - Drop libs/lootcli/, libloot Dockerfile build step, and lootcli staging/patchelf in build-inner.sh - Drop src/src/loot.{cpp,h}, src/src/lootdialog.{cpp,h,ui} - Extract MarkdownDocument / MarkdownPage (used by UpdateDialog for its changelog view) into src/src/markdowndocument.{h,cpp} - Strip addLootReport, makeLootTooltip, Loot::Plugin field, LOOT icon checks, and LOOT tooltip/isProblematic/hasInfo paths from pluginlist - Delete sortButton widget, updateSortButton(), onSortButtonClicked(), and all m_didUpdateMasterList wiring - Delete lootLogLevel setting, combo box, and "Integrated LOOT" group from the diagnostics settings tab --- src/src/CMakeLists.txt | 1 - src/src/loot.cpp | 1674 --------------------------------- src/src/loot.h | 149 --- src/src/lootdialog.cpp | 350 ------- src/src/lootdialog.h | 82 -- src/src/lootdialog.ui | 230 ----- src/src/mainwindow.cpp | 33 - src/src/mainwindow.h | 10 +- src/src/mainwindow.ui | 17 - src/src/markdowndocument.cpp | 33 + src/src/markdowndocument.h | 40 + src/src/pluginlist.cpp | 113 +-- src/src/pluginlist.h | 10 +- src/src/pluginlistview.cpp | 54 +- src/src/pluginlistview.h | 3 - src/src/settings.cpp | 11 - src/src/settings.h | 7 +- src/src/settingsdialog.ui | 22 - src/src/settingsdialogdiagnostics.cpp | 30 - src/src/settingsdialogdiagnostics.h | 1 - src/src/updatedialog.cpp | 1 - src/src/updatedialog.h | 2 +- 22 files changed, 89 insertions(+), 2784 deletions(-) delete mode 100644 src/src/loot.cpp delete mode 100644 src/src/loot.h delete mode 100644 src/src/lootdialog.cpp delete mode 100644 src/src/lootdialog.h delete mode 100644 src/src/lootdialog.ui create mode 100644 src/src/markdowndocument.cpp create mode 100644 src/src/markdowndocument.h (limited to 'src') diff --git a/src/src/CMakeLists.txt b/src/src/CMakeLists.txt index c22442c..b0eb235 100644 --- a/src/src/CMakeLists.txt +++ b/src/src/CMakeLists.txt @@ -104,7 +104,6 @@ target_link_libraries(organizer PRIVATE libbsarch_OOP mo2::bsatk mo2::esptk - mo2::lootcli-header # Qt6 Qt6::Widgets Qt6::Concurrent diff --git a/src/src/loot.cpp b/src/src/loot.cpp deleted file mode 100644 index 3204689..0000000 --- a/src/src/loot.cpp +++ /dev/null @@ -1,1674 +0,0 @@ -#include "loot.h" -#include "json.h" -#include "lootdialog.h" -#include "organizercore.h" -#include "spawn.h" -#include -#include - -#ifndef _WIN32 -#include "fluorinepaths.h" -#include -#include -extern char** environ; -#endif - -using namespace MOBase; -using namespace json; - -static QString LootReportPath = QDir::temp().absoluteFilePath("lootreport.json"); -#ifdef _WIN32 -static const DWORD PipeTimeout = 500; -#endif - -#ifdef _WIN32 -class AsyncPipe -{ -public: - AsyncPipe() : m_ioPending(false) - { - std::fill(std::begin(m_buffer), std::end(m_buffer), 0); - std::memset(&m_ov, 0, sizeof(m_ov)); - } - - env::HandlePtr create() - { - // creating pipe - env::HandlePtr out(createPipe()); - if (out.get() == INVALID_HANDLE_VALUE) { - return {}; - } - - HANDLE readEventHandle = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); - - if (readEventHandle == NULL) { - const auto e = GetLastError(); - log::error("CreateEvent failed for loot, {}", formatSystemMessage(e)); - return {}; - } - - m_ov.hEvent = readEventHandle; - m_readEvent.reset(readEventHandle); - - return out; - } - - std::string read() - { - if (m_ioPending) { - return checkPending(); - } else { - return tryRead(); - } - } - -private: - static const std::size_t bufferSize = 50000; - - env::HandlePtr m_stdout; - env::HandlePtr m_readEvent; - char m_buffer[bufferSize]; - OVERLAPPED m_ov; - bool m_ioPending; - - HANDLE createPipe() - { - static const wchar_t* PipeName = L"\\\\.\\pipe\\lootcli_pipe"; - - SECURITY_ATTRIBUTES sa = {}; - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.bInheritHandle = TRUE; - - env::HandlePtr pipe; - - // creating pipe - { - HANDLE pipeHandle = - ::CreateNamedPipe(PipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 50'000, - 50'000, PipeTimeout, &sa); - - if (pipeHandle == INVALID_HANDLE_VALUE) { - const auto e = GetLastError(); - log::error("CreateNamedPipe failed, {}", formatSystemMessage(e)); - return INVALID_HANDLE_VALUE; - } - - pipe.reset(pipeHandle); - } - - { - // duplicating the handle to read from it - HANDLE outputRead = INVALID_HANDLE_VALUE; - - const auto r = - DuplicateHandle(GetCurrentProcess(), pipe.get(), GetCurrentProcess(), - &outputRead, 0, TRUE, DUPLICATE_SAME_ACCESS); - - if (!r) { - const auto e = GetLastError(); - log::error("DuplicateHandle for pipe failed, {}", formatSystemMessage(e)); - return INVALID_HANDLE_VALUE; - } - - m_stdout.reset(outputRead); - } - - // creating handle to pipe which is passed to CreateProcess() - HANDLE outputWrite = ::CreateFileW(PipeName, FILE_WRITE_DATA | SYNCHRONIZE, 0, &sa, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - - if (outputWrite == INVALID_HANDLE_VALUE) { - const auto e = GetLastError(); - log::error("CreateFileW for pipe failed, {}", formatSystemMessage(e)); - return INVALID_HANDLE_VALUE; - } - - return outputWrite; - } - - std::string tryRead() - { - DWORD bytesRead = 0; - - if (!::ReadFile(m_stdout.get(), m_buffer, bufferSize, &bytesRead, &m_ov)) { - const auto e = GetLastError(); - - switch (e) { - case ERROR_IO_PENDING: { - m_ioPending = true; - break; - } - - case ERROR_BROKEN_PIPE: { - // broken pipe probably means lootcli is finished - break; - } - - default: { - log::error("{}", formatSystemMessage(e)); - break; - } - } - - return {}; - } - - return {m_buffer, m_buffer + bytesRead}; - } - - std::string checkPending() - { - DWORD bytesRead = 0; - - const auto r = WaitForSingleObject(m_readEvent.get(), PipeTimeout); - - if (r == WAIT_FAILED) { - const auto e = GetLastError(); - log::error("WaitForSingleObject in AsyncPipe failed, {}", formatSystemMessage(e)); - return {}; - } - - if (!::GetOverlappedResult(m_stdout.get(), &m_ov, &bytesRead, FALSE)) { - const auto e = GetLastError(); - - switch (e) { - case ERROR_IO_INCOMPLETE: { - break; - } - - case WAIT_TIMEOUT: { - break; - } - - case ERROR_BROKEN_PIPE: { - // broken pipe probably means lootcli is finished - break; - } - - default: { - log::error("GetOverlappedResult failed, {}", formatSystemMessage(e)); - break; - } - } - - return {}; - } - - ::ResetEvent(m_readEvent.get()); - m_ioPending = false; - - return {m_buffer, m_buffer + bytesRead}; - } -}; -#else -// Linux implementation using POSIX pipes -class AsyncPipe -{ -public: - AsyncPipe() : m_readFd(-1), m_writeFd(-1) {} - - ~AsyncPipe() - { - if (m_readFd >= 0) - ::close(m_readFd); - if (m_writeFd >= 0) - ::close(m_writeFd); - } - - env::HandlePtr create() - { - int fds[2]; - if (::pipe(fds) != 0) { - log::error("pipe() failed: {}", strerror(errno)); - return {}; - } - m_readFd = fds[0]; - m_writeFd = fds[1]; - - // set read end to non-blocking - int flags = ::fcntl(m_readFd, F_GETFL, 0); - ::fcntl(m_readFd, F_SETFL, flags | O_NONBLOCK); - - // return a non-null HandlePtr to indicate success - return env::HandlePtr(reinterpret_cast(static_cast(1))); - } - - int readFd() const { return m_readFd; } - int writeFd() const { return m_writeFd; } - - void closeWriteEnd() - { - if (m_writeFd >= 0) { - ::close(m_writeFd); - m_writeFd = -1; - } - } - - std::string read() - { - if (m_readFd < 0) - return {}; - - char buffer[50000]; - ssize_t n = ::read(m_readFd, buffer, sizeof(buffer)); - if (n > 0) { - return std::string(buffer, n); - } - return {}; - } - -private: - int m_readFd; - int m_writeFd; -}; -#endif - -log::Levels levelFromLoot(lootcli::LogLevels level) -{ - using LC = lootcli::LogLevels; - - switch (level) { - case LC::Trace: // fall-through - case LC::Debug: - return log::Debug; - - case LC::Info: - return log::Info; - - case LC::Warning: - return log::Warning; - - case LC::Error: - return log::Error; - - default: - return log::Info; - } -} - -QString Loot::Report::toMarkdown() const -{ - QString s; - - if (!okay) { - s += "## " + tr("Loot failed to run") + "\n"; - - if (errors.empty() && warnings.empty()) { - s += tr("No errors were reported. The log below might have more information.\n"); - } - } - - s += errorsMarkdown(); - - if (okay) { - s += "\n" + successMarkdown(); - } - - return s; -} - -QString Loot::Report::successMarkdown() const -{ - QString s; - - if (!messages.empty()) { - s += "### " + QObject::tr("General messages") + "\n"; - - for (auto&& m : messages) { - s += " - " + m.toMarkdown() + "\n"; - } - } - - if (!plugins.empty()) { - if (!s.isEmpty()) { - s += "\n"; - } - - s += "### " + QObject::tr("Plugins") + "\n"; - - for (auto&& p : plugins) { - const auto ps = p.toMarkdown(); - if (!ps.isEmpty()) { - s += ps + "\n"; - } - } - } - - if (s.isEmpty()) { - s += "**" + QObject::tr("No messages.") + "**\n"; - } - - s += stats.toMarkdown(); - - return s; -} - -QString Loot::Report::errorsMarkdown() const -{ - QString s; - - if (!errors.empty()) { - s += "### " + tr("Errors") + ":\n"; - - for (auto&& e : errors) { - s += " - " + e + "\n"; - } - } - - if (!warnings.empty()) { - if (!s.isEmpty()) { - s += "\n"; - } - - s += "### " + tr("Warnings") + ":\n"; - - for (auto&& w : warnings) { - s += " - " + w + "\n"; - } - } - - return s; -} - -QString Loot::Stats::toMarkdown() const -{ - return QString("`stats: %1s, lootcli %2, loot %3`") - .arg(QString::number(time / 1000.0, 'f', 2)) - .arg(lootcliVersion) - .arg(lootVersion); -} - -QString Loot::Plugin::toMarkdown() const -{ - QString s; - - if (!incompatibilities.empty()) { - s += " - **" + QObject::tr("Incompatibilities") + ": "; - - QString fs; - for (auto&& f : incompatibilities) { - if (!fs.isEmpty()) { - fs += ", "; - } - - fs += f.displayName.isEmpty() ? f.name : f.displayName; - } - - s += fs + "**\n"; - } - - if (!missingMasters.empty()) { - s += " - **" + QObject::tr("Missing masters") + ": "; - - QString ms; - for (auto&& m : missingMasters) { - if (!ms.isEmpty()) { - ms += ", "; - } - - ms += m; - } - - s += ms + "**\n"; - } - - for (auto&& m : messages) { - s += " - " + m.toMarkdown() + "\n"; - } - - for (auto&& d : dirty) { - s += " - " + d.toMarkdown(false) + "\n"; - } - - if (!s.isEmpty()) { - s = "#### " + name + "\n" + s; - } - - return s; -} - -QString Loot::Dirty::toString(bool isClean) const -{ - if (isClean) { - return QObject::tr("Verified clean by %1") - .arg(cleaningUtility.isEmpty() ? "?" : cleaningUtility); - } - - QString s = cleaningString(); - - if (!info.isEmpty()) { - s += " " + info; - } - - return s; -} - -QString Loot::Dirty::toMarkdown(bool isClean) const -{ - return toString(isClean); -} - -QString Loot::Dirty::cleaningString() const -{ - return QObject::tr("%1 found %2 ITM record(s), %3 deleted reference(s) and %4 " - "deleted navmesh(es).") - .arg(cleaningUtility.isEmpty() ? "?" : cleaningUtility) - .arg(itm) - .arg(deletedReferences) - .arg(deletedNavmesh); -} - -QString Loot::Message::toMarkdown() const -{ - QString s; - - switch (type) { - case log::Error: { - s += "**" + QObject::tr("Error") + "**: "; - break; - } - - case log::Warning: { - s += "**" + QObject::tr("Warning") + "**: "; - break; - } - - default: { - break; - } - } - - s += text; - - return s; -} - -Loot::Loot(OrganizerCore& core) - : m_core(core), m_thread(nullptr), m_cancel(false), m_result(false) -{} - -Loot::~Loot() -{ - if (m_thread) { - m_thread->wait(); - } - - deleteReportFile(); -} - -bool Loot::start(QWidget* parent, bool didUpdateMasterList) -{ - deleteReportFile(); - - log::debug("starting loot"); - - m_pipe.reset(new AsyncPipe); - - env::HandlePtr stdoutHandle = m_pipe->create(); - if (!stdoutHandle) { - return false; - } - - // vfs - m_core.prepareVFS(); - - // spawning - if (!spawnLootcli(parent, didUpdateMasterList, std::move(stdoutHandle))) { - return false; - } - - // starting thread - log::debug("starting loot thread"); - m_thread.reset(QThread::create([&] { - lootThread(); - })); - m_thread->start(); - - return true; -} - -bool Loot::spawnLootcli(QWidget* parent, bool didUpdateMasterList, - env::HandlePtr stdoutHandle) -{ -#ifdef _WIN32 - const auto logLevel = m_core.settings().diagnostics().lootLogLevel(); - - QStringList parameters; - parameters << "--game" << m_core.managedGame()->lootGameName() - - << "--gamePath" - << QString("\"%1\"").arg( - m_core.managedGame()->gameDirectory().absolutePath()) - - << "--pluginListPath" - << QString("\"%1/loadorder.txt\"").arg(m_core.profilePath()) - - << "--logLevel" - << QString::fromStdString(lootcli::logLevelToString(logLevel)) - - << "--out" << QString("\"%1\"").arg(LootReportPath) - - << "--language" << m_core.settings().interface().language(); - - if (didUpdateMasterList) { - parameters << "--skipUpdateMasterlist"; - } - - spawn::SpawnParameters sp; - sp.binary = QFileInfo(qApp->applicationDirPath() + "/loot/lootcli.exe"); - sp.arguments = parameters.join(" "); - sp.currentDirectory.setPath(qApp->applicationDirPath() + "/loot"); - sp.hooked = true; - sp.stdOut = stdoutHandle.get(); - - HANDLE lootHandle = spawn::startBinary(parent, sp); - - if (lootHandle == INVALID_HANDLE_VALUE) { - emit log(log::Levels::Error, tr("failed to start loot")); - return false; - } - - m_lootProcess.reset(lootHandle); - - return true; -#else - Q_UNUSED(parent); - Q_UNUSED(stdoutHandle); - - const auto logLevel = m_core.settings().diagnostics().lootLogLevel(); - - QStringList parameters; - parameters << "--game" << m_core.managedGame()->lootGameName() - - << "--gamePath" << m_core.managedGame()->gameDirectory().absolutePath() - - << "--pluginListPath" - << QString("%1/loadorder.txt").arg(m_core.profilePath()) - - << "--logLevel" - << QString::fromStdString(lootcli::logLevelToString(logLevel)) - - << "--out" << LootReportPath - - << "--language" << m_core.settings().interface().language(); - - if (didUpdateMasterList) { - parameters << "--skipUpdateMasterlist"; - } - - QString binary = qApp->applicationDirPath() + "/lootcli"; - - if (!QFile::exists(binary)) { - emit log(log::Levels::Error, tr("lootcli not found at %1").arg(binary)); - return false; - } - - // build argv for posix_spawn - std::string binaryStr = binary.toStdString(); - std::vector argStrs; - argStrs.push_back(binaryStr); - for (const auto& p : parameters) { - argStrs.push_back(p.toStdString()); - } - - std::vector argv; - for (auto& s : argStrs) { - argv.push_back(s.data()); - } - argv.push_back(nullptr); - - int writeFd = m_pipe->writeFd(); - int readFd = m_pipe->readFd(); - - pid_t pid = fork(); - if (pid == -1) { - emit log(log::Levels::Error, - tr("failed to start lootcli: %1").arg(strerror(errno))); - return false; - } - - if (pid == 0) { - // child process — only async-signal-safe calls allowed here - dup2(writeFd, STDOUT_FILENO); - close(writeFd); - close(readFd); - - std::string workDir = qApp->applicationDirPath().toStdString(); - chdir(workDir.c_str()); - - execv(binaryStr.c_str(), argv.data()); - _exit(127); - } - - // parent process - m_childPid = pid; - m_pipe->closeWriteEnd(); - - log::debug("lootcli spawned with pid {}", pid); - return true; -#endif -} - -void Loot::cancel() -{ - if (!m_cancel) { - log::debug("loot received cancel request"); - m_cancel = true; - } -} - -bool Loot::result() const -{ - return m_result; -} - -const QString& Loot::outPath() const -{ - return LootReportPath; -} - -const Loot::Report& Loot::report() const -{ - return m_report; -} - -const std::vector& Loot::errors() const -{ - return m_errors; -} - -const std::vector& Loot::warnings() const -{ - return m_warnings; -} - -void Loot::lootThread() -{ - try { - m_result = false; - - if (waitForCompletion()) { - m_result = true; - } - - m_report = createReport(); - } catch (...) { - log::error("unhandled exception in loot thread"); - } - - log::debug("finishing loot thread"); - emit finished(); -} - -bool Loot::waitForCompletion() -{ -#ifdef _WIN32 - bool terminating = false; - - log::debug("loot thread waiting for completion on lootcli"); - - for (;;) { - DWORD res = WaitForSingleObject(m_lootProcess.get(), 100); - - if (res == WAIT_OBJECT_0) { - log::debug("lootcli has completed"); - // done - break; - } - - if (res == WAIT_FAILED) { - const auto e = GetLastError(); - log::error("failed to wait on loot process, {}", formatSystemMessage(e)); - return false; - } - - if (m_cancel) { - log::debug("terminating lootcli process"); - ::TerminateProcess(m_lootProcess.get(), 1); - - log::debug("waiting for loocli process to terminate"); - WaitForSingleObject(m_lootProcess.get(), INFINITE); - - log::debug("lootcli terminated"); - return false; - } - - processStdout(m_pipe->read()); - } - - if (m_cancel) { - return false; - } - - processStdout(m_pipe->read()); - - // checking exit code - DWORD exitCode = 0; - - if (!::GetExitCodeProcess(m_lootProcess.get(), &exitCode)) { - const auto e = GetLastError(); - log::error("failed to get exit code for loot, {}", formatSystemMessage(e)); - return false; - } - - if (exitCode != 0UL) { - emit log(log::Levels::Error, - tr("Loot failed. Exit code was: 0x%1").arg(exitCode, 0, 16)); - return false; - } - - return true; -#else - if (m_childPid <= 0) { - return false; - } - - log::debug("loot thread waiting for completion on lootcli"); - - for (;;) { - // poll the pipe for data with 100ms timeout - struct pollfd pfd; - pfd.fd = m_pipe->readFd(); - pfd.events = POLLIN; - ::poll(&pfd, 1, 100); - - processStdout(m_pipe->read()); - - int status; - pid_t result = waitpid(m_childPid, &status, WNOHANG); - - if (result == m_childPid) { - log::debug("lootcli has completed"); - - // read any remaining output - processStdout(m_pipe->read()); - - if (WIFEXITED(status)) { - int exitCode = WEXITSTATUS(status); - if (exitCode != 0) { - emit log(log::Levels::Error, - tr("Loot failed. Exit code was: 0x%1").arg(exitCode, 0, 16)); - return false; - } - return true; - } else { - emit log(log::Levels::Error, tr("lootcli terminated abnormally")); - return false; - } - } - - if (result == -1) { - log::error("waitpid failed: {}", strerror(errno)); - return false; - } - - if (m_cancel) { - log::debug("terminating lootcli process"); - ::kill(m_childPid, SIGTERM); - - log::debug("waiting for lootcli process to terminate"); - waitpid(m_childPid, &status, 0); - - log::debug("lootcli terminated"); - return false; - } - } -#endif -} - -void Loot::processStdout(const std::string& lootOut) -{ - emit output(QString::fromStdString(lootOut)); - - m_outputBuffer += lootOut; - if (m_outputBuffer.empty()) { - return; - } - - std::size_t start = 0; - - for (;;) { - const auto newline = m_outputBuffer.find("\n", start); - if (newline == std::string::npos) { - break; - } - - const std::string_view line(m_outputBuffer.c_str() + start, newline - start); - const auto m = lootcli::parseMessage(line); - - if (m.type == lootcli::MessageType::None) { - log::error("unrecognised loot output: '{}'", line); - continue; - } - - processMessage(m); - - start = newline + 1; - } - - m_outputBuffer.erase(0, start); -} - -void Loot::processMessage(const lootcli::Message& m) -{ - switch (m.type) { - case lootcli::MessageType::Log: { - const auto level = levelFromLoot(m.logLevel); - - if (level == log::Error) { - m_errors.push_back(QString::fromStdString(m.log)); - } else if (level == log::Warning) { - m_warnings.push_back(QString::fromStdString(m.log)); - } - - emit log(level, QString::fromStdString(m.log)); - break; - } - - case lootcli::MessageType::Progress: { - emit progress(m.progress); - break; - } - } -} - -Loot::Report Loot::createReport() const -{ - Report r; - - r.okay = m_result; - r.errors = m_errors; - r.warnings = m_warnings; - - if (m_result) { - processOutputFile(r); - } - - return r; -} - -void Loot::deleteReportFile() -{ - if (QFile::exists(LootReportPath)) { - log::debug("deleting temporary loot report '{}'", LootReportPath); - const auto r = shell::Delete(QFileInfo(LootReportPath)); - - if (!r) { - log::error("failed to remove temporary loot json report '{}': {}", LootReportPath, - r.toString()); - } - } -} - -void Loot::processOutputFile(Report& r) const -{ - log::debug("parsing json output file at '{}'", LootReportPath); - - QFile outFile(LootReportPath); - if (!outFile.open(QIODevice::ReadOnly)) { - emit log(MOBase::log::Error, QString("failed to open file, %1 (error %2)") - .arg(outFile.errorString()) - .arg(outFile.error())); - - return; - } - - QJsonParseError e; - const QJsonDocument doc = QJsonDocument::fromJson(outFile.readAll(), &e); - if (doc.isNull()) { - emit log(MOBase::log::Error, - QString("invalid json, %1 (error %2)").arg(e.errorString()).arg(e.error)); - - return; - } - - requireObject(doc, "root"); - - const QJsonObject object = doc.object(); - - r.messages = reportMessages(getOpt(object, "messages")); - r.plugins = reportPlugins(getOpt(object, "plugins")); - r.stats = reportStats(getWarn(object, "stats")); -} - -std::vector Loot::reportPlugins(const QJsonArray& plugins) const -{ - std::vector v; - - for (auto pluginValue : plugins) { - const auto o = convertWarn(pluginValue, "plugin"); - if (o.isEmpty()) { - continue; - } - - auto p = reportPlugin(o); - if (!p.name.isEmpty()) { - v.emplace_back(std::move(p)); - } - } - - return v; -} - -Loot::Plugin Loot::reportPlugin(const QJsonObject& plugin) const -{ - Plugin p; - - p.name = getWarn(plugin, "name"); - if (p.name.isEmpty()) { - return {}; - } - - // ignore disabled plugins; lootcli doesn't know if a plugin is enabled or not - // and will report information on any plugin that's in the filesystem - if (!m_core.pluginList()->isEnabled(p.name)) { - return {}; - } - - if (plugin.contains("incompatibilities")) { - p.incompatibilities = reportFiles(getOpt(plugin, "incompatibilities")); - } - - if (plugin.contains("messages")) { - p.messages = reportMessages(getOpt(plugin, "messages")); - } - - if (plugin.contains("dirty")) { - p.dirty = reportDirty(getOpt(plugin, "dirty")); - } - - if (plugin.contains("clean")) { - p.clean = reportDirty(getOpt(plugin, "clean")); - } - - if (plugin.contains("missingMasters")) { - p.missingMasters = reportStringArray(getOpt(plugin, "missingMasters")); - } - - p.loadsArchive = getOpt(plugin, "loadsArchive", false); - p.isMaster = getOpt(plugin, "isMaster", false); - p.isLightMaster = getOpt(plugin, "isLightMaster", false); - - return p; -} - -Loot::Stats Loot::reportStats(const QJsonObject& stats) const -{ - Stats s; - - s.time = getWarn(stats, "time"); - s.lootcliVersion = getWarn(stats, "lootcliVersion"); - s.lootVersion = getWarn(stats, "lootVersion"); - - return s; -} - -std::vector Loot::reportMessages(const QJsonArray& array) const -{ - std::vector v; - - for (auto messageValue : array) { - const auto o = convertWarn(messageValue, "message"); - if (o.isEmpty()) { - continue; - } - - Message m; - - const auto type = getWarn(o, "type"); - - if (type == "info") { - m.type = log::Info; - } else if (type == "warn") { - m.type = log::Warning; - } else if (type == "error") { - m.type = log::Error; - } else { - log::error("unknown message type '{}'", type); - m.type = log::Info; - } - - m.text = getWarn(o, "text"); - - if (!m.text.isEmpty()) { - v.emplace_back(std::move(m)); - } - } - - return v; -} - -std::vector Loot::reportFiles(const QJsonArray& array) const -{ - std::vector v; - - for (auto&& fileValue : array) { - const auto o = convertWarn(fileValue, "file"); - if (o.isEmpty()) { - continue; - } - - File f; - - f.name = getWarn(o, "name"); - f.displayName = getOpt(o, "displayName"); - - if (!f.name.isEmpty()) { - v.emplace_back(std::move(f)); - } - } - - return v; -} - -std::vector Loot::reportDirty(const QJsonArray& array) const -{ - std::vector v; - - for (auto&& dirtyValue : array) { - const auto o = convertWarn(dirtyValue, "dirty"); - - Dirty d; - - d.crc = getWarn(o, "crc"); - d.itm = getOpt(o, "itm"); - d.deletedReferences = getOpt(o, "deletedReferences"); - d.deletedNavmesh = getOpt(o, "deletedNavmesh"); - d.cleaningUtility = getOpt(o, "cleaningUtility"); - d.info = getOpt(o, "info"); - - v.emplace_back(std::move(d)); - } - - return v; -} - -std::vector Loot::reportStringArray(const QJsonArray& array) const -{ - std::vector v; - - for (auto&& sv : array) { - auto s = convertWarn(sv, "string"); - if (s.isEmpty()) { - continue; - } - - v.emplace_back(std::move(s)); - } - - return v; -} - -#ifndef _WIN32 - -static const QString LootGitHubRepo = - "SulfurNitride/loot-linux-build-for-fluorine"; - -static QString lootAppImagePath() -{ - return fluorineDataDir() + "/bin/LOOT.AppImage"; -} - -// Fetch the download URL for the latest Linux AppImage from GitHub releases. -static QString fetchLootDownloadUrl() -{ - QNetworkAccessManager nam; - QEventLoop loop; - - QUrl apiUrl(QString("https://api.github.com/repos/%1/releases/latest") - .arg(LootGitHubRepo)); - QNetworkRequest req(apiUrl); - req.setRawHeader("Accept", "application/vnd.github.v3+json"); - req.setRawHeader("User-Agent", "Fluorine-Manager"); - req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, - QNetworkRequest::NoLessSafeRedirectPolicy); - - auto* reply = nam.get(req); - QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - loop.exec(); - - if (reply->error() != QNetworkReply::NoError) { - log::error("Failed to query GitHub releases: {} (HTTP {})", - reply->errorString(), - reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) - .toInt()); - reply->deleteLater(); - return {}; - } - - auto doc = QJsonDocument::fromJson(reply->readAll()); - reply->deleteLater(); - - auto assets = doc.object()["assets"].toArray(); - for (const auto& asset : assets) { - auto obj = asset.toObject(); - auto name = obj["name"].toString(); - if (name.contains("linux", Qt::CaseInsensitive) && - name.endsWith(".AppImage", Qt::CaseInsensitive)) { - return obj["browser_download_url"].toString(); - } - } - - // fallback: try any .AppImage - for (const auto& asset : assets) { - auto obj = asset.toObject(); - auto name = obj["name"].toString(); - if (name.endsWith(".AppImage", Qt::CaseInsensitive)) { - return obj["browser_download_url"].toString(); - } - } - - log::error("No Linux AppImage found in latest release of {}", LootGitHubRepo); - return {}; -} - -// Download the LOOT AppImage with a progress dialog. -static bool downloadLootAppImage(QWidget* parent, const QString& url, - const QString& destPath) -{ - QNetworkAccessManager nam; - QEventLoop loop; - QProgressDialog progress(QObject::tr("Downloading LOOT..."), QObject::tr("Cancel"), - 0, 100, parent); - progress.setWindowModality(Qt::WindowModal); - progress.setMinimumDuration(0); - progress.setValue(0); - - QNetworkRequest req{QUrl(url)}; - req.setRawHeader("User-Agent", "Fluorine-Manager"); - req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, - QNetworkRequest::NoLessSafeRedirectPolicy); - - auto* reply = nam.get(req); - - QObject::connect(reply, &QNetworkReply::downloadProgress, - [&](qint64 received, qint64 total) { - if (total > 0) { - progress.setMaximum(static_cast(total / 1024)); - progress.setValue(static_cast(received / 1024)); - } - }); - - QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - QObject::connect(&progress, &QProgressDialog::canceled, reply, &QNetworkReply::abort); - loop.exec(); - - if (reply->error() != QNetworkReply::NoError) { - if (reply->error() != QNetworkReply::OperationCanceledError) { - log::error("Failed to download LOOT: {}", reply->errorString()); - } - reply->deleteLater(); - return false; - } - - QDir().mkpath(QFileInfo(destPath).absolutePath()); - - QFile f(destPath); - if (!f.open(QIODevice::WriteOnly)) { - log::error("Failed to write LOOT AppImage: {}", f.errorString()); - reply->deleteLater(); - return false; - } - - f.write(reply->readAll()); - f.close(); - reply->deleteLater(); - - // Make executable - QFile::setPermissions(destPath, - QFileDevice::ReadOwner | QFileDevice::WriteOwner | - QFileDevice::ExeOwner | QFileDevice::ReadGroup | - QFileDevice::ExeGroup); - - log::info("LOOT AppImage downloaded to {}", destPath); - return true; -} - -// Ensure the LOOT AppImage is available, downloading if necessary. -static bool ensureLootAvailable(QWidget* parent) -{ - QString path = lootAppImagePath(); - if (QFile::exists(path)) { - return true; - } - - log::info("LOOT AppImage not found, downloading from GitHub..."); - - QString url = fetchLootDownloadUrl(); - if (url.isEmpty()) { - QMessageBox::critical( - parent, QObject::tr("LOOT"), - QObject::tr("Could not find a LOOT release to download.\n\n" - "Please check https://github.com/%1/releases") - .arg(LootGitHubRepo)); - return false; - } - - return downloadLootAppImage(parent, url, path); -} - -// Map MO2's lootGameName() to LOOT's internal folder name (used by --game). -// LOOT's getDefaultLootFolderName() uses full names for some games. -static QString lootFolderName(const QString& mo2GameName) -{ - static const QMap map = { - {"SkyrimSE", "Skyrim Special Edition"}, - {"SkyrimVR", "Skyrim VR"}, - {"EnderalSE", "Enderal Special Edition"}, - {"Fallout4VR", "Fallout4VR"}, - }; - return map.value(mo2GameName, mo2GameName); -} - -// Write (or update) LOOT's settings.toml so that --game / --game-path work. -// We always overwrite the game path and local_path to match the current -// Fluorine instance, since the user may switch between instances. -static void ensureLootSettings(const QString& lootDataPath, - const QString& mo2GameName, - const QString& folderName, - const QString& gamePath, - const QString& localPath) -{ - QDir().mkpath(lootDataPath); - QDir().mkpath(localPath); - - // Map MO2 game names to LOOT masterlist repository names. - static const QMap masterlistRepos = { - {"FalloutNV", "falloutnv"}, {"Fallout3", "fallout3"}, - {"Fallout4", "fallout4"}, {"Fallout4VR", "fallout4vr"}, - {"Skyrim", "skyrim"}, {"SkyrimSE", "skyrimse"}, - {"SkyrimVR", "skyrimvr"}, {"Enderal", "enderal"}, - {"EnderalSE", "enderalse"}, {"Oblivion", "oblivion"}, - {"Morrowind", "morrowind"}, {"Starfield", "starfield"}, - {"Nehrim", "oblivion"}, - }; - QString repoName = masterlistRepos.value(mo2GameName, mo2GameName.toLower()); - QString masterlistUrl = - QString("https://raw.githubusercontent.com/loot/%1/v0.26/masterlist.yaml") - .arg(repoName); - - // Always rewrite the settings file so the path matches the current - // Fluorine instance. Use the "type" key (not "gameId") because LOOT's - // type parser accepts MO2's short names like "SkyrimSE". - QString toml = QString( - "updateMasterlist = true\n" - "\n" - "[[games]]\n" - "type = \"%1\"\n" - "name = \"%2\"\n" - "folder = \"%2\"\n" - "path = \"%3\"\n" - "local_path = \"%4\"\n" - "masterlistSource = \"%5\"\n" - "\n") - .arg(mo2GameName, folderName, gamePath, localPath, masterlistUrl); - - QString settingsPath = lootDataPath + "/settings.toml"; - QFile f(settingsPath); - if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { - f.write(toml.toUtf8()); - f.close(); - log::info("Created LOOT settings at {}", settingsPath); - } -} - -// Launch the full LOOT GUI and wait for it to exit. -static bool launchLootGui(QWidget* parent, OrganizerCore& core) -{ - QString appImage = lootAppImagePath(); - if (!QFile::exists(appImage)) { - return false; - } - - QString mo2GameName = core.managedGame()->lootGameName(); - QString folderName = lootFolderName(mo2GameName); - QString gamePath = core.managedGame()->gameDirectory().absolutePath(); - QString lootDataPath = fluorineDataDir() + "/loot"; - - // Resolve the Fluorine prefix AppData/Local/ path — this is where - // LOOT auto-detects the plugins.txt / loadorder.txt from, so we must - // use it as local_path and deploy our load order files there. - QString localPath; - { - QString prefixBase = fluorineDataDir() + "/Prefix/pfx/drive_c/users/steamuser/AppData/Local"; - // Use documentsDirectory leaf name as the AppData/Local subfolder — - // this matches how Bethesda games map their local data folder. - QString dataDirName = core.managedGame()->documentsDirectory().dirName(); - if (dataDirName.isEmpty() || dataDirName == ".") { - dataDirName = core.managedGame()->gameShortName(); - } - QString candidate = prefixBase + "/" + dataDirName; - if (!dataDirName.isEmpty() && QDir(prefixBase).exists()) { - localPath = candidate; - } else { - localPath = lootDataPath + "/local/" + folderName; - } - } - - // Pre-seed LOOT settings so --game resolution works on first launch. - ensureLootSettings(lootDataPath, mo2GameName, folderName, gamePath, localPath); - - // Copy the profile's load order files to the local path so LOOT sees - // the current load order. MO2's plugins.txt omits implicitly-active - // plugins (base game ESMs) — LOOT needs every plugin listed or it warns - // about an "ambiguous load order". Merge loadorder.txt entries into - // plugins.txt so LOOT sees the complete picture. - QDir().mkpath(localPath); - QString profilePlugins = core.profilePath() + "/plugins.txt"; - QString profileLoadOrder = core.profilePath() + "/loadorder.txt"; - QString lootPlugins = localPath + "/plugins.txt"; - QString lootLoadOrder = localPath + "/loadorder.txt"; - - QFile::remove(lootPlugins); - QFile::remove(lootLoadOrder); - if (QFile::exists(profileLoadOrder)) { - QFile::copy(profileLoadOrder, lootLoadOrder); - } - if (QFile::exists(profilePlugins) && QFile::exists(profileLoadOrder)) { - // Build a set of active plugins from plugins.txt (case-insensitive). - QFile pluginsFile(profilePlugins); - QSet activePlugins; - if (pluginsFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&pluginsFile); - while (!in.atEnd()) { - QString line = in.readLine().trimmed(); - if (line.startsWith('*')) - line = line.mid(1); - if (!line.isEmpty() && !line.startsWith('#')) - activePlugins.insert(line.toLower()); - } - pluginsFile.close(); - } - - // Use loadorder.txt as the canonical order. Mark each plugin as - // active (*) or inactive based on plugins.txt. Base game ESMs that - // aren't in plugins.txt are always active. - QFile loFile(profileLoadOrder); - QFile outFile(lootPlugins); - if (loFile.open(QIODevice::ReadOnly | QIODevice::Text) && - outFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream in(&loFile); - QTextStream out(&outFile); - while (!in.atEnd()) { - QString line = in.readLine().trimmed(); - if (line.isEmpty() || line.startsWith('#')) - continue; - bool active = activePlugins.contains(line.toLower()); - // Base game ESMs (not in plugins.txt) are implicitly active. - if (!active && !activePlugins.isEmpty() && - (line.endsWith(".esm", Qt::CaseInsensitive) || - line.endsWith(".esl", Qt::CaseInsensitive))) { - // Check if it's missing from plugins.txt entirely (base game file). - if (!activePlugins.contains(line.toLower())) - active = true; - } - out << (active ? "*" : "") << line << "\n"; - } - loFile.close(); - outFile.close(); - } - } else if (QFile::exists(profilePlugins)) { - QFile::copy(profilePlugins, lootPlugins); - } - - // Mount the FUSE VFS so LOOT sees the merged mod files in the Data directory. - log::info("Mounting VFS for LOOT..."); - core.prepareVFS(); - - QStringList args; - args << "--game" << folderName - << "--game-path" << gamePath - << "--loot-data-path" << lootDataPath; - - log::info("Launching LOOT GUI: {} {}", appImage, args.join(" ")); - - QProcess lootProcess; - lootProcess.setProgram(appImage); - lootProcess.setArguments(args); - - // Restore the original environment so LOOT's AppImage doesn't inherit - // Fluorine's bundled library/plugin paths (which are incompatible with - // LOOT's own bundled Qt). - QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - QString origLdPath = env.value("FLUORINE_ORIG_LD_LIBRARY_PATH"); - if (!origLdPath.isEmpty()) { - env.insert("LD_LIBRARY_PATH", origLdPath); - } else { - env.remove("LD_LIBRARY_PATH"); - } - QString origQtPluginPath = env.value("FLUORINE_ORIG_QT_PLUGIN_PATH"); - if (!origQtPluginPath.isEmpty()) { - env.insert("QT_PLUGIN_PATH", origQtPluginPath); - } else { - env.remove("QT_PLUGIN_PATH"); - } - QString origPath = env.value("FLUORINE_ORIG_PATH"); - if (!origPath.isEmpty()) { - env.insert("PATH", origPath); - } - lootProcess.setProcessEnvironment(env); - - lootProcess.start(); - if (!lootProcess.waitForStarted(5000)) { - log::error("Failed to start LOOT: {}", lootProcess.errorString()); - QMessageBox::critical( - parent, QObject::tr("LOOT"), - QObject::tr("Failed to start LOOT:\n%1").arg(lootProcess.errorString())); - core.unmountVFS(); - return false; - } - - // Show a non-modal message while LOOT is running. - QMessageBox infoBox(QMessageBox::Information, QObject::tr("LOOT"), - QObject::tr("LOOT is running.\n\n" - "Sort your load order in LOOT, then close it " - "to apply the changes in Fluorine."), - QMessageBox::Cancel, parent); - infoBox.setWindowModality(Qt::WindowModal); - - // Poll for LOOT to exit or user to cancel. - QTimer pollTimer; - QObject::connect(&pollTimer, &QTimer::timeout, [&]() { - if (lootProcess.state() == QProcess::NotRunning) { - infoBox.accept(); - } - }); - pollTimer.start(500); - - int dialogResult = infoBox.exec(); - pollTimer.stop(); - - if (dialogResult != QMessageBox::Accepted && - lootProcess.state() == QProcess::Running) { - // User cancelled — kill LOOT - lootProcess.terminate(); - if (!lootProcess.waitForFinished(3000)) { - lootProcess.kill(); - lootProcess.waitForFinished(2000); - } - core.unmountVFS(); - return false; - } - - lootProcess.waitForFinished(-1); - - int exitCode = lootProcess.exitCode(); - log::info("LOOT exited with code {}", exitCode); - - // For FileTime-based games (FalloutNV, Fallout3, Oblivion), LOOT sets - // load order via file timestamps rather than modifying loadorder.txt. - // Read the plugin timestamps from the still-mounted VFS and write a - // sorted loadorder.txt before unmounting (timestamps are lost on unmount). - if (core.managedGame()->loadOrderMechanism() == - MOBase::IPluginGame::LoadOrderMechanism::FileTime) { - QString dataPath = core.managedGame()->dataDirectory().absolutePath(); - QDir dataDir(dataPath); - QStringList pluginFilters = {"*.esp", "*.esm", "*.esl"}; - - struct PluginMtime { - QString name; - qint64 mtime; - }; - std::vector plugins; - - for (const auto& entry : dataDir.entryInfoList(pluginFilters, QDir::Files)) { - plugins.push_back({entry.fileName(), - entry.lastModified().toSecsSinceEpoch()}); - } - - std::sort(plugins.begin(), plugins.end(), - [](const PluginMtime& a, const PluginMtime& b) { - return a.mtime < b.mtime; - }); - - if (!plugins.empty()) { - QFile lo(profileLoadOrder); - if (lo.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream out(&lo); - for (const auto& p : plugins) { - out << p.name << "\n"; - } - lo.close(); - log::info("Wrote sorted load order ({} plugins) from VFS timestamps", - plugins.size()); - } - } - } - - // Discard any COW'd files in staging (LOOT opens plugins with write access - // to set timestamps, which triggers copy-on-write — we don't want those - // copies ending up in overwrite). - core.discardVFSStagingOnUnmount(); - - // Unmount the VFS now that LOOT has finished. - log::info("Unmounting VFS after LOOT..."); - core.unmountVFS(); - - // Copy LOOT's updated load order files back to the profile. - // For FileTime games, we already wrote loadorder.txt from VFS timestamps - // above — skip the copy-back so we don't overwrite it with the old order. - bool isFileTime = core.managedGame()->loadOrderMechanism() == - MOBase::IPluginGame::LoadOrderMechanism::FileTime; - - // LOOT may write "Plugins.txt" (capital P) while we deployed "plugins.txt" - // (lowercase). On case-sensitive Linux these are two different files — the - // lowercase one is our pre-LOOT copy, the capital-P one is LOOT's output. - // Prefer the capital-P variant when it exists; otherwise fall back to the - // lowercase file (in case a future LOOT version writes lowercase). - QString lootPluginsActual; - { - QString capitalP = localPath + "/Plugins.txt"; - if (QFile::exists(capitalP)) { - lootPluginsActual = capitalP; - } else if (QFile::exists(lootPlugins)) { - lootPluginsActual = lootPlugins; - } - } - if (!lootPluginsActual.isEmpty()) { - QFile::remove(profilePlugins); - QFile::copy(lootPluginsActual, profilePlugins); - log::info("Copied LOOT {} back to profile", lootPluginsActual); - } - - bool isPluginsTxt = core.managedGame()->loadOrderMechanism() == - MOBase::IPluginGame::LoadOrderMechanism::PluginsTxt; - - if (!isFileTime && !isPluginsTxt) { - // For games that use a separate loadorder.txt (not FileTime, not - // PluginsTxt), copy LOOT's loadorder.txt back. - QString lootLoadOrderActual; - { - QString capitalL = localPath + "/Loadorder.txt"; - if (QFile::exists(capitalL)) { - lootLoadOrderActual = capitalL; - } else if (QFile::exists(lootLoadOrder)) { - lootLoadOrderActual = lootLoadOrder; - } - } - if (!lootLoadOrderActual.isEmpty()) { - QFile::remove(profileLoadOrder); - QFile::copy(lootLoadOrderActual, profileLoadOrder); - log::info("Copied LOOT {} back to profile", lootLoadOrderActual); - } - } - - if (isPluginsTxt && !lootPluginsActual.isEmpty()) { - // For PluginsTxt games (FO4, SkyrimSE, etc.), LOOT writes the sorted - // order into plugins.txt but does NOT update loadorder.txt. If we - // blindly copy the stale loadorder.txt back, readPluginLists() will - // prefer the old order from loadorder.txt over the freshly-sorted - // plugins.txt. Fix this by regenerating loadorder.txt from the - // sorted plugins.txt so both files are consistent. - QFile pluginsFile(profilePlugins); - if (pluginsFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QStringList sortedOrder; - while (!pluginsFile.atEnd()) { - QString line = QString::fromUtf8(pluginsFile.readLine()).trimmed(); - if (line.isEmpty() || line.startsWith('#')) - continue; - if (line.startsWith('*')) - line.remove(0, 1); - if (!line.isEmpty()) - sortedOrder.append(line); - } - pluginsFile.close(); - - if (!sortedOrder.isEmpty()) { - QFile lo(profileLoadOrder); - if (lo.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream out(&lo); - for (const auto& p : sortedOrder) { - out << p << "\n"; - } - lo.close(); - log::info("Regenerated loadorder.txt from LOOT-sorted plugins.txt " - "({} plugins)", sortedOrder.size()); - } - } - } - } - - return true; -} -#endif - -bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList) -{ - core.savePluginList(); - -#ifndef _WIN32 - // Linux: download and launch the full LOOT GUI - Q_UNUSED(didUpdateMasterList); - - try { - if (!ensureLootAvailable(parent)) { - return false; - } - - return launchLootGui(parent, core); - } catch (const std::exception& e) { - reportError(QObject::tr("failed to run loot: %1").arg(e.what())); - return false; - } -#else - try { - Loot loot(core); - LootDialog dialog(parent, core, loot); - - if (!loot.start(parent, didUpdateMasterList)) { - return false; - } - - dialog.exec(); - - return dialog.result(); - } catch (const UsvfsConnectorException& e) { - log::debug("{}", e.what()); - return false; - } catch (const std::exception& e) { - reportError(QObject::tr("failed to run loot: %1").arg(e.what())); - return false; - } -#endif -} diff --git a/src/src/loot.h b/src/src/loot.h deleted file mode 100644 index 387ba76..0000000 --- a/src/src/loot.h +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef MODORGANIZER_LOOT_H -#define MODORGANIZER_LOOT_H - -#include "envmodule.h" -#include -#include -#include -#ifdef _WIN32 -#include -#else -#include -#endif - -Q_DECLARE_METATYPE(lootcli::Progress); -Q_DECLARE_METATYPE(MOBase::log::Levels); - -class OrganizerCore; -class AsyncPipe; - -class Loot : public QObject -{ - Q_OBJECT; - -public: - struct Message - { - MOBase::log::Levels type; - QString text; - - QString toMarkdown() const; - }; - - struct File - { - QString name; - QString displayName; - }; - - struct Dirty - { - qint64 crc = 0; - qint64 itm = 0; - qint64 deletedReferences = 0; - qint64 deletedNavmesh = 0; - QString cleaningUtility; - QString info; - - QString toString(bool isClean) const; - QString toMarkdown(bool isClean) const; - QString cleaningString() const; - }; - - struct Plugin - { - QString name; - std::vector incompatibilities; - std::vector messages; - std::vector dirty, clean; - std::vector missingMasters; - bool loadsArchive = false; - bool isMaster = false; - bool isLightMaster = false; - - QString toMarkdown() const; - }; - - struct Stats - { - qint64 time = 0; - QString lootcliVersion; - QString lootVersion; - - QString toMarkdown() const; - }; - - struct Report - { - bool okay = false; - std::vector errors, warnings; - std::vector messages; - std::vector plugins; - Stats stats; - - QString toMarkdown() const; - - private: - QString successMarkdown() const; - QString errorsMarkdown() const; - }; - - Loot(OrganizerCore& core); - ~Loot(); - - bool start(QWidget* parent, bool didUpdateMasterList); - void cancel(); - bool result() const; - - const QString& outPath() const; - const Report& report() const; - const std::vector& errors() const; - const std::vector& warnings() const; - -signals: - void output(const QString& s); - void progress(const lootcli::Progress p); - void log(MOBase::log::Levels level, const QString& s) const; - void finished(); - -private: - OrganizerCore& m_core; - std::unique_ptr m_thread; - std::atomic m_cancel; - std::atomic m_result; - env::HandlePtr m_lootProcess; -#ifndef _WIN32 - pid_t m_childPid = -1; -#endif - std::unique_ptr m_pipe; - std::string m_outputBuffer; - std::vector m_errors, m_warnings; - Report m_report; - - bool spawnLootcli(QWidget* parent, bool didUpdateMasterList, - env::HandlePtr stdoutHandle); - - void lootThread(); - bool waitForCompletion(); - - void processStdout(const std::string& lootOut); - void processMessage(const lootcli::Message& m); - - Report createReport() const; - void processOutputFile(Report& r) const; - void deleteReportFile(); - - Message reportMessage(const QJsonObject& message) const; - std::vector reportPlugins(const QJsonArray& plugins) const; - Loot::Plugin reportPlugin(const QJsonObject& plugin) const; - Loot::Stats reportStats(const QJsonObject& stats) const; - - std::vector reportMessages(const QJsonArray& array) const; - std::vector reportFiles(const QJsonArray& array) const; - std::vector reportDirty(const QJsonArray& array) const; - std::vector reportStringArray(const QJsonArray& array) const; -}; - -bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList); - -#endif // MODORGANIZER_LOOT_H diff --git a/src/src/lootdialog.cpp b/src/src/lootdialog.cpp deleted file mode 100644 index 9b36f2d..0000000 --- a/src/src/lootdialog.cpp +++ /dev/null @@ -1,350 +0,0 @@ -#include "lootdialog.h" -#include "loot.h" -#include "organizercore.h" -#include "ui_lootdialog.h" -#ifdef MO2_WEBENGINE -#include -#endif -#include - -using namespace MOBase; - -QString progressToString(lootcli::Progress p) -{ - using P = lootcli::Progress; - - static const std::map map = { - {P::CheckingMasterlistExistence, QObject::tr("Checking masterlist existence")}, - {P::UpdatingMasterlist, QObject::tr("Updating masterlist")}, - {P::LoadingLists, QObject::tr("Loading lists")}, - {P::ReadingPlugins, QObject::tr("Reading plugins")}, - {P::SortingPlugins, QObject::tr("Sorting plugins")}, - {P::WritingLoadorder, QObject::tr("Writing loadorder.txt")}, - {P::ParsingLootMessages, QObject::tr("Parsing loot messages")}, - {P::Done, QObject::tr("Done")}}; - - auto itor = map.find(p); - if (itor == map.end()) { - return QString("unknown progress %1").arg(static_cast(p)); - } else { - return itor->second; - } -} - -MarkdownDocument::MarkdownDocument(QObject* parent) : QObject(parent) {} - -void MarkdownDocument::setText(const QString& text) -{ - if (m_text == text) - return; - - m_text = text; - emit textChanged(m_text); -} - -#ifdef MO2_WEBENGINE -MarkdownPage::MarkdownPage(QObject* parent) : QWebEnginePage(parent) {} - -bool MarkdownPage::acceptNavigationRequest(const QUrl& url, NavigationType, bool) -{ - static const QStringList allowed = {"qrc", "data"}; - - if (!allowed.contains(url.scheme())) { - shell::Open(url); - return false; - } - - return true; -} -#endif - -// Convert simple markdown to HTML for QTextBrowser -static QString markdownToHtml(const QString& md) -{ - QString html = ""; - - const auto lines = md.split('\n'); - bool inList = false; - - for (const auto& line : lines) { - QString trimmed = line.trimmed(); - - if (trimmed.isEmpty()) { - if (inList) { - html += ""; - inList = false; - } - html += "
"; - continue; - } - - // headers - if (trimmed.startsWith("#### ")) { - if (inList) { html += ""; inList = false; } - html += "

" + trimmed.mid(5).toHtmlEscaped() + "

"; - } else if (trimmed.startsWith("### ")) { - if (inList) { html += ""; inList = false; } - html += "

" + trimmed.mid(4).toHtmlEscaped() + "

"; - } else if (trimmed.startsWith("## ")) { - if (inList) { html += ""; inList = false; } - html += "

" + trimmed.mid(3).toHtmlEscaped() + "

"; - } else if (trimmed.startsWith(" - ") || trimmed.startsWith("- ")) { - if (!inList) { html += "
    "; inList = true; } - QString item = trimmed.startsWith(" - ") ? trimmed.mid(3) : trimmed.mid(2); - // bold - item.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "\\1"); - html += "
  • " + item + "
  • "; - } else { - if (inList) { html += "
"; inList = false; } - // bold - trimmed.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "\\1"); - // code - trimmed.replace(QRegularExpression("`(.+?)`"), "\\1"); - html += "

" + trimmed + "

"; - } - } - - if (inList) html += ""; - html += ""; - return html; -} - -LootDialog::LootDialog(QWidget* parent, OrganizerCore& core, Loot& loot) - : QDialog(parent, Qt::WindowMaximizeButtonHint), ui(new Ui::LootDialog), - m_core(core), m_loot(loot), m_finished(false), m_cancelling(false) -{ - createUI(); - - QObject::connect( - &m_loot, &Loot::output, this, - [&](auto&& s) { - addOutput(s); - }, - Qt::QueuedConnection); - - QObject::connect( - &m_loot, &Loot::progress, this, - [&](auto&& p) { - setProgress(p); - }, - Qt::QueuedConnection); - - QObject::connect( - &m_loot, &Loot::log, this, - [&](auto&& lv, auto&& s) { - log(lv, s); - }, - Qt::QueuedConnection); - - QObject::connect( - &m_loot, &Loot::finished, this, - [&] { - onFinished(); - }, - Qt::QueuedConnection); -} - -LootDialog::~LootDialog() = default; - -void LootDialog::setText(const QString& s) -{ - ui->progressText->setText(s); -} - -void LootDialog::setProgress(lootcli::Progress p) -{ - // don't overwrite the "stopping loot" message even if lootcli generates a new - // progress message - if (!m_cancelling) { - setText(progressToString(p)); - } - - if (p == lootcli::Progress::Done) { - ui->progressBar->setRange(0, 1); - ui->progressBar->setValue(1); - } -} - -void LootDialog::addOutput(const QString& s) -{ - if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) { - return; - } - - const auto lines = s.split(QRegularExpression("[\\r\\n]"), Qt::SkipEmptyParts); - - for (auto&& line : lines) { - if (line.isEmpty()) { - continue; - } - - addLineOutput(line); - } -} - -bool LootDialog::result() const -{ - return m_loot.result(); -} - -void LootDialog::cancel() -{ - if (!m_finished && !m_cancelling) { - log::debug("loot dialog: cancelling"); - m_loot.cancel(); - - setText(tr("Stopping LOOT...")); - addLineOutput("stopping loot"); - - ui->buttons->setEnabled(false); - m_cancelling = true; - } -} - -void LootDialog::openReport() -{ - const auto path = m_loot.outPath(); - shell::Open(path); -} - -int LootDialog::exec() -{ - auto& s = m_core.settings(); - - GeometrySaver gs(s, this); - s.geometry().restoreState(&m_expander); - - const auto r = QDialog::exec(); - - s.geometry().saveState(&m_expander); - - return r; -} - -void LootDialog::accept() -{ - // no-op -} - -void LootDialog::reject() -{ - if (m_finished) { - log::debug("loot dialog reject: loot finished, closing"); - QDialog::reject(); - } else { - log::debug("loot dialog reject: not finished, cancelling"); - cancel(); - } -} - -void LootDialog::createUI() -{ - ui->setupUi(this); - ui->progressBar->setMaximum(0); - -#ifdef MO2_WEBENGINE - auto* page = new MarkdownPage(this); - ui->report->setPage(page); - - auto* channel = new QWebChannel(this); - channel->registerObject("content", &m_report); - page->setWebChannel(channel); - - const QString path = QApplication::applicationDirPath() + "/resources/markdown.html"; - QFile f(path); - - if (f.open(QFile::ReadOnly)) { - const QString html = f.readAll(); - if (!html.isEmpty()) { - ui->report->setHtml(html); - } else { - log::error("failed to read '{}', {}", path, f.errorString()); - } - } else { - log::error("can't open '{}', {}", path, f.errorString()); - } -#else - ui->report->setHtml(markdownToHtml(tr("Running LOOT..."))); - connect(&m_report, &MarkdownDocument::textChanged, this, [this](const QString& md) { - ui->report->setHtml(markdownToHtml(md)); - }); -#endif - - m_expander.set(ui->details, ui->detailsPanel); - ui->openJsonReport->setEnabled(false); - connect(ui->openJsonReport, &QPushButton::clicked, [&] { - openReport(); - }); - - ui->buttons->setStandardButtons(QDialogButtonBox::Cancel); - - m_report.setText(tr("Running LOOT...")); - - resize(650, 450); - setSizeGripEnabled(true); -} - -void LootDialog::closeEvent(QCloseEvent* e) -{ - if (m_finished) { - log::debug("loot dialog close event: finished, closing"); - QDialog::closeEvent(e); - } else { - log::debug("loot dialog close event: not finished, cancelling"); - cancel(); - e->ignore(); - } -} - -void LootDialog::addLineOutput(const QString& line) -{ - ui->output->appendPlainText(line); -} - -void LootDialog::onFinished() -{ - log::debug("loot dialog: loot is finished"); - - m_finished = true; - - if (m_cancelling) { - log::debug("loot dialog: was cancelling, closing"); - close(); - } else { - log::debug("loot dialog: showing report"); - - showReport(); - - ui->openJsonReport->setEnabled(true); - ui->buttons->setStandardButtons(QDialogButtonBox::Close); - - // if loot failed, the Done progress won't be received; this makes sure - // the progress bar is stopped - setProgress(lootcli::Progress::Done); - } -} - -void LootDialog::log(log::Levels lv, const QString& s) -{ - if (lv >= log::Levels::Warning) { - log::log(lv, "{}", s); - } - - if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) { - addLineOutput(QString("[%1] %2").arg(log::levelToString(lv)).arg(s)); - } -} - -void LootDialog::showReport() -{ - const auto& lootReport = m_loot.report(); - - if (m_loot.result()) { - m_core.pluginList()->clearAdditionalInformation(); - for (auto&& p : lootReport.plugins) { - m_core.pluginList()->addLootReport(p.name, p); - } - } - - m_report.setText(lootReport.toMarkdown()); -} diff --git a/src/src/lootdialog.h b/src/src/lootdialog.h deleted file mode 100644 index 51e0aeb..0000000 --- a/src/src/lootdialog.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef MODORGANIZER_LOOTDIALOG_H -#define MODORGANIZER_LOOTDIALOG_H - -#include -#include -#include - -namespace Ui -{ -class LootDialog; -} - -class OrganizerCore; -class Loot; - -class MarkdownDocument : public QObject -{ - Q_OBJECT; - Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged FINAL); - -public: - explicit MarkdownDocument(QObject* parent = nullptr); - void setText(const QString& text); - -signals: - void textChanged(const QString& text); - -private: - QString m_text; -}; - -#ifdef MO2_WEBENGINE -class MarkdownPage : public QWebEnginePage -{ - Q_OBJECT; - -public: - explicit MarkdownPage(QObject* parent = nullptr); - -protected: - bool acceptNavigationRequest(const QUrl& url, NavigationType, bool) override; -}; -#endif - -class LootDialog : public QDialog -{ - Q_OBJECT; - -public: - LootDialog(QWidget* parent, OrganizerCore& core, Loot& loot); - ~LootDialog(); - - void setText(const QString& s); - void setProgress(lootcli::Progress p); - - void addOutput(const QString& s); - bool result() const; - void cancel(); - void openReport(); - - int exec() override; - void accept() override; - void reject() override; - -private: - std::unique_ptr ui; - MOBase::ExpanderWidget m_expander; - OrganizerCore& m_core; - Loot& m_loot; - bool m_finished; - bool m_cancelling; - MarkdownDocument m_report; - - void createUI(); - void closeEvent(QCloseEvent* e) override; - void addLineOutput(const QString& line); - void onFinished(); - void log(MOBase::log::Levels lv, const QString& s); - void showReport(); -}; - -#endif // MODORGANIZER_LOOTDIALOG_H diff --git a/src/src/lootdialog.ui b/src/src/lootdialog.ui deleted file mode 100644 index b9e62f1..0000000 --- a/src/src/lootdialog.ui +++ /dev/null @@ -1,230 +0,0 @@ - - - LootDialog - - - - 0 - 0 - 457 - 600 - - - - LOOT - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Progress - - - - - - - 24 - - - false - - - - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Details - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Open JSON report - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - - - - buttons - accepted() - LootDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttons - rejected() - LootDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/src/mainwindow.cpp b/src/src/mainwindow.cpp index d61273c..e148c24 100644 --- a/src/src/mainwindow.cpp +++ b/src/src/mainwindow.cpp @@ -204,8 +204,6 @@ QString UnmanagedModName() return QObject::tr(""); } -bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList); - void setFilterShortcuts(QWidget* widget, QLineEdit* edit) { auto activate = [=] { @@ -394,8 +392,6 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore, ui->groupCombo->installEventFilter(noWheel); ui->profileBox->installEventFilter(noWheel); - updateSortButton(); - connect(&m_PluginContainer, SIGNAL(diagnosisUpdate()), this, SLOT(scheduleCheckForProblems())); @@ -417,10 +413,6 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore, SLOT(updateAvailable())); connect(m_OrganizerCore.updater(), SIGNAL(motdAvailable(QString)), this, SLOT(motdReceived(QString))); - connect(&m_OrganizerCore, &OrganizerCore::refreshTriggered, this, [this]() { - updateSortButton(); - }); - connect(&NexusInterface::instance(), SIGNAL(requestNXMDownload(QString)), &m_OrganizerCore, SLOT(downloadRequestedNXM(QString))); connect(&NexusInterface::instance(), @@ -656,11 +648,6 @@ void MainWindow::resetButtonIcons() QIcon::fromTheme("edit-undo", QIcon(":/MO/gui/restore"))); ui->saveModsButton->setIcon( QIcon::fromTheme("document-save", QIcon(":/MO/gui/backup"))); -#ifdef _WIN32 - ui->sortButton->setIcon(QIcon::fromTheme("view-sort-ascending", QIcon(":/MO/gui/sort"))); -#else - ui->sortButton->setVisible(false); -#endif ui->restoreButton->setIcon( QIcon::fromTheme("edit-undo", QIcon(":/MO/gui/restore"))); ui->saveButton->setIcon(QIcon::fromTheme("document-save", QIcon(":/MO/gui/backup"))); @@ -669,9 +656,6 @@ void MainWindow::resetButtonIcons() ui->openFolderMenu->setIconSize(QSize(16, 16)); ui->restoreModsButton->setIconSize(QSize(16, 16)); ui->saveModsButton->setIconSize(QSize(16, 16)); -#ifdef _WIN32 - ui->sortButton->setIconSize(QSize(16, 16)); -#endif ui->restoreButton->setIconSize(QSize(16, 16)); ui->saveButton->setIconSize(QSize(16, 16)); } @@ -2967,8 +2951,6 @@ void MainWindow::on_actionSettings_triggered() m_OrganizerCore.refreshLists(); - updateSortButton(); - if (settings.paths().profiles() != oldProfilesDirectory) { refreshProfiles(); } @@ -3249,21 +3231,6 @@ void MainWindow::toggleUpdateAction() ui->actionUpdate->setVisible(s.checkForUpdates()); } -void MainWindow::updateSortButton() -{ -#ifdef _WIN32 - if (m_OrganizerCore.managedGame()->sortMechanism() != - IPluginGame::SortMechanism::NONE) { - ui->sortButton->setEnabled(true); - ui->sortButton->setToolTip(tr("Sort the plugins using LOOT.")); - } else { - ui->sortButton->setDisabled(true); - ui->sortButton->setToolTip(tr("There is no supported sort mechanism for this game. " - "You will probably have to use a third-party tool.")); - } -#endif -} - void MainWindow::nxmEndorsementsAvailable(QVariant userData, QVariant resultData, int) { QVariantList data = resultData.toList(); diff --git a/src/src/mainwindow.h b/src/src/mainwindow.h index 3e22fd1..b6c515a 100644 --- a/src/src/mainwindow.h +++ b/src/src/mainwindow.h @@ -249,8 +249,6 @@ private: void toggleMO2EndorseState(); void toggleUpdateAction(); - void updateSortButton(); - // update info struct NxmUpdateInfoData { @@ -440,10 +438,10 @@ private slots: void toolBar_customContextMenuRequested(const QPoint& point); void removeFromToolbar(QAction* action); - void about(); - - void resetActionIcons(); - void resetButtonIcons(); + void about(); + + void resetActionIcons(); + void resetButtonIcons(); private slots: // ui slots // actions diff --git a/src/src/mainwindow.ui b/src/src/mainwindow.ui index caeda51..317057b 100644 --- a/src/src/mainwindow.ui +++ b/src/src/mainwindow.ui @@ -806,23 +806,6 @@ - - - - Sort the plugins using LOOT. - - - Sort the plugins using LOOT. - - - Sort - - - - :/MO/gui/sort:/MO/gui/sort - - - diff --git a/src/src/markdowndocument.cpp b/src/src/markdowndocument.cpp new file mode 100644 index 0000000..ec2593a --- /dev/null +++ b/src/src/markdowndocument.cpp @@ -0,0 +1,33 @@ +#include "markdowndocument.h" + +#ifdef MO2_WEBENGINE +#include +#include +#endif + +MarkdownDocument::MarkdownDocument(QObject* parent) : QObject(parent) {} + +void MarkdownDocument::setText(const QString& text) +{ + if (m_text == text) + return; + + m_text = text; + emit textChanged(m_text); +} + +#ifdef MO2_WEBENGINE +MarkdownPage::MarkdownPage(QObject* parent) : QWebEnginePage(parent) {} + +bool MarkdownPage::acceptNavigationRequest(const QUrl& url, NavigationType, bool) +{ + static const QStringList allowed = {"qrc", "data"}; + + if (!allowed.contains(url.scheme())) { + MOBase::shell::Open(url); + return false; + } + + return true; +} +#endif diff --git a/src/src/markdowndocument.h b/src/src/markdowndocument.h new file mode 100644 index 0000000..18e33d9 --- /dev/null +++ b/src/src/markdowndocument.h @@ -0,0 +1,40 @@ +#ifndef MODORGANIZER_MARKDOWNDOCUMENT_H +#define MODORGANIZER_MARKDOWNDOCUMENT_H + +#include +#include + +#ifdef MO2_WEBENGINE +#include +#endif + +class MarkdownDocument : public QObject +{ + Q_OBJECT; + Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged FINAL); + +public: + explicit MarkdownDocument(QObject* parent = nullptr); + void setText(const QString& text); + +signals: + void textChanged(const QString& text); + +private: + QString m_text; +}; + +#ifdef MO2_WEBENGINE +class MarkdownPage : public QWebEnginePage +{ + Q_OBJECT; + +public: + explicit MarkdownPage(QObject* parent = nullptr); + +protected: + bool acceptNavigationRequest(const QUrl& url, NavigationType, bool) override; +}; +#endif + +#endif // MODORGANIZER_MARKDOWNDOCUMENT_H diff --git a/src/src/pluginlist.cpp b/src/src/pluginlist.cpp index 8fac338..3961dff 100644 --- a/src/src/pluginlist.cpp +++ b/src/src/pluginlist.cpp @@ -636,17 +636,6 @@ void PluginList::addInformation(const QString& name, const QString& message) } } -void PluginList::addLootReport(const QString& name, Loot::Plugin plugin) -{ - auto iter = m_ESPsByName.find(name); - - if (iter != m_ESPsByName.end()) { - m_AdditionalInfo[name].loot = std::move(plugin); - } else { - log::warn("failed to associate loot report for \"{}\"", name); - } -} - bool PluginList::isEnabled(int index) { return m_ESPs.at(index).enabled; @@ -662,10 +651,10 @@ void PluginList::readLockedOrderFrom(const QString& fileName) return; } - if (!file.open(QIODevice::ReadOnly)) { - log::error("failed to open locked order file '{}': {}", fileName, file.errorString()); - return; - } + if (!file.open(QIODevice::ReadOnly)) { + log::error("failed to open locked order file '{}': {}", fileName, file.errorString()); + return; + } int lineNumber = 0; while (!file.atEnd()) { QByteArray line = file.readLine(); @@ -1595,69 +1584,11 @@ QVariant PluginList::tooltipData(const QModelIndex& modelIndex) const toolTip += ""; } - - // loot - toolTip += makeLootTooltip(itor->second.loot); } return toolTip; } -QString PluginList::makeLootTooltip(const Loot::Plugin& loot) const -{ - QString s; - - for (auto&& f : loot.incompatibilities) { - s += "
  • " + - tr("Incompatible with %1") - .arg(f.displayName.isEmpty() ? f.name : f.displayName) + - "
  • "; - } - - for (auto&& m : loot.missingMasters) { - s += "
  • " + tr("Depends on missing %1").arg(m) + "
  • "; - } - - for (auto&& m : loot.messages) { - s += "
  • "; - - switch (m.type) { - case log::Warning: - s += tr("Warning") + ": "; - break; - - case log::Error: - s += tr("Error") + ": "; - break; - - case log::Info: // fall-through - case log::Debug: - default: - // nothing - break; - } - - s += m.text + "
  • "; - } - - for (auto&& d : loot.dirty) { - s += "
  • " + d.toString(false) + "
  • "; - } - - for (auto&& c : loot.clean) { - s += "
  • " + c.toString(true) + "
  • "; - } - - if (!s.isEmpty()) { - s = "
    " - "
      " + - s + "
    "; - } - - return s; -} - QVariant PluginList::iconData(const QModelIndex& modelIndex) const { int index = modelIndex.row(); @@ -1712,45 +1643,17 @@ QVariant PluginList::iconData(const QModelIndex& modelIndex) const result.append(":/MO/gui/unchecked-checkbox"); } - if (info && !info->loot.dirty.empty()) { - result.append(":/MO/gui/edit_clear"); - } - return result; } -bool PluginList::isProblematic(const ESPInfo& esp, const AdditionalInfo* info) const +bool PluginList::isProblematic(const ESPInfo& esp, const AdditionalInfo*) const { - if (esp.masterUnset.size() > 0) { - return true; - } - - if (info) { - if (!info->loot.incompatibilities.empty()) { - return true; - } - - if (!info->loot.missingMasters.empty()) { - return true; - } - } - - return false; + return esp.masterUnset.size() > 0; } -bool PluginList::hasInfo(const ESPInfo& esp, const AdditionalInfo* info) const +bool PluginList::hasInfo(const ESPInfo&, const AdditionalInfo* info) const { - if (info) { - if (!info->messages.empty()) { - return true; - } - - if (!info->loot.messages.empty()) { - return true; - } - } - - return false; + return info && !info->messages.empty(); } bool PluginList::setData(const QModelIndex& modIndex, const QVariant& value, int role) diff --git a/src/src/pluginlist.h b/src/src/pluginlist.h index 2cdf49a..56745ff 100644 --- a/src/src/pluginlist.h +++ b/src/src/pluginlist.h @@ -20,7 +20,6 @@ along with Mod Organizer. If not, see . #ifndef PLUGINLIST_H #define PLUGINLIST_H -#include "loot.h" #include "profile.h" #include #include @@ -161,17 +160,12 @@ public: void clearInformation(const QString& name); /** - * @brief add additional information on a mod (i.e. from loot) + * @brief add additional information on a mod * @param name name of the plugin to add information about * @param message the message to add to the plugin */ void addInformation(const QString& name, const QString& message); - /** - * adds information from a loot report - */ - void addLootReport(const QString& name, Loot::Plugin plugin); - /** * @brief test if a plugin is enabled * @@ -368,7 +362,6 @@ private: struct AdditionalInfo { QStringList messages; - Loot::Plugin loot; }; private: @@ -435,7 +428,6 @@ private: QVariant tooltipData(const QModelIndex& modelIndex) const; QVariant iconData(const QModelIndex& modelIndex) const; - QString makeLootTooltip(const Loot::Plugin& loot) const; bool isProblematic(const ESPInfo& esp, const AdditionalInfo* info) const; bool hasInfo(const ESPInfo& esp, const AdditionalInfo* info) const; }; diff --git a/src/src/pluginlistview.cpp b/src/src/pluginlistview.cpp index ffdae3d..7fc4c93 100644 --- a/src/src/pluginlistview.cpp +++ b/src/src/pluginlistview.cpp @@ -25,8 +25,7 @@ using namespace MOBase; PluginListView::PluginListView(QWidget* parent) : QTreeView(parent), m_sortProxy(nullptr), - m_Scrollbar(new ViewMarkingScrollBar(this, Qt::BackgroundRole)), - m_didUpdateMasterList(false) + m_Scrollbar(new ViewMarkingScrollBar(this, Qt::BackgroundRole)) { setVerticalScrollBar(m_Scrollbar); MOBase::setCustomizableColumns(this); @@ -177,50 +176,6 @@ void PluginListView::onFilterChanged(const QString& filter) updatePluginCount(); } -void PluginListView::onSortButtonClicked() -{ - const bool offline = m_core->settings().network().offlineMode(); - - auto r = QMessageBox::No; - - if (offline) { - r = QMessageBox::question(topLevelWidget(), tr("Sorting plugins"), - tr("Are you sure you want to sort your plugins list?") + - "\r\n\r\n" + - tr("Note: You are currently in offline mode and LOOT " - "will not update the master list."), - QMessageBox::Yes | QMessageBox::No); - } else { - r = QMessageBox::question(topLevelWidget(), tr("Sorting plugins"), - tr("Are you sure you want to sort your plugins list?"), - QMessageBox::Yes | QMessageBox::No); - } - - if (r != QMessageBox::Yes) { - return; - } - - m_core->savePluginList(); - - topLevelWidget()->setEnabled(false); - Guard g([=, this]() { - topLevelWidget()->setEnabled(true); - }); - - // don't try to update the master list in offline mode - const bool didUpdateMasterList = offline ? true : m_didUpdateMasterList; - - if (runLoot(topLevelWidget(), *m_core, didUpdateMasterList)) { - // don't assume the master list was updated in offline mode - if (!offline) { - m_didUpdateMasterList = true; - } - - m_core->refreshESPList(false); - m_core->savePluginList(); - } -} - std::pair PluginListView::selected() const { return {indexViewToModel(currentIndex()), @@ -258,13 +213,6 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* updatePluginCount(); }); -#ifdef _WIN32 - // sort - connect(mwui->sortButton, &QPushButton::clicked, [=, this] { - onSortButtonClicked(); - }); -#endif - // filter connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, &PluginListSortProxy::updateFilter); diff --git a/src/src/pluginlistview.h b/src/src/pluginlistview.h index e27f290..3b47471 100644 --- a/src/src/pluginlistview.h +++ b/src/src/pluginlistview.h @@ -38,7 +38,6 @@ protected slots: void onDoubleClicked(const QModelIndex& index); void onFilterChanged(const QString& filter); - void onSortButtonClicked(); protected: friend class PluginListContextMenu; @@ -79,8 +78,6 @@ private: PluginListSortProxy* m_sortProxy; ModListViewActions* m_modActions; ViewMarkingScrollBar* m_Scrollbar; - - bool m_didUpdateMasterList; }; #endif // PLUGINLISTVIEW_H diff --git a/src/src/settings.cpp b/src/src/settings.cpp index fc6316e..74204c7 100644 --- a/src/src/settings.cpp +++ b/src/src/settings.cpp @@ -2429,17 +2429,6 @@ void DiagnosticsSettings::setLogLevel(log::Levels level) set(m_Settings, "Settings", "log_level", level); } -lootcli::LogLevels DiagnosticsSettings::lootLogLevel() const -{ - return get(m_Settings, "Settings", "loot_log_level", - lootcli::LogLevels::Info); -} - -void DiagnosticsSettings::setLootLogLevel(lootcli::LogLevels level) -{ - set(m_Settings, "Settings", "loot_log_level", level); -} - env::CoreDumpTypes DiagnosticsSettings::coreDumpType() const { return get(m_Settings, "Settings", "crash_dumps_type", diff --git a/src/src/settings.h b/src/src/settings.h index a4a9e89..8abb650 100644 --- a/src/src/settings.h +++ b/src/src/settings.h @@ -21,7 +21,6 @@ along with Mod Organizer. If not, see . #define SETTINGS_H #include "envdump.h" -#include #include #include #include @@ -703,15 +702,11 @@ class DiagnosticsSettings public: DiagnosticsSettings(QSettings& settings); - // log level for both MO and usvfs + // log level for MO // MOBase::log::Levels logLevel() const; void setLogLevel(MOBase::log::Levels level); - // log level for loot - lootcli::LogLevels lootLogLevel() const; - void setLootLogLevel(lootcli::LogLevels level); - // crash dump type for both MO and usvfs // env::CoreDumpTypes coreDumpType() const; diff --git a/src/src/settingsdialog.ui b/src/src/settingsdialog.ui index 3e1c54a..6b4ebc6 100644 --- a/src/src/settingsdialog.ui +++ b/src/src/settingsdialog.ui @@ -2440,28 +2440,6 @@ programs you are intentionally running.
    - - - - Integrated LOOT - - - - QFormLayout::FieldsStayAtSizeHint - - - - - LOOT Log Level - - - - - - - - - diff --git a/src/src/settingsdialogdiagnostics.cpp b/src/src/settingsdialogdiagnostics.cpp index ab3c922..267599d 100644 --- a/src/src/settingsdialogdiagnostics.cpp +++ b/src/src/settingsdialogdiagnostics.cpp @@ -10,7 +10,6 @@ DiagnosticsSettingsTab::DiagnosticsSettingsTab(Settings& s, SettingsDialog& d) : SettingsTab(s, d) { setLogLevel(); - setLootLogLevel(); setCrashDumpTypesBox(); ui->dumpsMaxEdit->setValue(settings().diagnostics().maxCoreDumps()); @@ -49,32 +48,6 @@ void DiagnosticsSettingsTab::setLogLevel() } } -void DiagnosticsSettingsTab::setLootLogLevel() -{ - using L = lootcli::LogLevels; - - auto v = [](L level) { - return QVariant(static_cast(level)); - }; - - ui->lootLogLevel->clear(); - - ui->lootLogLevel->addItem(QObject::tr("Trace"), v(L::Trace)); - ui->lootLogLevel->addItem(QObject::tr("Debug"), v(L::Debug)); - ui->lootLogLevel->addItem(QObject::tr("Info (recommended)"), v(L::Info)); - ui->lootLogLevel->addItem(QObject::tr("Warning"), v(L::Warning)); - ui->lootLogLevel->addItem(QObject::tr("Error"), v(L::Error)); - - const auto sel = settings().diagnostics().lootLogLevel(); - - for (int i = 0; i < ui->lootLogLevel->count(); ++i) { - if (ui->lootLogLevel->itemData(i) == v(sel)) { - ui->lootLogLevel->setCurrentIndex(i); - break; - } - } -} - void DiagnosticsSettingsTab::setCrashDumpTypesBox() { ui->dumpsTypeBox->clear(); @@ -107,7 +80,4 @@ void DiagnosticsSettingsTab::update() static_cast(ui->dumpsTypeBox->currentData().toInt())); settings().diagnostics().setMaxCoreDumps(ui->dumpsMaxEdit->value()); - - settings().diagnostics().setLootLogLevel( - static_cast(ui->lootLogLevel->currentData().toInt())); } diff --git a/src/src/settingsdialogdiagnostics.h b/src/src/settingsdialogdiagnostics.h index 0888ced..23a5ed5 100644 --- a/src/src/settingsdialogdiagnostics.h +++ b/src/src/settingsdialogdiagnostics.h @@ -13,7 +13,6 @@ public: private: void setLogLevel(); - void setLootLogLevel(); void setCrashDumpTypesBox(); }; diff --git a/src/src/updatedialog.cpp b/src/src/updatedialog.cpp index ac019fb..ba81c87 100644 --- a/src/src/updatedialog.cpp +++ b/src/src/updatedialog.cpp @@ -2,7 +2,6 @@ #include "ui_updatedialog.h" #ifdef MO2_WEBENGINE -#include "lootdialog.h" // for MarkdownPage #include #endif diff --git a/src/src/updatedialog.h b/src/src/updatedialog.h index ca49a23..ec8e762 100644 --- a/src/src/updatedialog.h +++ b/src/src/updatedialog.h @@ -3,7 +3,7 @@ #include -#include "lootdialog.h" // for MarkdownDocument +#include "markdowndocument.h" #include namespace Ui -- cgit v1.3.1