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

Commit 6c9fe91

Browse files
committed
Make returned path generic in PresetMan::FullModulePath to not have to correct backslashes after getting it (twice in some cases)
1 parent 04a8fc4 commit 6c9fe91

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Managers/PresetMan.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,19 @@ bool PresetMan::IsModuleUserdata(std::string moduleName) const {
351351

352352
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
353353

354-
std::string PresetMan::FullModulePath(std::string modulePath)
355-
{
356-
const std::string moduleName = GetModuleNameFromPath(modulePath);
357-
const std::string moduleFolder = (IsModuleOfficial(moduleName) ? "Data/" : IsModuleUserdata(moduleName) ? System::GetUserdataDirectory() : System::GetModDirectory());
358-
const std::string topFolder = modulePath.substr(0, modulePath.find_first_of("/\\") + 1);
359-
if (topFolder == moduleFolder) {
360-
return modulePath;
361-
}
362-
return moduleFolder + modulePath;
354+
std::string PresetMan::FullModulePath(const std::string &modulePath) {
355+
const std::string modulePathGeneric = std::filesystem::path(modulePath).generic_string();
356+
const std::string pathTopDir = modulePathGeneric.substr(0, modulePathGeneric.find_first_of("/\\") + 1);
357+
const std::string moduleName = GetModuleNameFromPath(modulePathGeneric);
358+
359+
std::string moduleTopDir = System::GetModDirectory();
360+
361+
if (IsModuleOfficial(moduleName)) {
362+
moduleTopDir = System::GetDataDirectory();
363+
} else if (IsModuleUserdata(moduleName)) {
364+
moduleTopDir = System::GetUserdataDirectory();
365+
}
366+
return (pathTopDir == moduleTopDir) ? modulePathGeneric : moduleTopDir + modulePathGeneric;
363367
}
364368

365369
//////////////////////////////////////////////////////////////////////////////////////////

Managers/PresetMan.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ class PresetMan : public Singleton<PresetMan> {
178178
/// <returns>True if the module is an official data module, otherwise false.</returns>
179179
bool IsModuleOfficial(std::string moduleName);
180180

181-
182181
/// <summary>
183182
/// Returns whether or not the module is vanilla.
184183
/// </summary>
@@ -191,7 +190,7 @@ class PresetMan : public Singleton<PresetMan> {
191190
/// </summary>
192191
/// <param name="modulePath">The Path to be completed.</param>
193192
/// <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>
194-
std::string FullModulePath(std::string modulePath);
193+
std::string FullModulePath(const std::string &modulePath);
195194

196195
//////////////////////////////////////////////////////////////////////////////////////////
197196
// Method: GetTotalModuleCount

System/System.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace RTE {
1616
std::vector<size_t> System::s_WorkingTree;
1717
std::filesystem::file_time_type System::s_ProgramStartTime = std::filesystem::file_time_type::clock::now();
1818
bool System::s_CaseSensitive = true;
19+
const std::string System::s_DataDirectory = "Data/";
1920
const std::string System::s_ScreenshotDirectory = "ScreenShots/";
2021
const std::string System::s_ModDirectory = "Mods/";
2122
const std::string System::s_UserdataDirectory = "Userdata/";

System/System.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ namespace RTE {
4343
/// <returns>Absolute path to current working directory.</returns>
4444
static const std::string & GetWorkingDirectory() { return s_WorkingDirectory; }
4545

46+
/// <summary>
47+
/// Gets the game data directory name.
48+
/// </summary>
49+
/// <returns>Folder name of the game data directory.</returns>
50+
static const std::string & GetDataDirectory() { return s_DataDirectory; }
51+
4652
/// <summary>
4753
/// Gets the screenshot directory name.
4854
/// </summary>
@@ -174,6 +180,7 @@ namespace RTE {
174180
static std::filesystem::file_time_type s_ProgramStartTime; //!< Low precision time point of program start for checking if a file was created after starting.
175181

176182
static bool s_CaseSensitive; //!< Whether case sensitivity is enforced when checking for file existence.
183+
static const std::string s_DataDirectory; //!< String containing the folder name of the game data directory.
177184
static const std::string s_ScreenshotDirectory; //!< String containing the folder name of the screenshots directory.
178185
static const std::string s_ModDirectory; //!< String containing the folder name of the mod directory.
179186
static const std::string s_UserdataDirectory; //!< String containing the folder name of the userdata directory.

0 commit comments

Comments
 (0)