@@ -952,7 +952,7 @@ namespace RTE {
952
952
#ifndef _WIN32
953
953
fullPath = *caseInsensitiveFullPath;
954
954
#endif
955
- for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath) {
955
+ for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath)) {
956
956
if (directoryEntry.is_directory ()) { directoryPaths->emplace_back (directoryEntry.path ().filename ().generic_string ()); }
957
957
}
958
958
}
@@ -975,7 +975,7 @@ namespace RTE {
975
975
#ifndef _WIN32
976
976
fullPath = *caseInsensitiveFullPath;
977
977
#endif
978
- for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath) {
978
+ for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath)) {
979
979
if (directoryEntry.is_regular_file ()) { filePaths->emplace_back (directoryEntry.path ().filename ().generic_string ()); }
980
980
}
981
981
}
@@ -1056,7 +1056,7 @@ namespace RTE {
1056
1056
}
1057
1057
}
1058
1058
1059
- return std::optional<std::string>(inspectedPath);
1059
+ return std::optional<std::string>(inspectedPath. generic_string () );
1060
1060
}
1061
1061
1062
1062
int LuaMan::FileOpen (const std::string &path, const std::string &accessMode) {
@@ -1171,46 +1171,42 @@ namespace RTE {
1171
1171
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1172
1172
if (IsValidModulePath (fullPath)) {
1173
1173
#ifndef _WIN32
1174
- // TODO: The goal here is to return the same fullPath,
1174
+ // The goal here is to return the same fullPath,
1175
1175
// but with the parent directories given the real filesys casing
1176
- //
1177
- // 1. There is no way for this lambda to fail
1178
- // 1. Account for the `recursive` argument of this fn
1179
- // 2. Let a lambda true if a parent directory has to be created,
1180
- // since create_directory() will return false for us in that case
1181
- auto caseInsensitiveFullPath = [&fullPath]() -> auto {
1182
- // std::filesystem::path inspectedPath = System::GetWorkingDirectory();
1183
- // const std::filesystem::path relativeFilePath = std::filesystem::path(fullPath).lexically_relative(inspectedPath);
1184
-
1185
- // // Iterate over all path parts
1186
- // for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin(); relativeFilePathIterator != relativeFilePath.end(); ++relativeFilePathIterator) {
1187
- // bool pathPartExists = false;
1188
-
1189
- // // Iterate over all entries in the path part's directory,
1190
- // // to check if the path part is in there case insensitively
1191
- // for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator(inspectedPath)) {
1192
- // if (StringsEqualCaseInsensitive(filesystemEntryPath.filename().generic_string(), relativeFilePathIterator->generic_string())) {
1193
- // inspectedPath = filesystemEntryPath;
1194
-
1195
- // // If the path part is found, stop looking for it
1196
- // pathPartExists = true;
1197
- // break;
1198
- // }
1199
- // }
1200
-
1201
- // if (!pathPartExists) {
1202
- // // If this is the last part, then all directories in relativeFilePath exist, but the file doesn't
1203
- // if (std::next(relativeFilePathIterator) == relativeFilePath.end()) {
1204
- // return fopen((inspectedPath / relativeFilePath.filename()).generic_string().c_str(), accessMode.c_str());
1205
- // }
1206
-
1207
- // // Some directory in relativeFilePath doesn't exist, so the file can't be created
1208
- // return nullptr;
1209
- // }
1210
- // }
1211
-
1212
- // // If the file exists, open it
1213
- // return fopen(inspectedPath.generic_string().c_str(), accessMode.c_str());
1176
+ std::string caseInsensitiveFullPath = [&fullPath]() -> std::string {
1177
+ std::filesystem::path inspectedPath = System::GetWorkingDirectory ();
1178
+ const std::filesystem::path relativeFilePath = std::filesystem::path (fullPath).lexically_relative (inspectedPath);
1179
+
1180
+ // Iterate over all path parts
1181
+ for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin (); relativeFilePathIterator != relativeFilePath.end (); ++relativeFilePathIterator) {
1182
+ bool pathPartExists = false ;
1183
+
1184
+ // Iterate over all entries in the path part's directory,
1185
+ // to check if the path part is in there case insensitively
1186
+ for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator (inspectedPath)) {
1187
+ if (StringsEqualCaseInsensitive (filesystemEntryPath.filename ().generic_string (), relativeFilePathIterator->generic_string ())) {
1188
+ inspectedPath = filesystemEntryPath;
1189
+
1190
+ // If the path part is found, stop looking for it
1191
+ pathPartExists = true ;
1192
+ break ;
1193
+ }
1194
+ }
1195
+
1196
+ if (!pathPartExists) {
1197
+ // If part of the path exists, append the rest of fullPath its parts
1198
+ relativeFilePathIterator++;
1199
+ while (relativeFilePathIterator != relativeFilePath.end ()) {
1200
+ inspectedPath += " /" + relativeFilePathIterator->generic_string ();
1201
+ relativeFilePathIterator++;
1202
+ }
1203
+
1204
+ return inspectedPath;
1205
+ }
1206
+ }
1207
+
1208
+ // If the entire path exists
1209
+ return inspectedPath;
1214
1210
}();
1215
1211
if (caseInsensitiveFullPath)
1216
1212
#endif
0 commit comments