diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 6cdbe2d20..4df0ad34a 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- -#include #include "gamecontrol.h" #include "tarray.h" #include "zstring.h" diff --git a/source/common/i_specialpaths.h b/source/common/i_specialpaths.h index e8929a048..44596165a 100644 --- a/source/common/i_specialpaths.h +++ b/source/common/i_specialpaths.h @@ -13,6 +13,7 @@ FString M_GetSavegamesPath(); FString M_GetDocumentsPath(); FString M_GetDemoPath(); +FString M_GetNormalizedPath(const char* path); #ifdef __APPLE__ FString M_GetMacAppSupportPath(const bool create = true); diff --git a/source/common/searchpaths.cpp b/source/common/searchpaths.cpp index bcfaf3463..066265668 100644 --- a/source/common/searchpaths.cpp +++ b/source/common/searchpaths.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include "m_crc32.h" #include "i_specialpaths.h" +#include "i_system.h" #include "compat.h" #include "gameconfigfile.h" #include "cmdlib.h" @@ -451,28 +452,26 @@ void G_AddExternalSearchPaths(TArray &searchpaths) void CollectSubdirectories(TArray &searchpath, const char *dirmatch) { - try + FString dirpath = MakeUTF8(dirmatch); // convert into clean UTF-8 + dirpath.Truncate(dirpath.Len() - 2); // remove the '/*' + FString AbsPath = M_GetNormalizedPath(dirpath); + if (DirExists(AbsPath)) { - FString dirpath = MakeUTF8(dirmatch); // convert into clean UTF-8 - dirpath.Truncate(dirpath.Len() - 2); // remove the '/*' - fs::path path = AbsolutePath(dirpath.GetChars()); - if (fs::exists(path) && fs::is_directory(path)) + findstate_t findstate; + void* handle; + if ((handle = I_FindFirst(AbsPath + "/*.*", &findstate)) != (void*)-1) { - for (const auto& entry : fs::directory_iterator(path)) + do { - if (fs::is_directory(entry.status())) + if (!(I_FindAttr(&findstate) & FA_DIREC)) { - FString newdir = absolute(entry.path()).u8string().c_str(); - if (searchpath.Find(newdir) == searchpath.Size()) - searchpath.Push(newdir); + FStringf fullpath("%s/%s", AbsPath.GetChars(), I_FindName(&findstate)); + searchpath.Push(fullpath); } - } + } while (I_FindNext(handle, &findstate) == 0); + I_FindClose(handle); } } - catch (fs::filesystem_error &) - { - // Just ignore this path if it caused an error. - } } //========================================================================== diff --git a/source/platform/macos/i_specialpaths.mm b/source/platform/macos/i_specialpaths.mm index 59179f400..ea321b167 100644 --- a/source/platform/macos/i_specialpaths.mm +++ b/source/platform/macos/i_specialpaths.mm @@ -220,3 +220,23 @@ FString M_GetDocumentsPath() return path; } + + +//=========================================================================== +// +// M_NormalizedPath +// +// Normalizes the given path and returns the result. +// +//=========================================================================== + +FString M_GetNormalizedPath(const char* path) +{ + NSString *str = [NSString stringWithUTF8String:path]; + NSString *out; + if ([str completePathIntoString:&out caseSensitive:NO matchesIntoArray:nil filterTypes:nil]) + { + return out.UTF8String; + } + return path; +} diff --git a/source/platform/win32/i_specialpaths.cpp b/source/platform/win32/i_specialpaths.cpp index a64cb03fc..1834bf868 100644 --- a/source/platform/win32/i_specialpaths.cpp +++ b/source/platform/win32/i_specialpaths.cpp @@ -382,3 +382,21 @@ FString M_GetDemoPath() CreatePath(path); return path; } + +//=========================================================================== +// +// M_NormalizedPath +// +// Normalizes the given path and returns the result. +// +//=========================================================================== + +FString M_GetNormalizedPath(const char* path) +{ + std::wstring wpath = WideString(path); + wchar_t buffer[MAX_PATH]; + GetFullPathNameW(wpath.c_str(), MAX_PATH, buffer, nullptr); + FString result(buffer); + FixPathSeperator(result); + return result; +}