aboutsummaryrefslogtreecommitdiff
path: root/libs/diagnose_basic/src/diagnosebasic.h
blob: 826158a64f35c826540450989f1fd34277841d35 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
Copyright (C) 2013 Sebastian Herbord. All rights reserved.

This file is part of basic diagnosis plugin for MO

This plugin is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this plugin.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DIAGNOSEBASIC_H
#define DIAGNOSEBASIC_H

#include <QRegularExpression>
#include <QSet>
#include <QString>

#include <uibase/imodlist.h>
#include <uibase/imoinfo.h>
#include <uibase/iplugin.h>
#include <uibase/iplugindiagnose.h>

class DiagnoseBasic : public QObject,
                      public MOBase::IPlugin,
                      public MOBase::IPluginDiagnose
{
  Q_OBJECT
  Q_INTERFACES(MOBase::IPlugin MOBase::IPluginDiagnose)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  Q_PLUGIN_METADATA(IID "org.tannin.DiagnoseBasic")
#endif

public:
  DiagnoseBasic();

public:  // IPlugin
  virtual bool init(MOBase::IOrganizer* moInfo);
  virtual QString name() const;
  virtual QString author() const;
  virtual QString description() const;
  virtual MOBase::VersionInfo version() const;
  virtual bool isActive() const;
  virtual QList<MOBase::PluginSetting> settings() const;

public:  // IPluginDiagnose
  virtual std::vector<unsigned int> activeProblems() const;
  virtual QString shortDescription(unsigned int key) const;
  virtual QString fullDescription(unsigned int key) const;
  virtual bool hasGuidedFix(unsigned int key) const;
  virtual void startGuidedFix(unsigned int key) const;

private:
  bool errorReported() const;
  bool overwriteFiles() const;
  bool invalidFontConfig() const;
  bool nitpickInstalled() const;
  bool assetOrder() const;
  bool missingMasters() const;
  bool alternateGame() const;
  bool fileAttributes(const QString& executable) const;

private:
  static const unsigned int PROBLEM_ERRORLOG         = 1;
  static const unsigned int PROBLEM_OVERWRITE        = 2;
  static const unsigned int PROBLEM_INVALIDFONT      = 3;
  static const unsigned int PROBLEM_NITPICKINSTALLED = 4;
  static const unsigned int PROBLEM_PROFILETWEAKS    = 7;
  static const unsigned int PROBLEM_MISSINGMASTERS   = 8;
  static const unsigned int PROBLEM_ALTERNATE        = 9;

  static const unsigned int NUM_CONTEXT_ROWS = 5;

  static const QRegularExpression RE_LOG_FILE;

private:
  struct ListElement
  {
    QString espName;
    QString modName;
    int pluginPriority;
    int modPriority;
    int sortGroup;
    bool avoidMove;
    QSet<QString> relevantScripts;
  };

  struct Move
  {
    ListElement item;
    ListElement reference;
    enum EType
    {
      BEFORE,
      AFTER
    } type;
    Move(const ListElement& initItem, const ListElement& initReference, EType initType)
        : item(initItem), reference(initReference), type(initType)
    {}
  };

  struct Sorter
  {
    struct
    {
      int operator()(const ListElement& lhs, const ListElement& rhs)
      {
        return lhs.modPriority < rhs.modPriority;
      }
    } minMod;

    std::vector<Move> moves;

    void operator()(std::vector<ListElement> modList);

  private:
    void sortGroup(std::vector<ListElement> modList);
  };

  friend bool operator<(const Move& lhs, const Move& rhs);

private:
  void topoSort(std::vector<ListElement>& list) const;
  bool checkEmpty(const QString& path) const;

private:
  MOBase::IOrganizer* m_MOInfo;
  mutable QString m_ErrorMessage;
  mutable QString m_NewestModlistBackup;
  mutable std::set<QString> m_MissingMasters;
  mutable std::map<QString, std::set<QString>> m_PluginChildren;
};

#endif  // DIAGNOSEBASIC_H