Codechange: Use directory_iterator to list directories in file list windows.

This replaces use of custom ttd_opendir. Files are listed separately using ScanPath as that handles downloaded content.
This commit is contained in:
Peter Nelson
2024-04-18 00:04:46 +01:00
committed by Peter Nelson
parent 5a523cf212
commit d7c547d0db
4 changed files with 33 additions and 67 deletions

View File

@@ -192,27 +192,15 @@ void FiosGetDrives(FileList &file_list)
}
}
bool FiosIsValidFile(const std::string &, const struct dirent *ent, struct stat *sb)
bool FiosIsHiddenFile(const std::filesystem::path &path)
{
/* hectonanoseconds between Windows and POSIX epoch */
static const int64_t posix_epoch_hns = 0x019DB1DED53E8000LL;
const WIN32_FIND_DATA *fd = &ent->dir->fd;
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // Disable 'no-disk' message box.
sb->st_size = ((uint64_t) fd->nFileSizeHigh << 32) + fd->nFileSizeLow;
/* UTC FILETIME to seconds-since-1970 UTC
* we just have to subtract POSIX epoch and scale down to units of seconds.
* http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1&#1860504
* XXX - not entirely correct, since filetimes on FAT aren't UTC but local,
* this won't entirely be correct, but we use the time only for comparison. */
sb->st_mtime = (time_t)((*(const uint64_t*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7);
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
DWORD attributes = GetFileAttributes(path.c_str());
return true;
}
SetErrorMode(sem); // Restore previous setting.
bool FiosIsHiddenFile(const struct dirent *ent)
{
return (ent->dir->fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
return (attributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
}
std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path)