diff options
| author | Chris Bessent <lost.dragonist@gmail.com> | 2020-01-06 05:17:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-06 05:17:01 -0700 |
| commit | dfa600996c49c1b23dca884c963dc917bd9cfc0a (patch) | |
| tree | c6def4277cc962822d0dcde71fa9148e050f693f /src/loot.h | |
| parent | e69078e2399a88bda7bb9ffae7a3d57db9a4e9cf (diff) | |
| parent | d1a788dfad341b32235abc25c2ba1645f8be1ace (diff) | |
Merge pull request #954 from ModOrganizer2/Develop
Stage for release 2.2.2
Diffstat (limited to 'src/loot.h')
| -rw-r--r-- | src/loot.h | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/loot.h b/src/loot.h new file mode 100644 index 00000000..f9943626 --- /dev/null +++ b/src/loot.h @@ -0,0 +1,144 @@ +#ifndef MODORGANIZER_LOOT_H +#define MODORGANIZER_LOOT_H + +#include "envmodule.h" +#include <log.h> +#include <lootcli/lootcli.h> +#include <windows.h> +#include <QWidget> + +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<File> incompatibilities; + std::vector<Message> messages; + std::vector<Dirty> dirty, clean; + std::vector<QString> 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<QString> errors, warnings; + std::vector<Message> messages; + std::vector<Plugin> 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<QString>& errors() const; + const std::vector<QString>& 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<QThread> m_thread; + std::atomic<bool> m_cancel; + std::atomic<bool> m_result; + env::HandlePtr m_lootProcess; + std::unique_ptr<AsyncPipe> m_pipe; + std::string m_outputBuffer; + std::vector<QString> 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<Plugin> reportPlugins(const QJsonArray& plugins) const; + Loot::Plugin reportPlugin(const QJsonObject& plugin) const; + Loot::Stats reportStats(const QJsonObject& stats) const; + + std::vector<Message> reportMessages(const QJsonArray& array) const; + std::vector<Loot::File> reportFiles(const QJsonArray& array) const; + std::vector<Loot::Dirty> reportDirty(const QJsonArray& array) const; + std::vector<QString> reportStringArray(const QJsonArray& array) const; +}; + + +bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList); + +#endif // MODORGANIZER_LOOT_H |
