-second function freed of std::filesystem.

This commit is contained in:
Christoph Oelckers 2020-01-03 17:34:52 +01:00
parent c82d6de6c3
commit 9f0b720b25
3 changed files with 56 additions and 18 deletions

View file

@ -522,6 +522,7 @@ void G_ReadConfig(const char* game)
void G_SaveConfig() void G_SaveConfig()
{ {
if (!GameConfig) return;
GameConfig->ArchiveGlobalData(); GameConfig->ArchiveGlobalData();
GameConfig->ArchiveGameData(GameName); GameConfig->ArchiveGameData(GameName);
GameConfig->WriteConfigFile(); GameConfig->WriteConfigFile();

View file

@ -463,11 +463,15 @@ void CollectSubdirectories(TArray<FString> &searchpath, const char *dirmatch)
{ {
do do
{ {
if (!(I_FindAttr(&findstate) & FA_DIREC)) if (I_FindAttr(&findstate) & FA_DIREC)
{ {
FStringf fullpath("%s/%s", AbsPath.GetChars(), I_FindName(&findstate)); auto p = I_FindName(&findstate);
if (strcmp(p, ".") && strcmp(p, ".."))
{
FStringf fullpath("%s/%s", AbsPath.GetChars(), p);
searchpath.Push(fullpath); searchpath.Push(fullpath);
} }
}
} while (I_FindNext(handle, &findstate) == 0); } while (I_FindNext(handle, &findstate) == 0);
I_FindClose(handle); I_FindClose(handle);
} }
@ -538,8 +542,8 @@ TArray<FString> CollectSearchPaths()
struct FileEntry struct FileEntry
{ {
FString FileName; FString FileName;
uintmax_t FileLength; size_t FileLength;
uint64_t FileTime; time_t FileTime;
uint32_t CRCValue; uint32_t CRCValue;
uint32_t Index; uint32_t Index;
}; };
@ -563,20 +567,25 @@ TArray<FileEntry> CollectAllFilesInSearchPath()
auto paths = CollectSearchPaths(); auto paths = CollectSearchPaths();
for(auto &path : paths) for(auto &path : paths)
{ {
auto fpath = fs::u8path(path.GetChars()); if (DirExists(path))
if (fs::exists(fpath) && fs::is_directory(fpath))
{ {
for (const auto& entry : fs::directory_iterator(fpath)) findstate_t findstate;
void* handle;
if ((handle = I_FindFirst(path + "/*.*", &findstate)) != (void*)-1)
{ {
if (fs::is_regular_file(entry.status())) do
{ {
if (!(I_FindAttr(&findstate) & FA_DIREC))
{
auto p = I_FindName(&findstate);
filelist.Reserve(1); filelist.Reserve(1);
auto& flentry = filelist.Last(); auto& flentry = filelist.Last();
flentry.FileName = absolute(entry.path()).u8string().c_str(); flentry.FileName.Format("%s/%s", path.GetChars(), p);
flentry.FileLength = entry.file_size(); GetFileInfo(flentry.FileName, &flentry.FileLength, &flentry.FileTime);
flentry.FileTime = entry.last_write_time().time_since_epoch().count();
flentry.Index = index++; // to preserve order when working on the list. flentry.Index = index++; // to preserve order when working on the list.
} }
} while (I_FindNext(handle, &findstate) == 0);
I_FindClose(handle);
} }
} }
} }

View file

@ -125,13 +125,41 @@ bool DirEntryExists(const char *pathname, bool *isdir)
#else #else
// Windows must use the wide version of stat to preserve non-standard paths. // Windows must use the wide version of stat to preserve non-standard paths.
auto wstr = WideString(pathname); auto wstr = WideString(pathname);
struct _stat64i32 info; struct _stat64 info;
bool res = _wstat64i32(wstr.c_str(), &info) == 0; bool res = _wstat64(wstr.c_str(), &info) == 0;
#endif #endif
if (isdir) *isdir = !!(info.st_mode & S_IFDIR); if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
return res; return res;
} }
//==========================================================================
//
// DirEntryExists
//
// Returns true if the given path exists, be it a directory or a file.
//
//==========================================================================
bool GetFileInfo(const char* pathname, size_t *size, time_t *time)
{
if (pathname == NULL || *pathname == 0)
return false;
#ifndef _WIN32
struct stat info;
bool res = stat(pathname, &info) == 0;
#else
// Windows must use the wide version of stat to preserve non-standard paths.
auto wstr = WideString(pathname);
struct _stat64 info;
bool res = _wstat64(wstr.c_str(), &info) == 0;
#endif
if (!res || (info.st_mode & S_IFDIR)) return false;
if (size) *size = info.st_size;
if (time) *time = info.st_mtime;
return res;
}
//========================================================================== //==========================================================================
// //
// DefaultExtension -- FString version // DefaultExtension -- FString version