@@ -30,6 +30,29 @@ with this program; if not, write to the Free Software Foundation, Inc.,
30
30
#include " convert_json.h"
31
31
#include " script/common/c_internal.h"
32
32
33
+ void ModSpec::checkAndLog () const
34
+ {
35
+ if (!string_allowed (name, MODNAME_ALLOWED_CHARS)) {
36
+ throw ModError (" Error loading mod \" " + name +
37
+ " \" : Mod name does not follow naming conventions: "
38
+ " Only characters [a-z0-9_] are allowed." );
39
+ }
40
+
41
+ // Log deprecation messages
42
+ auto handling_mode = get_deprecated_handling_mode ();
43
+ if (!deprecation_msgs.empty () && handling_mode != DeprecatedHandlingMode::Ignore) {
44
+ std::ostringstream os;
45
+ os << " Mod " << name << " at " << path << " :" << std::endl;
46
+ for (auto msg : deprecation_msgs)
47
+ os << " \t " << msg << std::endl;
48
+
49
+ if (handling_mode == DeprecatedHandlingMode::Error)
50
+ throw ModError (os.str ());
51
+ else
52
+ warningstream << os.str ();
53
+ }
54
+ }
55
+
33
56
bool parseDependsString (std::string &dep, std::unordered_set<char > &symbols)
34
57
{
35
58
dep = trim (dep);
@@ -45,21 +68,6 @@ bool parseDependsString(std::string &dep, std::unordered_set<char> &symbols)
45
68
return !dep.empty ();
46
69
}
47
70
48
- static void log_mod_deprecation (const ModSpec &spec, const std::string &warning)
49
- {
50
- auto handling_mode = get_deprecated_handling_mode ();
51
- if (handling_mode != DeprecatedHandlingMode::Ignore) {
52
- std::ostringstream os;
53
- os << warning << " (" << spec.name << " at " << spec.path << " )" << std::endl;
54
-
55
- if (handling_mode == DeprecatedHandlingMode::Error) {
56
- throw ModError (os.str ());
57
- } else {
58
- warningstream << os.str ();
59
- }
60
- }
61
- }
62
-
63
71
void parseModContents (ModSpec &spec)
64
72
{
65
73
// NOTE: this function works in mutual recursion with getModsInPath
@@ -89,7 +97,7 @@ void parseModContents(ModSpec &spec)
89
97
if (info.exists (" name" ))
90
98
spec.name = info.get (" name" );
91
99
else
92
- log_mod_deprecation ( spec, " Mods not having a mod.conf file with the name is deprecated." );
100
+ spec. deprecation_msgs . push_back ( " Mods not having a mod.conf file with the name is deprecated." );
93
101
94
102
if (info.exists (" author" ))
95
103
spec.author = info.get (" author" );
@@ -130,7 +138,7 @@ void parseModContents(ModSpec &spec)
130
138
std::ifstream is ((spec.path + DIR_DELIM + " depends.txt" ).c_str ());
131
139
132
140
if (is.good ())
133
- log_mod_deprecation ( spec, " depends.txt is deprecated, please use mod.conf instead." );
141
+ spec. deprecation_msgs . push_back ( " depends.txt is deprecated, please use mod.conf instead." );
134
142
135
143
while (is.good ()) {
136
144
std::string dep;
@@ -153,7 +161,7 @@ void parseModContents(ModSpec &spec)
153
161
if (info.exists (" description" ))
154
162
spec.desc = info.get (" description" );
155
163
else if (fs::ReadFile (spec.path + DIR_DELIM + " description.txt" , spec.desc ))
156
- log_mod_deprecation ( spec, " description.txt is deprecated, please use mod.conf instead." );
164
+ spec. deprecation_msgs . push_back ( " description.txt is deprecated, please use mod.conf instead." );
157
165
}
158
166
}
159
167
0 commit comments