aboutsummaryrefslogtreecommitdiff
path: root/libs/form43_checker_native/src/form43checker.cpp
blob: e3cb67685e934d9b928b36b08a3673d0b8cbc4d6 (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
#include "form43checker.h"

#include <uibase/ipluginlist.h>
#include <uibase/pluginrequirements.h>

#include <QCoreApplication>
#include <QFileInfo>

using namespace MOBase;

Form43Checker::Form43Checker() : m_organizer(nullptr) {}

bool Form43Checker::init(IOrganizer* moInfo)
{
  m_organizer = moInfo;
  return true;
}

QString Form43Checker::name() const
{
  return "Form 43 Plugin Checker (Native)";
}

QString Form43Checker::localizedName() const
{
  return tr("Form 43 Plugin Checker (Native)");
}

QString Form43Checker::author() const
{
  return "AnyOldName3";
}

QString Form43Checker::description() const
{
  return tr("Checks plugins (.ESM/.ESP files) to see if any are lower than "
            "Form 44 (Skyrim SE).");
}

VersionInfo Form43Checker::version() const
{
  return VersionInfo(1, 2, 0, VersionInfo::RELEASE_FINAL);
}

std::vector<std::shared_ptr<const IPluginRequirement>>
Form43Checker::requirements() const
{
  return {PluginRequirementFactory::gameDependency("Skyrim Special Edition")};
}

QList<PluginSetting> Form43Checker::settings() const
{
  return {};
}

std::vector<unsigned int> Form43Checker::activeProblems() const
{
  updateInvalidPlugins();
  if (!m_invalidPlugins.isEmpty()) {
    return {PROBLEM_FORM43};
  }
  return {};
}

QString Form43Checker::shortDescription(unsigned int key) const
{
  return tr("Form 43 (or lower) plugin detected");
}

QString Form43Checker::fullDescription(unsigned int key) const
{
  QStringList plugins = listPlugins();
  QString pluginListString =
      "<br><br>\u2022  " + plugins.join("<br>\u2022  ");

  QString output = tr("You have one or more plugins that are not form 44. "
                       "They are:%1")
                       .arg(pluginListString);
  output += "<br><br>";
  output += tr(
      "Form 43 (or lower) plugins are modules that were made for Skyrim LE "
      "(Oldrim) and have not been properly ported to Skyrim Special Edition, "
      "which uses form 44 plugins. This usually results in parts of the mod "
      "not working correctly."
      "<br><br>"
      "To be converted, these plugins simply need to be opened and saved with "
      "the SSE Creation Kit but their presence can be an indication that a mod "
      "was not properly ported to SSE and so can potentially have additional "
      "issues."
      "<br><br>"
      "Online guides can have more information on how to correctly convert mods "
      "for Skyrim SE.<br>");
  return output;
}

bool Form43Checker::hasGuidedFix(unsigned int key) const
{
  return false;
}

void Form43Checker::startGuidedFix(unsigned int key) const {}

void Form43Checker::updateInvalidPlugins() const
{
  m_invalidPlugins.clear();
  QStringList files = m_organizer->findFiles(
      "", QStringList() << "*.esp" << "*.esm");
  for (const QString& file : files) {
    int ver = getFormVersion(file);
    if (ver != -1 && ver < 44) {
      m_invalidPlugins.append(file);
    }
  }
}

int Form43Checker::getFormVersion(const QString& file) const
{
  QString pluginName = QFileInfo(file).fileName();
  return m_organizer->pluginList()->formVersion(pluginName);
}

QStringList Form43Checker::listPlugins() const
{
  QStringList result;
  for (const QString& file : m_invalidPlugins) {
    QString pluginName = QFileInfo(file).fileName();
    int ver            = getFormVersion(file);
    result.append(QString("%1 (form %2)").arg(pluginName).arg(ver));
  }
  return result;
}