- getting rid of std::filesystem, part one.

Since it's not usable on macOS it needs to go.
This commit is contained in:
Christoph Oelckers 2020-01-03 14:19:52 +01:00
parent 6a4870e7fb
commit 78e7b2dd8c
5 changed files with 53 additions and 16 deletions

View file

@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include <filesystem>
#include "gamecontrol.h"
#include "tarray.h"
#include "zstring.h"

View file

@ -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);

View file

@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <filesystem>
#include "m_crc32.h"
#include "i_specialpaths.h"
#include "i_system.h"
#include "compat.h"
#include "gameconfigfile.h"
#include "cmdlib.h"
@ -451,27 +452,25 @@ void G_AddExternalSearchPaths(TArray<FString> &searchpaths)
void CollectSubdirectories(TArray<FString> &searchpath, const char *dirmatch)
{
try
{
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))
FString AbsPath = M_GetNormalizedPath(dirpath);
if (DirExists(AbsPath))
{
for (const auto& entry : fs::directory_iterator(path))
findstate_t findstate;
void* handle;
if ((handle = I_FindFirst(AbsPath + "/*.*", &findstate)) != (void*)-1)
{
if (fs::is_directory(entry.status()))
do
{
FString newdir = absolute(entry.path()).u8string().c_str();
if (searchpath.Find(newdir) == searchpath.Size())
searchpath.Push(newdir);
}
}
}
}
catch (fs::filesystem_error &)
if (!(I_FindAttr(&findstate) & FA_DIREC))
{
// Just ignore this path if it caused an error.
FStringf fullpath("%s/%s", AbsPath.GetChars(), I_FindName(&findstate));
searchpath.Push(fullpath);
}
} while (I_FindNext(handle, &findstate) == 0);
I_FindClose(handle);
}
}
}

View file

@ -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;
}

View file

@ -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;
}