Skip to content

Commit 629842b

Browse files
committed
Move GetCaseInsensitiveFullPath() to RTETools
Remove vestigial #include
1 parent 71ee722 commit 629842b

File tree

4 files changed

+44
-47
lines changed

4 files changed

+44
-47
lines changed

Source/Managers/LuaMan.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -939,42 +939,6 @@ namespace RTE {
939939
return stackDescription.str();
940940
}
941941

942-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
943-
944-
// TODO: Ask Causeless whether this is an appropriate spot for this method
945-
std::string LuaMan::GetCaseInsensitiveFullPath(const std::string &fullPath) {
946-
std::filesystem::path inspectedPath = System::GetWorkingDirectory();
947-
const std::filesystem::path relativeFilePath = std::filesystem::path(fullPath).lexically_relative(inspectedPath);
948-
949-
// Iterate over all path parts
950-
for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin(); relativeFilePathIterator != relativeFilePath.end(); ++relativeFilePathIterator) {
951-
bool pathPartExists = false;
952-
953-
// Iterate over all entries in the path part's directory,
954-
// to check if the path part is in there case insensitively
955-
for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator(inspectedPath)) {
956-
if (StringsEqualCaseInsensitive(filesystemEntryPath.filename().generic_string(), relativeFilePathIterator->generic_string())) {
957-
inspectedPath = filesystemEntryPath;
958-
959-
// If the path part is found, stop looking for it
960-
pathPartExists = true;
961-
break;
962-
}
963-
}
964-
965-
if (!pathPartExists) {
966-
// If part of the path exists, append the rest of fullPath its parts
967-
while (relativeFilePathIterator != relativeFilePath.end()) {
968-
inspectedPath /= relativeFilePathIterator->generic_string();
969-
relativeFilePathIterator++;
970-
}
971-
break;
972-
}
973-
}
974-
975-
return inspectedPath.generic_string();
976-
}
977-
978942
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
979943

980944
const std::vector<std::string> * LuaMan::DirectoryList(const std::string &path) {

Source/Managers/LuaMan.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include "BS_thread_pool.hpp"
1010

11-
#include <optional>
12-
1311
#define g_LuaMan LuaMan::Instance()
1412

1513
struct lua_State;
@@ -438,15 +436,6 @@ namespace RTE {
438436
#pragma endregion
439437

440438
#pragma region File I/O Handling
441-
/// <summary>
442-
/// If a file "foo/Bar.txt" exists, and this method is passed "FOO/BAR.TXT", then this method will return "foo/Bar.txt".
443-
/// This method's purpose is to enable Linux to get the real path using a case-insensitive search.
444-
/// The real path is used by the Lua file I/O handling methods to ensure full Windows compatibility.
445-
/// </summary>
446-
/// <param name="fullPath">Path to case-insensitively translate to a real path.</param>
447-
/// <returns>The real path. If the path doesn't exist, it returns the fullPath argument with all the existing parent directories correctly capitalized.</returns>
448-
std::string GetCaseInsensitiveFullPath(const std::string &fullPath);
449-
450439
/// <summary>
451440
/// Returns a vector of all the directories in path, which is relative to the working directory.
452441
/// </summary>

Source/System/RTETools.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,39 @@ namespace RTE {
218218

219219
return hash;
220220
}
221+
222+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223+
224+
std::string GetCaseInsensitiveFullPath(const std::string &fullPath) {
225+
std::filesystem::path inspectedPath = System::GetWorkingDirectory();
226+
const std::filesystem::path relativeFilePath = std::filesystem::path(fullPath).lexically_relative(inspectedPath);
227+
228+
// Iterate over all path parts
229+
for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin(); relativeFilePathIterator != relativeFilePath.end(); ++relativeFilePathIterator) {
230+
bool pathPartExists = false;
231+
232+
// Iterate over all entries in the path part's directory,
233+
// to check if the path part is in there case insensitively
234+
for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator(inspectedPath)) {
235+
if (StringsEqualCaseInsensitive(filesystemEntryPath.filename().generic_string(), relativeFilePathIterator->generic_string())) {
236+
inspectedPath = filesystemEntryPath;
237+
238+
// If the path part is found, stop looking for it
239+
pathPartExists = true;
240+
break;
241+
}
242+
}
243+
244+
if (!pathPartExists) {
245+
// If part of the path exists, append the rest of fullPath its parts
246+
while (relativeFilePathIterator != relativeFilePath.end()) {
247+
inspectedPath /= relativeFilePathIterator->generic_string();
248+
relativeFilePathIterator++;
249+
}
250+
break;
251+
}
252+
}
253+
254+
return inspectedPath.generic_string();
255+
}
221256
}

Source/System/RTETools.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ namespace RTE {
292292
/// <returns>Whether the two strings are equal case insensitively.</returns>
293293
inline bool StringsEqualCaseInsensitive(const std::string_view &strA, const std::string_view &strB) { return std::equal(strA.begin(), strA.end(), strB.begin(), strB.end(), [](char strAChar, char strBChar) { return std::tolower(strAChar) == std::tolower(strBChar); }); }
294294

295+
/// <summary>
296+
/// If a file "foo/Bar.txt" exists, and this method is passed "FOO/BAR.TXT", then this method will return "foo/Bar.txt".
297+
/// This method's purpose is to enable Linux to get the real path using a case-insensitive search.
298+
/// The real path is used by the Lua file I/O handling methods to ensure full Windows compatibility.
299+
/// </summary>
300+
/// <param name="fullPath">Path to case-insensitively translate to a real path.</param>
301+
/// <returns>The real path. If the path doesn't exist, it returns the fullPath argument with all the existing parent directories correctly capitalized.</returns>
302+
std::string GetCaseInsensitiveFullPath(const std::string &fullPath);
303+
295304
/// <summary>
296305
/// Hashes a string in a cross-compiler/platform safe way (std::hash gives different results on different compilers).
297306
/// </summary>

0 commit comments

Comments
 (0)