Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 1cf3ca7

Browse files
committed
Cleanup and const correctness
1 parent ecc13a9 commit 1cf3ca7

File tree

4 files changed

+35
-55
lines changed

4 files changed

+35
-55
lines changed

Managers/FrameMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ namespace RTE {
512512

513513
std::string fullFileName(fullFileNameBuffer.data());
514514
#else
515-
std::string fullFileName = std::format("{}/{}_{:%F_%H-%M-%S}.png", System::GetScreenshotDirectory(), nameBase, std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
515+
std::string fullFileName = std::format("{}{}_{:%F_%H-%M-%S}.png", System::GetScreenshotDirectory(), nameBase, std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
516516
#endif
517517

518518
bool saveSuccess = false;

Managers/PresetMan.cpp

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "LoadingScreen.h"
3030
#include "SettingsMan.h"
3131

32-
33-
3432
namespace RTE {
3533

3634
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)
285283

286284
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
287285

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("/\\");
298291

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;
301294

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+
}
311301

312-
// Remove trailing slash
313302
if (!moduleName.empty() && moduleName.back() == '/') {
314303
moduleName.pop_back();
315304
}
316-
317-
return moduleName;
305+
return moduleName;
318306
}
319307

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+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330309

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));
333315
}
334316

335317
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336318

337-
bool PresetMan::IsModuleOfficial(std::string moduleName) {
319+
bool PresetMan::IsModuleOfficial(const std::string &moduleName) const {
338320
return std::find(c_OfficialModules.begin(), c_OfficialModules.end(), moduleName) != c_OfficialModules.end();
339321
}
340322

341323
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
342324

343-
bool PresetMan::IsModuleUserdata(std::string moduleName) const {
325+
bool PresetMan::IsModuleUserdata(const std::string &moduleName) const {
344326
auto userdataModuleItr = std::find_if(c_UserdataModules.begin(), c_UserdataModules.end(),
345327
[&moduleName](const auto &userdataModulesEntry) {
346328
return userdataModulesEntry.first == moduleName;
@@ -351,7 +333,7 @@ bool PresetMan::IsModuleUserdata(std::string moduleName) const {
351333

352334
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
353335

354-
std::string PresetMan::GetFullModulePath(const std::string &modulePath) {
336+
std::string PresetMan::GetFullModulePath(const std::string &modulePath) const {
355337
const std::string modulePathGeneric = std::filesystem::path(modulePath).generic_string();
356338
const std::string pathTopDir = modulePathGeneric.substr(0, modulePathGeneric.find_first_of("/\\") + 1);
357339
const std::string moduleName = GetModuleNameFromPath(modulePathGeneric);

Managers/PresetMan.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,35 @@ class PresetMan : public Singleton<PresetMan> {
160160
/// </summary>
161161
/// <param name="dataPath">The full path to a data file inside the data module id you want to get.</param>
162162
/// <returns>The requested Name. If no module of the name was found, "" will be returned.</returns>
163-
std::string GetModuleNameFromPath(std::string dataPath);
163+
std::string GetModuleNameFromPath(const std::string &dataPath) const;
164164

165-
//////////////////////////////////////////////////////////////////////////////////////////
166-
// Method: GetModuleIDFromPath
167-
//////////////////////////////////////////////////////////////////////////////////////////
168-
// Description: Gets the ID of a loaded DataModule, from a full data file path.
169-
// Arguments: The full path to a data file inside the data module id you want to get.
170-
// Return value: The requested ID. If no module of the name was found, -1 will be returned.
171-
172-
int GetModuleIDFromPath(std::string dataPath);
165+
/// <summary>
166+
/// Gets the ID of a loaded DataModule from a full data file path.
167+
/// </summary>
168+
/// <param name="dataPath">The full path to a data file inside the data module ID you want to get.</param>
169+
/// <returns>The requested ID. If no module of the name was found, -1 will be returned.</returns>
170+
int GetModuleIDFromPath(const std::string &dataPath);
173171

174172
/// <summary>
175173
/// Returns whether or not the module is vanilla.
176174
/// </summary>
177175
/// <param name="moduleName">The name of the module to check, in the form "[moduleName].rte"</param>
178176
/// <returns>True if the module is an official data module, otherwise false.</returns>
179-
bool IsModuleOfficial(std::string moduleName);
177+
bool IsModuleOfficial(const std::string &moduleName) const;
180178

181179
/// <summary>
182180
/// Returns whether or not the module is vanilla.
183181
/// </summary>
184182
/// <param name="moduleName">The name of the module to check, in the form "[moduleName].rte"</param>
185183
/// <returns>True if the module is a listed user data module, otherwise false.</returns>
186-
bool IsModuleUserdata(std::string moduleName) const;
184+
bool IsModuleUserdata(const std::string &moduleName) const;
187185

188186
/// <summary>
189187
/// Returns the Full path to the module including Data/, Userdata/ or Mods/.
190188
/// </summary>
191189
/// <param name="modulePath">The Path to be completed.</param>
192190
/// <returns>The complete path to the file, including Data/, Userdata/ or Mods/ based on whether or not it's part of an official module or userdata.</returns>
193-
std::string GetFullModulePath(const std::string &modulePath);
191+
std::string GetFullModulePath(const std::string &modulePath) const;
194192

195193
//////////////////////////////////////////////////////////////////////////////////////////
196194
// Method: GetTotalModuleCount

System/DataModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace RTE {
7070
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7171

7272
bool DataModule::CreateOnDiskAsUserdata(const std::string &moduleName, const std::string_view &friendlyName, bool ignoreMissingItems, bool scanFolderContents) {
73-
std::string moduleNameWithPackageExtension = System::GetUserdataDirectory() + moduleName + ((moduleName.ends_with(System::GetModulePackageExtension()) ? "" : System::GetModulePackageExtension()));
73+
std::string moduleNameWithPackageExtension = System::GetUserdataDirectory() + moduleName + (moduleName.ends_with(System::GetModulePackageExtension()) ? "" : System::GetModulePackageExtension());
7474
if (Writer writer(moduleNameWithPackageExtension + "/Index.ini", false, true); writer.WriterOK()) {
7575
DataModule newModule;
7676
newModule.m_IsUserdata = true;

0 commit comments

Comments
 (0)