29
29
#include " LoadingScreen.h"
30
30
#include " SettingsMan.h"
31
31
32
-
33
-
34
32
namespace RTE {
35
33
36
34
const std::array<std::string, 10 > PresetMan::c_OfficialModules = { " Base.rte" , " Coalition.rte" , " Imperatus.rte" , " Techion.rte" , " Dummy.rte" , " Ronin.rte" , " Browncoats.rte" , " Uzira.rte" , " MuIlaak.rte" , " Missions.rte" };
@@ -285,62 +283,46 @@ int PresetMan::GetModuleID(std::string moduleName)
285
283
286
284
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
287
285
288
- std::string PresetMan::GetModuleNameFromPath (std::string dataPath)
289
- {
290
- if (dataPath.empty ()) {
291
- return " " ;
292
- }
293
-
294
- int slashPos = dataPath.find_first_of ( ' /' );
295
- if (slashPos == std::string::npos) {
296
- slashPos = dataPath.find_first_of ( ' \\ ' );
297
- }
286
+ std::string PresetMan::GetModuleNameFromPath (const std::string &dataPath) const {
287
+ if (dataPath.empty ()) {
288
+ return " " ;
289
+ }
290
+ size_t slashPos = dataPath.find_first_of (" /\\ " );
298
291
299
- // Include trailing slash in the substring range in case we need to match against the Data/Mods/Userdata directory
300
- std::string moduleName = slashPos != std::string::npos ? dataPath.substr ( 0 , slashPos + 1 ) : dataPath;
292
+ // Include trailing slash in the substring range in case we need to match against the Data/Mods/Userdata directory.
293
+ std::string moduleName = ( slashPos != std::string::npos) ? dataPath.substr (0 , slashPos + 1 ) : dataPath;
301
294
302
- // Check if path starts with Data/ or the Mods/Userdata dir names and remove that part to get to the actual module name.
303
- if (moduleName == " Data/" || moduleName == System::GetModDirectory () || moduleName == System::GetUserdataDirectory ()) {
304
- std::string shortenPath = dataPath.substr ( slashPos + 1 );
305
- slashPos = shortenPath.find_first_of ( ' /' );
306
- if (slashPos == std::string::npos) {
307
- slashPos = shortenPath.find_first_of ( ' \\ ' );
308
- }
309
- moduleName = shortenPath.substr ( 0 , slashPos + 1 );
310
- }
295
+ // Check if path starts with Data/ or the Mods/Userdata dir names and remove that part to get to the actual module name.
296
+ if (moduleName == System::GetDataDirectory () || moduleName == System::GetModDirectory () || moduleName == System::GetUserdataDirectory ()) {
297
+ std::string shortenPath = dataPath.substr (slashPos + 1 );
298
+ slashPos = shortenPath.find_first_of (" /\\ " );
299
+ moduleName = shortenPath.substr (0 , slashPos + 1 );
300
+ }
311
301
312
- // Remove trailing slash
313
302
if (!moduleName.empty () && moduleName.back () == ' /' ) {
314
303
moduleName.pop_back ();
315
304
}
316
-
317
- return moduleName;
305
+ return moduleName;
318
306
}
319
307
320
- // ////////////////////////////////////////////////////////////////////////////////////////
321
- // Method: GetModuleIDFromPath
322
- // ////////////////////////////////////////////////////////////////////////////////////////
323
- // Description: Gets the ID of a loaded DataModule, from a full data file path.
324
-
325
- int PresetMan::GetModuleIDFromPath (std::string dataPath)
326
- {
327
- if (dataPath.empty ()) {
328
- return -1 ;
329
- }
308
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330
309
331
- const std::string moduleName = GetModuleNameFromPath (dataPath);
332
- return GetModuleID (moduleName);
310
+ int PresetMan::GetModuleIDFromPath (const std::string &dataPath) {
311
+ if (dataPath.empty ()) {
312
+ return -1 ;
313
+ }
314
+ return GetModuleID (GetModuleNameFromPath (dataPath));
333
315
}
334
316
335
317
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336
318
337
- bool PresetMan::IsModuleOfficial (std::string moduleName) {
319
+ bool PresetMan::IsModuleOfficial (const std::string & moduleName) const {
338
320
return std::find (c_OfficialModules.begin (), c_OfficialModules.end (), moduleName) != c_OfficialModules.end ();
339
321
}
340
322
341
323
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
342
324
343
- bool PresetMan::IsModuleUserdata (std::string moduleName) const {
325
+ bool PresetMan::IsModuleUserdata (const std::string & moduleName) const {
344
326
auto userdataModuleItr = std::find_if (c_UserdataModules.begin (), c_UserdataModules.end (),
345
327
[&moduleName](const auto &userdataModulesEntry) {
346
328
return userdataModulesEntry.first == moduleName;
@@ -351,7 +333,7 @@ bool PresetMan::IsModuleUserdata(std::string moduleName) const {
351
333
352
334
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
353
335
354
- std::string PresetMan::GetFullModulePath (const std::string &modulePath) {
336
+ std::string PresetMan::GetFullModulePath (const std::string &modulePath) const {
355
337
const std::string modulePathGeneric = std::filesystem::path (modulePath).generic_string ();
356
338
const std::string pathTopDir = modulePathGeneric.substr (0 , modulePathGeneric.find_first_of (" /\\ " ) + 1 );
357
339
const std::string moduleName = GetModuleNameFromPath (modulePathGeneric);
0 commit comments