aboutsummaryrefslogtreecommitdiff
path: root/libs/installer_fomod_plus/installer/lib/FileInstaller.h
blob: 1c122a760ebf669ac60ce4cdedff90bd85dae13a (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
#pragma once

#include <ifiletree.h>
#include <nlohmann/json.hpp>

#include "ConditionTester.h"
#include "FlagMap.h"
#include "Logger.h"
#include "xml/ModuleConfiguration.h"


/* This is what legacy fomodInstaller does:
        modName.update(dialog.getName(), GUESS_USER);
        return dialog.updateTree(tree);

   This is a link to the legacy updateTree method:
    https://github.com/ModOrganizer2/modorganizer-installer_fomod/blob/fc263f2d923c704b4853c11ed4f8b8cf3920f30d/src/fomodinstallerdialog.cpp#L546

*/

// Things this should do:
// - Copy all requiredInstall files
// - Copy all conditionalInstall files
// - Copy all selected files from steps that were visible to the user at the point of install

using namespace MOBase;

using FileGlobalIndex = int;
using FileDescriptor = std::pair<File, FileGlobalIndex>;

class StepViewModel;

class FileInstaller {
public:
    FileInstaller(
        IOrganizer* organizer,
        QString fomodPath,
        const std::shared_ptr<IFileTree>& fileTree,
        std::unique_ptr<ModuleConfiguration> fomodFile,
        const std::shared_ptr<FlagMap>& flagMap,
        const std::vector<std::shared_ptr<StepViewModel> >& steps);

    std::shared_ptr<IFileTree> install() const;

    /**
     * @brief Create a 'fomod.json' file to add to the base of the installTree. Functionally similar to MO2's meta.ini.
     *
     * Until there's more utility in the JSON structure itself, it will simply be of this format:
     * @code
     * {
     *  "steps": [
     *    {
     *      "name": "Step 1",
     *      "groups": [
     *        {
     *          "name": "Group 1",
     *          "plugins: [
     *            "Plugin1.esp",
     *            "Plugin2.esp"
     *          ]
     *        }
     *      ]
     *    }
     *  ]
     * }
     * @endcode
     *
     * @return nhlohmann::json
     */
    nlohmann::json generateFomodJson() const;

    std::string getQualifiedFilePath(const std::string& treePath) const;

    std::vector<std::string> collectPositiveFileNamesFromDependencyPatterns(const std::vector<DependencyPattern> &patterns);

    void addFiles(std::vector<File>& main, std::vector<File> toAdd) const;

private:
    IOrganizer* mOrganizer;
    Logger& log = Logger::getInstance();
    QString mFomodPath;
    std::shared_ptr<IFileTree> mFileTree;
    std::unique_ptr<ModuleConfiguration> mFomodFile;
    std::shared_ptr<FlagMap> mFlagMap;
    ConditionTester mConditionTester;
    std::vector<std::shared_ptr<StepViewModel> > mSteps; // TODO: Maybe this is nasty. Idk.

    std::vector<File> collectFilesToInstall() const;

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