mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-11 18:50:46 +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()
|
void G_SaveConfig()
|
||||||
{
|
{
|
||||||
|
if (!GameConfig) return;
|
||||||
GameConfig->ArchiveGlobalData();
|
GameConfig->ArchiveGlobalData();
|
||||||
GameConfig->ArchiveGameData(GameName);
|
GameConfig->ArchiveGameData(GameName);
|
||||||
GameConfig->WriteConfigFile();
|
GameConfig->WriteConfigFile();
|
||||||
|
|
|
@ -463,10 +463,14 @@ 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);
|
||||||
searchpath.Push(fullpath);
|
if (strcmp(p, ".") && strcmp(p, ".."))
|
||||||
|
{
|
||||||
|
FStringf fullpath("%s/%s", AbsPath.GetChars(), p);
|
||||||
|
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
|
||||||
{
|
{
|
||||||
filelist.Reserve(1);
|
if (!(I_FindAttr(&findstate) & FA_DIREC))
|
||||||
auto& flentry = filelist.Last();
|
{
|
||||||
flentry.FileName = absolute(entry.path()).u8string().c_str();
|
auto p = I_FindName(&findstate);
|
||||||
flentry.FileLength = entry.file_size();
|
filelist.Reserve(1);
|
||||||
flentry.FileTime = entry.last_write_time().time_since_epoch().count();
|
auto& flentry = filelist.Last();
|
||||||
flentry.Index = index++; // to preserve order when working on the list.
|
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
|
#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
|
||||||
|
|
Loading…
Reference in a new issue