summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fios.cpp6
-rw-r--r--src/os2.cpp8
-rw-r--r--src/unix.cpp7
-rw-r--r--src/win32.cpp6
4 files changed, 20 insertions, 7 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index b2956f9ad..e1a738d8e 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -33,6 +33,7 @@ static int _fios_count, _fios_alloc;
/* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
extern bool FiosIsRoot(const char *path);
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
+extern bool FiosIsHiddenFile(const struct dirent *ent);
extern void FiosGetDrives(void);
extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot);
@@ -227,7 +228,8 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
/* found file must be directory, but not '.' or '..' */
if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
- strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
+ (!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
+ strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
fios = FiosAlloc();
fios->type = FIOS_TYPE_DIR;
fios->mtime = 0;
@@ -258,7 +260,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
char *t;
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
- if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue;
+ if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue;
/* File has no extension, skip it */
if ((t = strrchr(d_name, '.')) == NULL) continue;
diff --git a/src/os2.cpp b/src/os2.cpp
index 88ca2fddf..7443e6896 100644
--- a/src/os2.cpp
+++ b/src/os2.cpp
@@ -114,11 +114,15 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
char filename[MAX_PATH];
snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
- if (stat(filename, sb) != 0) return false;
+ return stat(filename, sb) == 0;
+}
- return (ent->d_name[0] != '.'); // hidden file
+bool FiosIsHiddenFile(const struct dirent *ent)
+{
+ return ent->d_name[0] == '.';
}
+
static void ChangeWorkingDirectory(char *exe)
{
char *s = strrchr(exe, PATHSEPCHAR);
diff --git a/src/unix.cpp b/src/unix.cpp
index 68b96ee39..d4b3899ba 100644
--- a/src/unix.cpp
+++ b/src/unix.cpp
@@ -92,9 +92,12 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
#endif
snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
- if (stat(filename, sb) != 0) return false;
+ return stat(filename, sb) == 0;
+}
- return (ent->d_name[0] != '.'); // hidden file
+bool FiosIsHiddenFile(const struct dirent *ent)
+{
+ return ent->d_name[0] == '.';
}
#if defined(__BEOS__) || defined(__linux__)
diff --git a/src/win32.cpp b/src/win32.cpp
index e6a4f6a27..032196d32 100644
--- a/src/win32.cpp
+++ b/src/win32.cpp
@@ -749,7 +749,6 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
// hectonanoseconds between Windows and POSIX epoch
static const int64 posix_epoch_hns = 0x019DB1DED53E8000LL;
const WIN32_FIND_DATAW *fd = &ent->dir->fd;
- if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false;
sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow;
/* UTC FILETIME to seconds-since-1970 UTC
@@ -763,6 +762,11 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
return true;
}
+bool FiosIsHiddenFile(const struct dirent *ent)
+{
+ return (ent->dir->fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
+}
+
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
{
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box