mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 14:52:01 +00:00
-second function freed of std::filesystem.
This commit is contained in:
parent
c82d6de6c3
commit
9f0b720b25
3 changed files with 56 additions and 18 deletions
|
@ -522,6 +522,7 @@ void G_ReadConfig(const char* game)
|
|||
|
||||
void G_SaveConfig()
|
||||
{
|
||||
if (!GameConfig) return;
|
||||
GameConfig->ArchiveGlobalData();
|
||||
GameConfig->ArchiveGameData(GameName);
|
||||
GameConfig->WriteConfigFile();
|
||||
|
|
|
@ -463,10 +463,14 @@ void CollectSubdirectories(TArray<FString> &searchpath, const char *dirmatch)
|
|||
{
|
||||
do
|
||||
{
|
||||
if (!(I_FindAttr(&findstate) & FA_DIREC))
|
||||
if (I_FindAttr(&findstate) & FA_DIREC)
|
||||
{
|
||||
FStringf fullpath("%s/%s", AbsPath.GetChars(), I_FindName(&findstate));
|
||||
searchpath.Push(fullpath);
|
||||
auto p = I_FindName(&findstate);
|
||||
if (strcmp(p, ".") && strcmp(p, ".."))
|
||||
{
|
||||
FStringf fullpath("%s/%s", AbsPath.GetChars(), p);
|
||||
searchpath.Push(fullpath);
|
||||
}
|
||||
}
|
||||
} while (I_FindNext(handle, &findstate) == 0);
|
||||
I_FindClose(handle);
|
||||
|
@ -538,8 +542,8 @@ TArray<FString> CollectSearchPaths()
|
|||
struct FileEntry
|
||||
{
|
||||
FString FileName;
|
||||
uintmax_t FileLength;
|
||||
uint64_t FileTime;
|
||||
size_t FileLength;
|
||||
time_t FileTime;
|
||||
uint32_t CRCValue;
|
||||
uint32_t Index;
|
||||
};
|
||||
|
@ -563,20 +567,25 @@ TArray<FileEntry> CollectAllFilesInSearchPath()
|
|||
auto paths = CollectSearchPaths();
|
||||
for(auto &path : paths)
|
||||
{
|
||||
auto fpath = fs::u8path(path.GetChars());
|
||||
if (fs::exists(fpath) && fs::is_directory(fpath))
|
||||
if (DirExists(path))
|
||||
{
|
||||
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
|
||||
{
|
||||
filelist.Reserve(1);
|
||||
auto& flentry = filelist.Last();
|
||||
flentry.FileName = absolute(entry.path()).u8string().c_str();
|
||||
flentry.FileLength = entry.file_size();
|
||||
flentry.FileTime = entry.last_write_time().time_since_epoch().count();
|
||||
flentry.Index = index++; // to preserve order when working on the list.
|
||||
}
|
||||
if (!(I_FindAttr(&findstate) & FA_DIREC))
|
||||
{
|
||||
auto p = I_FindName(&findstate);
|
||||
filelist.Reserve(1);
|
||||
auto& flentry = filelist.Last();
|
||||
flentry.FileName.Format("%s/%s", path.GetChars(), p);
|
||||
GetFileInfo(flentry.FileName, &flentry.FileLength, &flentry.FileTime);
|
||||
flentry.Index = index++; // to preserve order when working on the list.
|
||||
}
|
||||
} while (I_FindNext(handle, &findstate) == 0);
|
||||
I_FindClose(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,13 +125,41 @@ bool DirEntryExists(const char *pathname, bool *isdir)
|
|||
#else
|
||||
// Windows must use the wide version of stat to preserve non-standard paths.
|
||||
auto wstr = WideString(pathname);
|
||||
struct _stat64i32 info;
|
||||
bool res = _wstat64i32(wstr.c_str(), &info) == 0;
|
||||
struct _stat64 info;
|
||||
bool res = _wstat64(wstr.c_str(), &info) == 0;
|
||||
#endif
|
||||
if (isdir) *isdir = !!(info.st_mode & S_IFDIR);
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue