@@ -940,7 +940,7 @@ namespace RTE {
940
940
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
941
941
942
942
// TODO: Ask Causeless whether this is an appropriate spot for this method
943
- std::optional<std:: string> LuaMan::GetCaseInsensitiveFullPath (const std::string &fullPath) {
943
+ std::string LuaMan::GetCaseInsensitiveFullPath (const std::string &fullPath) {
944
944
std::filesystem::path inspectedPath = System::GetWorkingDirectory ();
945
945
const std::filesystem::path relativeFilePath = std::filesystem::path (fullPath).lexically_relative (inspectedPath);
946
946
@@ -961,16 +961,16 @@ namespace RTE {
961
961
}
962
962
963
963
if (!pathPartExists) {
964
- // TODO: This should return the same thing DirectoryCreate() does,
965
- // where it just appends the rest of fullPath.
966
- // This way it's the responsibility of the caller to use std::filestem::exists(),
967
- // which allows DirectoryCreate() and Rename() to call this function too,
968
- // since they allow the fullPath and newPath argument to not exist yet.
969
- return NOTasdstd::nullopt ;
964
+ // If part of the path exists, append the rest of fullPath its parts
965
+ while (relativeFilePathIterator != relativeFilePath. end ()) {
966
+ inspectedPath /= relativeFilePathIterator-> generic_string ();
967
+ relativeFilePathIterator++;
968
+ }
969
+ break ;
970
970
}
971
971
}
972
972
973
- return std::optional<std::string>( inspectedPath.generic_string () );
973
+ return inspectedPath.generic_string ();
974
974
}
975
975
976
976
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -981,13 +981,10 @@ namespace RTE {
981
981
982
982
if (IsValidModulePath (fullPath)) {
983
983
#ifndef _WIN32
984
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
985
- if (caseInsensitiveFullPath)
984
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
986
985
#endif
986
+ if (std::filesystem::exists (fullPath))
987
987
{
988
- #ifndef _WIN32
989
- fullPath = *caseInsensitiveFullPath;
990
- #endif
991
988
for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath)) {
992
989
if (directoryEntry.is_directory ()) { directoryPaths->emplace_back (directoryEntry.path ().filename ().generic_string ()); }
993
990
}
@@ -1004,13 +1001,10 @@ namespace RTE {
1004
1001
1005
1002
if (IsValidModulePath (fullPath)) {
1006
1003
#ifndef _WIN32
1007
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1008
- if (caseInsensitiveFullPath)
1004
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1009
1005
#endif
1006
+ if (std::filesystem::exists (fullPath))
1010
1007
{
1011
- #ifndef _WIN32
1012
- fullPath = *caseInsensitiveFullPath;
1013
- #endif
1014
1008
for (const std::filesystem::directory_entry &directoryEntry : std::filesystem::directory_iterator (fullPath)) {
1015
1009
if (directoryEntry.is_regular_file ()) { filePaths->emplace_back (directoryEntry.path ().filename ().generic_string ()); }
1016
1010
}
@@ -1025,15 +1019,9 @@ namespace RTE {
1025
1019
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1026
1020
if (IsValidModulePath (fullPath)) {
1027
1021
#ifndef _WIN32
1028
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1029
- if (caseInsensitiveFullPath)
1022
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1030
1023
#endif
1031
- {
1032
- #ifndef _WIN32
1033
- fullPath = *caseInsensitiveFullPath;
1034
- #endif
1035
- return std::filesystem::is_regular_file (fullPath);
1036
- }
1024
+ return std::filesystem::is_regular_file (fullPath);
1037
1025
}
1038
1026
return false ;
1039
1027
}
@@ -1044,15 +1032,9 @@ namespace RTE {
1044
1032
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1045
1033
if (IsValidModulePath (fullPath)) {
1046
1034
#ifndef _WIN32
1047
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1048
- if (caseInsensitiveFullPath)
1049
- #endif
1050
- {
1051
- #ifndef _WIN32
1052
- fullPath = *caseInsensitiveFullPath;
1035
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1053
1036
#endif
1054
- return std::filesystem::is_directory (fullPath);
1055
- }
1037
+ return std::filesystem::is_directory (fullPath);
1056
1038
}
1057
1039
return false ;
1058
1040
}
@@ -1156,16 +1138,10 @@ namespace RTE {
1156
1138
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1157
1139
if (IsValidModulePath (fullPath)) {
1158
1140
#ifndef _WIN32
1159
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1160
- if (caseInsensitiveFullPath)
1161
- #endif
1162
- {
1163
- #ifndef _WIN32
1164
- fullPath = *caseInsensitiveFullPath;
1141
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1165
1142
#endif
1166
- if (std::filesystem::is_regular_file (fullPath)) {
1167
- return std::filesystem::remove (fullPath);
1168
- }
1143
+ if (std::filesystem::is_regular_file (fullPath)) {
1144
+ return std::filesystem::remove (fullPath);
1169
1145
}
1170
1146
}
1171
1147
g_ConsoleMan.PrintString (" ERROR: Failed to remove file " + path);
@@ -1178,49 +1154,15 @@ namespace RTE {
1178
1154
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1179
1155
if (IsValidModulePath (fullPath)) {
1180
1156
#ifndef _WIN32
1181
- // The goal here is to return the same fullPath,
1182
- // but with the parent directories given the real filesys casing
1183
- std::filesystem::path inspectedPath = System::GetWorkingDirectory ();
1184
- const std::filesystem::path relativeFilePath = std::filesystem::path (fullPath).lexically_relative (inspectedPath);
1185
-
1186
- // Iterate over all path parts
1187
- for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin (); relativeFilePathIterator != relativeFilePath.end (); ++relativeFilePathIterator) {
1188
- bool pathPartExists = false ;
1189
-
1190
- // Iterate over all entries in the path part's directory,
1191
- // to check if the path part is in there case insensitively
1192
- for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator (inspectedPath)) {
1193
- if (StringsEqualCaseInsensitive (filesystemEntryPath.filename ().generic_string (), relativeFilePathIterator->generic_string ())) {
1194
- inspectedPath = filesystemEntryPath;
1195
-
1196
- // If the path part is found, stop looking for it
1197
- pathPartExists = true ;
1198
- break ;
1199
- }
1200
- }
1201
-
1202
- if (!pathPartExists) {
1203
- // If part of the path exists, append the rest of fullPath its parts
1204
- while (relativeFilePathIterator != relativeFilePath.end ()) {
1205
- inspectedPath /= relativeFilePathIterator->generic_string ();
1206
- relativeFilePathIterator++;
1207
- }
1208
-
1209
- break ;
1210
- }
1211
- }
1212
-
1213
- fullPath = inspectedPath;
1157
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1214
1158
#endif
1215
- {
1216
- try {
1217
- if (recursive) {
1218
- return std::filesystem::create_directories (fullPath);
1219
- } else {
1220
- return std::filesystem::create_directory (fullPath);
1221
- }
1222
- } catch (const std::filesystem::filesystem_error &e) {}
1223
- }
1159
+ try {
1160
+ if (recursive) {
1161
+ return std::filesystem::create_directories (fullPath);
1162
+ } else {
1163
+ return std::filesystem::create_directory (fullPath);
1164
+ }
1165
+ } catch (const std::filesystem::filesystem_error &e) {}
1224
1166
}
1225
1167
g_ConsoleMan.PrintString (" ERROR: Failed to remove directory " + path);
1226
1168
return false ;
@@ -1232,22 +1174,16 @@ namespace RTE {
1232
1174
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1233
1175
if (IsValidModulePath (fullPath)) {
1234
1176
#ifndef _WIN32
1235
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1236
- if (caseInsensitiveFullPath)
1237
- #endif
1238
- {
1239
- #ifndef _WIN32
1240
- fullPath = *caseInsensitiveFullPath;
1177
+ fullPath = GetCaseInsensitiveFullPath (fullPath);
1241
1178
#endif
1242
- if (std::filesystem::is_directory (fullPath)) {
1243
- try {
1244
- if (recursive) {
1245
- return std::filesystem::remove_all (fullPath) > 0 ;
1246
- } else {
1247
- return std::filesystem::remove (fullPath);
1248
- }
1249
- } catch (const std::filesystem::filesystem_error &e) {}
1250
- }
1179
+ if (std::filesystem::is_directory (fullPath)) {
1180
+ try {
1181
+ if (recursive) {
1182
+ return std::filesystem::remove_all (fullPath) > 0 ;
1183
+ } else {
1184
+ return std::filesystem::remove (fullPath);
1185
+ }
1186
+ } catch (const std::filesystem::filesystem_error &e) {}
1251
1187
}
1252
1188
}
1253
1189
g_ConsoleMan.PrintString (" ERROR: Failed to remove directory " + path);
@@ -1261,20 +1197,13 @@ namespace RTE {
1261
1197
std::string fullNewPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (newPath);
1262
1198
if (IsValidModulePath (fullOldPath) && IsValidModulePath (fullNewPath)) {
1263
1199
#ifndef _WIN32
1264
- auto caseInsensitiveFullOldPath = GetCaseInsensitiveFullPath (fullOldPath);
1265
- auto caseInsensitiveFullNewPath = GetCaseInsensitiveFullPath (fullNewPath);
1266
- if (caseInsensitiveFullOldPath && caseInsensitiveFullNewPath)
1200
+ fullOldPath = GetCaseInsensitiveFullPath (fullOldPath);
1201
+ fullNewPath = GetCaseInsensitiveFullPath (fullNewPath);
1267
1202
#endif
1268
- {
1269
- #ifndef _WIN32
1270
- fullOldPath = *caseInsensitiveFullOldPath;
1271
- fullNewPath = *caseInsensitiveFullNewPath;
1272
- #endif
1273
- try {
1274
- std::filesystem::rename (fullOldPath, fullNewPath);
1275
- return true ;
1276
- } catch (const std::filesystem::filesystem_error &e) {}
1277
- }
1203
+ try {
1204
+ std::filesystem::rename (fullOldPath, fullNewPath);
1205
+ return true ;
1206
+ } catch (const std::filesystem::filesystem_error &e) {}
1278
1207
}
1279
1208
g_ConsoleMan.PrintString (" ERROR: Failed to rename oldPath " + oldPath + " to newPath " + newPath);
1280
1209
return false ;
0 commit comments