aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_fomod_plus/installer/FomodPlusInstaller.h
blob: 494ad8e85bf8b9e1731507d851b8279f9da163f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once

#include "stringutil.h"

#include <iplugin.h>
#include <iplugininstaller.h>
#include <iplugininstallersimple.h>

#include <nlohmann/json.hpp>
#include "FomodInstallerWindow.h"
#include "lib/Logger.h"
#include "xml/FomodInfoFile.h"
#include "xml/ModuleConfiguration.h"

#include <QDialog>
#include <integration/FomodDataContent.h>
#include <FOMODData/FomodDB.h>

class FomodInstallerWindow;

using namespace MOBase;
using namespace std;

using ParsedFilesTuple = std::tuple<std::unique_ptr<FomodInfoFile>, std::unique_ptr<ModuleConfiguration>, QStringList>;

class FomodPlusInstaller final : public IPluginInstallerSimple {
    Q_OBJECT
    Q_INTERFACES(MOBase::IPlugin MOBase::IPluginInstaller)
    Q_PLUGIN_METADATA(IID "io.clearing.FomodPlus" FILE "fomodplus.json")

public:
    bool init(IOrganizer* organizer) override;

    // constant values
    [[nodiscard]] QString name() const override { return StringConstants::Plugin::NAME.data(); }
    [[nodiscard]] QString author() const override { return StringConstants::Plugin::AUTHOR.data(); }
    [[nodiscard]] QString description() const override { return StringConstants::Plugin::DESCRIPTION.data(); }
    [[nodiscard]] VersionInfo version() const override { return { 1, 0, 0, VersionInfo::RELEASE_FINAL }; }

    [[nodiscard]] unsigned int priority() const override
    {
        return 999; /* Above installer_fomod's highest priority. */
    }

    [[nodiscard]] std::vector<std::shared_ptr<const IPluginRequirement> > requirements() const override;

    [[nodiscard]] bool isManualInstaller() const override { return false; }

    [[nodiscard]] bool isArchiveSupported(std::shared_ptr<const IFileTree> tree) const override;

    [[nodiscard]] QList<PluginSetting> settings() const override;

    std::pair<nlohmann::json, IModInterface*> getExistingFomodJson(const GuessedValue<QString>& modName,
        const int& nexusId, const int& stepsInCurrentFomod) const;

    void clearPriorInstallData();

    EInstallResult install(GuessedValue<QString>& modName, std::shared_ptr<IFileTree>& tree, QString& version,
        int& nexusID) override;

    void onInstallationStart(QString const& archive, bool reinstallation, IModInterface* currentMod) override;

    void onInstallationEnd(EInstallResult result, IModInterface* newMod) override;

    [[nodiscard]] bool shouldShowImages() const;

    [[nodiscard]] bool shouldShowNotifications() const;
    bool shouldShowSidebarFilter() const;

    [[nodiscard]] bool shouldAutoRestoreChoices() const;

    [[nodiscard]] bool isWizardIntegrated() const;

    void toggleShouldShowImages() const;

    QString getSelectedColor() const;

private:
    Logger& log            = Logger::getInstance();
    IOrganizer* mOrganizer = nullptr;
    QString mFomodPath{};
    std::shared_ptr<nlohmann::json> mFomodJson{ nullptr };
    bool mInstallerUsed{ false };
    std::shared_ptr<FomodDataContent> mFomodContent{ nullptr };
    std::unique_ptr<FomodDB> mFomodDb;

    /**
   * @brief Retrieve the tree entry corresponding to the fomod directory.
   *
   * @param tree Tree to look-up the directory in.
   *
   * @return the entry corresponding to the fomod directory in the tree, or a null
   * pointer if the entry was not found.
   */
    [[nodiscard]] static shared_ptr<const IFileTree> findFomodDirectory(const shared_ptr<const IFileTree>& tree);

    [[nodiscard]] static QDialog::DialogCode showInstallerWindow(const shared_ptr<FomodInstallerWindow>& window);

    [[nodiscard]] ParsedFilesTuple parseFomodFiles(const shared_ptr<IFileTree>& tree);

    static void appendImageFiles(vector<shared_ptr<const FileTreeEntry> >& entries,
        const shared_ptr<const IFileTree>& tree);

    void appendPluginFiles(vector<shared_ptr<const FileTreeEntry> >& entries, const shared_ptr<const IFileTree>& tree);

    void setupUiInjection() const;
    void toggleFeature(bool enabled) const;

    [[nodiscard]] bool shouldFallbackToLegacyInstaller() const;

    void logMessage(const LogLevel level, const std::string& message) const
    {
        log.logMessage(level, "[INSTALLER] " + message);
    }
};