From f25c7ef2d519f98f7acd64cfa01c03d3b7781384 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 13:17:28 +0200 Subject: [PATCH] =?UTF-8?q?Unified=20implementation=20of=20=E2=80=99direct?= =?UTF-8?q?ory=20as=20resource=20file'=20for=20POSIX=20targets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resourcefiles/file_directory.cpp | 75 ++++++++-------------------- 1 file changed, 20 insertions(+), 55 deletions(-) diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 77e5d0141..2e5630169 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -35,27 +35,13 @@ #include -#include #ifdef _WIN32 #include -#define stat _stat #else -#include -#ifndef __sun #include #endif -#endif -#include -#include -#include -#include -#include -#include -#include "doomtype.h" -#include "tarray.h" #include "resourcefile.h" -#include "zstring.h" #include "cmdlib.h" #include "doomerrors.h" @@ -185,46 +171,6 @@ int FDirectory::AddDirectory(const char *dirpath) return count; } -#elif defined(__sun) || defined(__APPLE__) - -int FDirectory::AddDirectory(const char *dirpath) -{ - int count = 0; - TArray scanDirectories; - scanDirectories.Push(dirpath); - for(unsigned int i = 0;i < scanDirectories.Size();i++) - { - DIR* directory = opendir(scanDirectories[i].GetChars()); - if (directory == NULL) - { - Printf("Could not read directory: %s\n", strerror(errno)); - return 0; - } - - struct dirent *file; - while((file = readdir(directory)) != NULL) - { - if(file->d_name[0] == '.') //File is hidden or ./.. directory so ignore it. - continue; - - FString fullFileName = scanDirectories[i] + file->d_name; - - struct stat fileStat; - stat(fullFileName.GetChars(), &fileStat); - - if(S_ISDIR(fileStat.st_mode)) - { - scanDirectories.Push(scanDirectories[i] + file->d_name + "/"); - continue; - } - AddEntry(scanDirectories[i] + file->d_name, fileStat.st_size); - count++; - } - closedir(directory); - } - return count; -} - #else //========================================================================== @@ -249,6 +195,10 @@ int FDirectory::AddDirectory(const char *dirpath) Printf("Failed to start directory traversal: %s\n", strerror(errno)); return 0; } + + const size_t namepos = strlen(Filename); + FString pathfix; + while ((ent = fts_read(fts)) != NULL) { if (ent->fts_info == FTS_D && ent->fts_name[0] == '.') @@ -266,7 +216,22 @@ int FDirectory::AddDirectory(const char *dirpath) // We're only interested in remembering files. continue; } - AddEntry(ent->fts_path, ent->fts_statp->st_size); + + // Some implementations add an extra separator between + // root of the hierarchy and entity's path. + // It needs to be removed in order to resolve + // lumps' relative paths properly. + const char* path = ent->fts_path; + + if ('/' == path[namepos]) + { + pathfix = FString(path, namepos); + pathfix.AppendCStrPart(&path[namepos + 1], ent->fts_pathlen - namepos - 1); + + path = pathfix.GetChars(); + } + + AddEntry(path, ent->fts_statp->st_size); count++; } fts_close(fts);