@@ -214,6 +214,55 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
214
214
}
215
215
}
216
216
217
+ void ModConfiguration::addModsFormConfig (const std::string &settings_path, const std::set<std::string> &mods)
218
+ {
219
+ Settings conf;
220
+ std::set<std::string> load_mod_names;
221
+
222
+ conf.readConfigFile (settings_path.c_str ());
223
+ std::vector<std::string> names = conf.getNames ();
224
+ for (std::vector<std::string>::iterator it = names.begin ();
225
+ it != names.end (); ++it) {
226
+ std::string name = *it;
227
+ if (name.compare (0 ,9 ," load_mod_" )==0 && conf.getBool (name))
228
+ load_mod_names.insert (name.substr (9 ));
229
+ }
230
+
231
+ std::vector<ModSpec> addon_mods;
232
+ for (std::set<std::string>::const_iterator i = mods.begin ();
233
+ i != mods.end (); ++i) {
234
+ std::vector<ModSpec> addon_mods_in_path = flattenMods (getModsInPath (*i));
235
+ for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin ();
236
+ it != addon_mods_in_path.end (); ++it) {
237
+ const ModSpec& mod = *it;
238
+ if (load_mod_names.count (mod.name ) != 0 )
239
+ addon_mods.push_back (mod);
240
+ else
241
+ conf.setBool (" load_mod_" + mod.name , false );
242
+ }
243
+ }
244
+ conf.updateConfigFile (settings_path.c_str ());
245
+
246
+ addMods (addon_mods);
247
+ checkConflictsAndDeps ();
248
+
249
+ // complain about mods declared to be loaded, but not found
250
+ for (std::vector<ModSpec>::iterator it = addon_mods.begin ();
251
+ it != addon_mods.end (); ++it)
252
+ load_mod_names.erase ((*it).name );
253
+ std::vector<ModSpec> UnsatisfiedMods = getUnsatisfiedMods ();
254
+ for (std::vector<ModSpec>::iterator it = UnsatisfiedMods.begin ();
255
+ it != UnsatisfiedMods.end (); ++it)
256
+ load_mod_names.erase ((*it).name );
257
+ if (!load_mod_names.empty ()) {
258
+ errorstream << " The following mods could not be found:" ;
259
+ for (std::set<std::string>::iterator it = load_mod_names.begin ();
260
+ it != load_mod_names.end (); ++it)
261
+ errorstream << " \" " << (*it) << " \" " ;
262
+ errorstream << std::endl;
263
+ }
264
+ }
265
+
217
266
void ModConfiguration::checkConflictsAndDeps ()
218
267
{
219
268
// report on name conflicts
@@ -296,53 +345,22 @@ ServerModConfiguration::ServerModConfiguration(const std::string &worldpath):
296
345
addModsInPath (gamespec.gamemods_path );
297
346
addModsInPath (worldpath + DIR_DELIM + " worldmods" );
298
347
299
- // check world.mt file for mods explicitely declared to be
300
- // loaded or not by a load_mod_<modname> = ... line.
301
- std::string worldmt = worldpath+DIR_DELIM+" world.mt" ;
302
- Settings worldmt_settings;
303
- worldmt_settings.readConfigFile (worldmt.c_str ());
304
- std::vector<std::string> names = worldmt_settings.getNames ();
305
- std::set<std::string> include_mod_names;
306
- for (std::vector<std::string>::const_iterator it = names.begin ();
307
- it != names.end (); ++it) {
308
- std::string name = *it;
309
- // for backwards compatibility: exclude only mods which are
310
- // explicitely excluded. if mod is not mentioned at all, it is
311
- // enabled. So by default, all installed mods are enabled.
312
- if (name.compare (0 ,9 ," load_mod_" ) == 0 &&
313
- worldmt_settings.getBool (name)) {
314
- include_mod_names.insert (name.substr (9 ));
315
- }
316
- }
317
-
318
- // Collect all mods that are also in include_mod_names
319
- std::vector<ModSpec> addon_mods;
320
- for (std::set<std::string>::const_iterator it_path = gamespec.addon_mods_paths .begin ();
321
- it_path != gamespec.addon_mods_paths .end (); ++it_path) {
322
- std::vector<ModSpec> addon_mods_in_path = flattenMods (getModsInPath (*it_path));
323
- for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin ();
324
- it != addon_mods_in_path.end (); ++it) {
325
- const ModSpec& mod = *it;
326
- if (include_mod_names.count (mod.name ) != 0 )
327
- addon_mods.push_back (mod);
328
- else
329
- worldmt_settings.setBool (" load_mod_" + mod.name , false );
330
- }
331
- }
332
- worldmt_settings.updateConfigFile (worldmt.c_str ());
333
-
334
- addMods (addon_mods);
335
-
336
- checkConflictsAndDeps ();
348
+ // Load normal mods
349
+ std::string worldmt = worldpath + DIR_DELIM + " world.mt" ;
350
+ addModsFormConfig (worldmt, gamespec.addon_mods_paths );
337
351
}
338
352
339
353
#ifndef SERVER
340
354
ClientModConfiguration::ClientModConfiguration (const std::string &path):
341
355
ModConfiguration(path)
342
356
{
343
- addModsInPath (path);
344
- addModsInPath (porting::path_user + DIR_DELIM + " clientmods" );
345
- checkConflictsAndDeps ();
357
+ std::set<std::string> paths;
358
+ std::string path_user = porting::path_user + DIR_DELIM + " clientmods" ;
359
+ paths.insert (path);
360
+ paths.insert (path_user);
361
+
362
+ std::string settings_path = path_user + DIR_DELIM + " mods.conf" ;
363
+ addModsFormConfig (settings_path, paths);
346
364
}
347
365
#endif
348
366
0 commit comments