@@ -360,7 +360,7 @@ namespace RTE {
360
360
361
361
// TODO
362
362
// It would be nice to assign to least-saturated state, but that's a bit tricky with MO registering...
363
- /* auto itr = std::min_element(m_ScriptStates.begin(), m_ScriptStates.end(),
363
+ /* auto itr = std::min_element(m_ScriptStates.begin(), m_ScriptStates.end(),
364
364
[](const LuaStateWrapper& lhs, const LuaStateWrapper& rhs) { return lhs.GetRegisteredMOs().size() < rhs.GetRegisteredMOs().size(); }
365
365
);
366
366
@@ -375,7 +375,7 @@ namespace RTE {
375
375
bool success = m_ScriptStates[ourState].GetMutex ().try_lock ();
376
376
RTEAssert (success, " Script mutex was already locked while in a non-multithreaded environment!" );
377
377
378
- return &m_ScriptStates[ourState];
378
+ return &m_ScriptStates[ourState];
379
379
}
380
380
381
381
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -405,13 +405,13 @@ namespace RTE {
405
405
406
406
void LuaMan::ExecuteLuaScriptCallbacks () {
407
407
std::vector<std::function<void ()>> callbacks;
408
-
408
+
409
409
// Move our functions into the local buffer to clear the existing callbacks and to lock for as little time as possible
410
410
{
411
411
std::scoped_lock lock (m_ScriptCallbacksMutex);
412
412
callbacks.swap (m_ScriptCallbacks);
413
413
}
414
-
414
+
415
415
for (const std::function<void ()> &callback : callbacks) {
416
416
callback ();
417
417
}
@@ -871,7 +871,7 @@ namespace RTE {
871
871
872
872
bool LuaStateWrapper::TableEntryIsDefined (const std::string &tableName, const std::string &indexName) {
873
873
std::lock_guard<std::recursive_mutex> lock (m_Mutex);
874
-
874
+
875
875
// Push the table onto the stack, checking if it even exists.
876
876
lua_getglobal (m_State, tableName.c_str ());
877
877
if (!lua_istable (m_State, -1 )) {
@@ -937,6 +937,42 @@ namespace RTE {
937
937
return stackDescription.str ();
938
938
}
939
939
940
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
941
+
942
+ // TODO: Ask Causeless whether this is an appropriate spot for this method
943
+ std::optional<std::string> LuaMan::GetCaseInsensitiveFullPath (const std::string &fullPath) {
944
+ std::filesystem::path inspectedPath = System::GetWorkingDirectory ();
945
+ const std::filesystem::path relativeFilePath = std::filesystem::path (fullPath).lexically_relative (inspectedPath);
946
+
947
+ // Iterate over all path parts
948
+ for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin (); relativeFilePathIterator != relativeFilePath.end (); ++relativeFilePathIterator) {
949
+ bool pathPartExists = false ;
950
+
951
+ // Iterate over all entries in the path part's directory,
952
+ // to check if the path part is in there case insensitively
953
+ for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator (inspectedPath)) {
954
+ if (StringsEqualCaseInsensitive (filesystemEntryPath.filename ().generic_string (), relativeFilePathIterator->generic_string ())) {
955
+ inspectedPath = filesystemEntryPath;
956
+
957
+ // If the path part is found, stop looking for it
958
+ pathPartExists = true ;
959
+ break ;
960
+ }
961
+ }
962
+
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;
970
+ }
971
+ }
972
+
973
+ return std::optional<std::string>(inspectedPath.generic_string ());
974
+ }
975
+
940
976
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
941
977
942
978
const std::vector<std::string> * LuaMan::DirectoryList (const std::string &path) {
@@ -945,7 +981,7 @@ namespace RTE {
945
981
946
982
if (IsValidModulePath (fullPath)) {
947
983
#ifndef _WIN32
948
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
984
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
949
985
if (caseInsensitiveFullPath)
950
986
#endif
951
987
{
@@ -968,7 +1004,7 @@ namespace RTE {
968
1004
969
1005
if (IsValidModulePath (fullPath)) {
970
1006
#ifndef _WIN32
971
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
1007
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
972
1008
if (caseInsensitiveFullPath)
973
1009
#endif
974
1010
{
@@ -989,7 +1025,7 @@ namespace RTE {
989
1025
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
990
1026
if (IsValidModulePath (fullPath)) {
991
1027
#ifndef _WIN32
992
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
1028
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
993
1029
if (caseInsensitiveFullPath)
994
1030
#endif
995
1031
{
@@ -1008,7 +1044,7 @@ namespace RTE {
1008
1044
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1009
1045
if (IsValidModulePath (fullPath)) {
1010
1046
#ifndef _WIN32
1011
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
1047
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1012
1048
if (caseInsensitiveFullPath)
1013
1049
#endif
1014
1050
{
@@ -1030,35 +1066,6 @@ namespace RTE {
1030
1066
1031
1067
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1032
1068
1033
- // TODO: Move this shit to some other place
1034
- std::optional<std::string> GetCaseInsensitiveFullPath (const std::string &fullPath) {
1035
- std::filesystem::path inspectedPath = System::GetWorkingDirectory ();
1036
- const std::filesystem::path relativeFilePath = std::filesystem::path (fullPath).lexically_relative (inspectedPath);
1037
-
1038
- // Iterate over all path parts
1039
- for (std::filesystem::path::const_iterator relativeFilePathIterator = relativeFilePath.begin (); relativeFilePathIterator != relativeFilePath.end (); ++relativeFilePathIterator) {
1040
- bool pathPartExists = false ;
1041
-
1042
- // Iterate over all entries in the path part's directory,
1043
- // to check if the path part is in there case insensitively
1044
- for (const std::filesystem::path &filesystemEntryPath : std::filesystem::directory_iterator (inspectedPath)) {
1045
- if (StringsEqualCaseInsensitive (filesystemEntryPath.filename ().generic_string (), relativeFilePathIterator->generic_string ())) {
1046
- inspectedPath = filesystemEntryPath;
1047
-
1048
- // If the path part is found, stop looking for it
1049
- pathPartExists = true ;
1050
- break ;
1051
- }
1052
- }
1053
-
1054
- if (!pathPartExists) {
1055
- return std::nullopt;
1056
- }
1057
- }
1058
-
1059
- return std::optional<std::string>(inspectedPath.generic_string ());
1060
- }
1061
-
1062
1069
int LuaMan::FileOpen (const std::string &path, const std::string &accessMode) {
1063
1070
if (c_FileAccessModes.find (accessMode) == c_FileAccessModes.end ()) {
1064
1071
g_ConsoleMan.PrintString (" ERROR: Cannot open file, invalid file access mode specified." );
@@ -1149,7 +1156,7 @@ namespace RTE {
1149
1156
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1150
1157
if (IsValidModulePath (fullPath)) {
1151
1158
#ifndef _WIN32
1152
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
1159
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1153
1160
if (caseInsensitiveFullPath)
1154
1161
#endif
1155
1162
{
@@ -1173,47 +1180,39 @@ namespace RTE {
1173
1180
#ifndef _WIN32
1174
1181
// The goal here is to return the same fullPath,
1175
1182
// but with the parent directories given the real filesys casing
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
- }
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 ;
1194
1199
}
1200
+ }
1195
1201
1196
- if (!pathPartExists) {
1197
- // If part of the path exists, append the rest of fullPath its parts
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 ();
1198
1206
relativeFilePathIterator++;
1199
- while (relativeFilePathIterator != relativeFilePath.end ()) {
1200
- inspectedPath += " /" + relativeFilePathIterator->generic_string ();
1201
- relativeFilePathIterator++;
1202
- }
1203
-
1204
- return inspectedPath;
1205
1207
}
1208
+
1209
+ break ;
1206
1210
}
1211
+ }
1207
1212
1208
- // If the entire path exists
1209
- return inspectedPath;
1210
- }();
1211
- if (caseInsensitiveFullPath)
1213
+ fullPath = inspectedPath;
1212
1214
#endif
1213
1215
{
1214
- #ifndef _WIN32
1215
- fullPath = *caseInsensitiveFullPath;
1216
- #endif
1217
1216
try {
1218
1217
if (recursive) {
1219
1218
return std::filesystem::create_directories (fullPath);
@@ -1233,7 +1232,7 @@ namespace RTE {
1233
1232
std::string fullPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (path);
1234
1233
if (IsValidModulePath (fullPath)) {
1235
1234
#ifndef _WIN32
1236
- auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath)
1235
+ auto caseInsensitiveFullPath = GetCaseInsensitiveFullPath (fullPath);
1237
1236
if (caseInsensitiveFullPath)
1238
1237
#endif
1239
1238
{
@@ -1262,8 +1261,8 @@ namespace RTE {
1262
1261
std::string fullNewPath = System::GetWorkingDirectory () + g_PresetMan.GetFullModulePath (newPath);
1263
1262
if (IsValidModulePath (fullOldPath) && IsValidModulePath (fullNewPath)) {
1264
1263
#ifndef _WIN32
1265
- auto caseInsensitiveFullOldPath = GetCaseInsensitiveFullPath (fullOldPath)
1266
- auto caseInsensitiveFullNewPath = GetCaseInsensitiveFullPath (fullNewPath)
1264
+ auto caseInsensitiveFullOldPath = GetCaseInsensitiveFullPath (fullOldPath);
1265
+ auto caseInsensitiveFullNewPath = GetCaseInsensitiveFullPath (fullNewPath);
1267
1266
if (caseInsensitiveFullOldPath && caseInsensitiveFullNewPath)
1268
1267
#endif
1269
1268
{
@@ -1338,15 +1337,15 @@ namespace RTE {
1338
1337
1339
1338
void LuaMan::StartAsyncGarbageCollection () {
1340
1339
ZoneScoped;
1341
-
1340
+
1342
1341
std::vector<LuaStateWrapper*> allStates;
1343
1342
allStates.reserve (m_ScriptStates.size () + 1 );
1344
1343
1345
1344
allStates.push_back (&m_MasterScriptState);
1346
1345
for (LuaStateWrapper& wrapper : m_ScriptStates) {
1347
1346
allStates.push_back (&wrapper);
1348
1347
}
1349
-
1348
+
1350
1349
m_GarbageCollectionTask = BS::multi_future<void >();
1351
1350
for (LuaStateWrapper* luaState : allStates) {
1352
1351
m_GarbageCollectionTask.push_back (
0 commit comments