From 587fba0b683ee23149f8634c868d95c07cbe60fb Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 29 Mar 2017 17:19:54 +0100 Subject: [PATCH] Rename DirectoryFile/FileProperty to Path, and re-use struct in OS code * They describe directories or files, and really describe a single path on the remote system. --- qrenderdoc/Code/RenderManager.cpp | 6 +- .../Windows/Dialogs/VirtualFileDialog.cpp | 58 +++++++++---------- renderdoc/api/replay/data_types.h | 8 ++- renderdoc/api/replay/renderdoc_replay.h | 2 +- renderdoc/api/replay/replay_enums.h | 4 +- renderdoc/core/remote_server.cpp | 38 +++++------- renderdoc/os/os_specific.h | 13 +---- renderdoc/os/posix/posix_stringio.cpp | 22 +++---- renderdoc/os/win32/win32_stringio.cpp | 24 ++++---- 9 files changed, 77 insertions(+), 98 deletions(-) diff --git a/qrenderdoc/Code/RenderManager.cpp b/qrenderdoc/Code/RenderManager.cpp index bdb6406d7..11bdc47ed 100644 --- a/qrenderdoc/Code/RenderManager.cpp +++ b/qrenderdoc/Code/RenderManager.cpp @@ -108,7 +108,7 @@ void RenderManager::GetHomeFolder(bool synchronous, DirectoryBrowseMethod cb) if(IsRunning() && m_Thread->isCurrentThread()) { auto lambda = [cb, this](IReplayRenderer *r) { - cb(m_Remote->GetHomeFolder().c_str(), rdctype::array()); + cb(m_Remote->GetHomeFolder().c_str(), rdctype::array()); }; if(synchronous) @@ -125,7 +125,7 @@ void RenderManager::GetHomeFolder(bool synchronous, DirectoryBrowseMethod cb) home = m_Remote->GetHomeFolder(); } - cb(home.c_str(), rdctype::array()); + cb(home.c_str(), rdctype::array()); } bool RenderManager::ListFolder(QString path, bool synchronous, DirectoryBrowseMethod cb) @@ -148,7 +148,7 @@ bool RenderManager::ListFolder(QString path, bool synchronous, DirectoryBrowseMe return true; } - rdctype::array contents; + rdctype::array contents; // prevent pings while fetching remote FS data { diff --git a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp index 1aa82d5f9..83b2e34ec 100644 --- a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp @@ -55,7 +55,7 @@ public: makeIconStates(exeIcon, Pixmaps::page_white_code()); makeIconStates(dirIcon, Pixmaps::folder_page()); - Renderer.GetHomeFolder(true, [this](const char *path, const rdctype::array &files) { + Renderer.GetHomeFolder(true, [this](const char *path, const rdctype::array &files) { QString homeDir = QString::fromUtf8(path); if(QChar(path[0]).isLetter() && path[1] == ':') @@ -64,7 +64,7 @@ public: // NT paths Renderer.ListFolder( - "/", true, [this, homeDir](const char *path, const rdctype::array &files) { + "/", true, [this, homeDir](const char *path, const rdctype::array &files) { for(int i = 0; i < files.count; i++) { FSNode *node = new FSNode(); @@ -85,7 +85,7 @@ public: node->parent = NULL; node->parentIndex = 0; node->file.filename = "/"; - node->file.flags = FileProperty::Directory; + node->file.flags = PathProperty::Directory; roots.push_back(node); home = indexForPath(homeDir); @@ -236,11 +236,11 @@ public: return ret; // if it's not a dir, there are no children - if(getNode(index)->file.flags & FileProperty::Directory) + if(getNode(index)->file.flags & PathProperty::Directory) ret &= ~Qt::ItemNeverHasChildren; // if we can't populate it, set it as disabled - if(getNode(index)->file.flags & FileProperty::ErrorAccessDenied) + if(getNode(index)->file.flags & PathProperty::ErrorAccessDenied) ret &= ~Qt::ItemIsEnabled; return ret; @@ -306,15 +306,15 @@ public: } case 1: { - if(node->file.flags & FileProperty::Directory) + if(node->file.flags & PathProperty::Directory) return QVariant(); return qulonglong(node->file.size); } case 2: { - if(node->file.flags & FileProperty::Directory) + if(node->file.flags & PathProperty::Directory) return tr("Directory"); - else if(node->file.flags & FileProperty::Executable) + else if(node->file.flags & PathProperty::Executable) return tr("Executable file"); else return tr("File"); @@ -332,11 +332,11 @@ public: case Qt::DecorationRole: if(index.column() == 0) { - int hideIndex = (node->file.flags & FileProperty::Hidden) ? 1 : 0; + int hideIndex = (node->file.flags & PathProperty::Hidden) ? 1 : 0; - if(node->file.flags & FileProperty::Directory) + if(node->file.flags & PathProperty::Directory) return dirIcon[hideIndex]; - else if(node->file.flags & FileProperty::Executable) + else if(node->file.flags & PathProperty::Executable) return exeIcon[hideIndex]; else return fileIcon[hideIndex]; @@ -345,12 +345,12 @@ public: if(index.column() == 1) return Qt::AlignRight; break; - case FileIsDirRole: return bool(node->file.flags & FileProperty::Directory); - case FileIsHiddenRole: return bool(node->file.flags & FileProperty::Hidden); - case FileIsExecutableRole: return bool(node->file.flags & FileProperty::Executable); + case FileIsDirRole: return bool(node->file.flags & PathProperty::Directory); + case FileIsHiddenRole: return bool(node->file.flags & PathProperty::Hidden); + case FileIsExecutableRole: return bool(node->file.flags & PathProperty::Executable); case FileIsRootRole: return roots.contains(node); case FileIsAccessDeniedRole: - return bool(node->file.flags & FileProperty::ErrorAccessDenied); + return bool(node->file.flags & PathProperty::ErrorAccessDenied); case FilePathRole: return makePath(node); case FileNameRole: return ToQStr(node->file.filename); default: break; @@ -400,7 +400,7 @@ private: bool populated = false; - DirectoryFile file; + PathEntry file; QList children; }; @@ -444,32 +444,30 @@ private: node->populated = true; // nothing to do for non-directories - if(!(node->file.flags & FileProperty::Directory)) + if(!(node->file.flags & PathProperty::Directory)) return; Renderer.ListFolder( - makePath(node), true, - [this, node](const char *path, const rdctype::array &files) { + makePath(node), true, [this, node](const char *path, const rdctype::array &files) { - if(files.count == 1 && (files[0].flags & FileProperty::ErrorAccessDenied)) + if(files.count == 1 && (files[0].flags & PathProperty::ErrorAccessDenied)) { - node->file.flags |= FileProperty::ErrorAccessDenied; + node->file.flags |= PathProperty::ErrorAccessDenied; return; } - QVector sortedFiles; + QVector sortedFiles; sortedFiles.reserve(files.count); - for(const DirectoryFile &f : files) + for(const PathEntry &f : files) sortedFiles.push_back(f); - qSort(sortedFiles.begin(), sortedFiles.end(), - [](const DirectoryFile &a, const DirectoryFile &b) { - // sort greater than so that files with the flag are sorted before those without - if((a.flags & FileProperty::Directory) != (b.flags & FileProperty::Directory)) - return (a.flags & FileProperty::Directory) > (b.flags & FileProperty::Directory); + qSort(sortedFiles.begin(), sortedFiles.end(), [](const PathEntry &a, const PathEntry &b) { + // sort greater than so that files with the flag are sorted before those without + if((a.flags & PathProperty::Directory) != (b.flags & PathProperty::Directory)) + return (a.flags & PathProperty::Directory) > (b.flags & PathProperty::Directory); - return strcmp(a.filename.c_str(), b.filename.c_str()) < 0; - }); + return strcmp(a.filename.c_str(), b.filename.c_str()) < 0; + }); for(int i = 0; i < sortedFiles.count(); i++) { diff --git a/renderdoc/api/replay/data_types.h b/renderdoc/api/replay/data_types.h index bb7fdddb5..4dd4b3708 100644 --- a/renderdoc/api/replay/data_types.h +++ b/renderdoc/api/replay/data_types.h @@ -36,15 +36,17 @@ struct FloatVector DECLARE_REFLECTION_STRUCT(FloatVector); -struct DirectoryFile +struct PathEntry { + PathEntry() : flags(PathProperty::NoFlags), lastmod(0), size(0) {} + PathEntry(const char *fn, PathProperty f) : filename(fn), flags(f), lastmod(0), size(0) {} rdctype::str filename; - FileProperty flags; + PathProperty flags; uint32_t lastmod; uint64_t size; }; -DECLARE_REFLECTION_STRUCT(DirectoryFile); +DECLARE_REFLECTION_STRUCT(PathEntry); struct ResourceFormat { diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index b997d09ff..961e9df5a 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -296,7 +296,7 @@ struct IRemoteServer virtual bool RemoteSupportedReplays(rdctype::array *out) = 0; virtual rdctype::str GetHomeFolder() = 0; - virtual rdctype::array ListFolder(const char *path) = 0; + virtual rdctype::array ListFolder(const char *path) = 0; virtual uint32_t ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, void *env, const CaptureOptions *opts) = 0; diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index ad2b61845..9b8712259 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -163,7 +163,7 @@ inline enum_name operator++(enum_name &a) \ #define ENUM_ARRAY_SIZE(enum_name) size_t(enum_name::Count) -enum class FileProperty : uint32_t +enum class PathProperty : uint32_t { NoFlags = 0x0, Directory = 0x1, @@ -175,7 +175,7 @@ enum class FileProperty : uint32_t ErrorInvalidPath = 0x8000, }; -BITMASK_OPERATORS(FileProperty); +BITMASK_OPERATORS(PathProperty); // replay_shader.h diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index 3930831a0..b9f729094 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -37,7 +37,7 @@ using std::pair; template <> -string ToStrHelper::Get(const FileProperty &el) +string ToStrHelper::Get(const PathProperty &el) { return "<...>"; } @@ -49,7 +49,7 @@ string ToStrHelper::Get(const CaptureOptions &el) } template <> -void Serialiser::Serialise(const char *name, DirectoryFile &el) +void Serialiser::Serialise(const char *name, PathEntry &el) { ScopedContext scope(this, name, "DirectoryFile", 0, true); @@ -296,20 +296,9 @@ static void ActiveRemoteClientThread(void *data) sendType = eRemoteServer_ListDir; - vector files = FileIO::GetFilesInDirectory(path.c_str()); + std::vector files = FileIO::GetFilesInDirectory(path.c_str()); - uint32_t count = (uint32_t)files.size(); - sendSer.Serialise("", count); - - for(uint32_t i = 0; i < count; i++) - { - DirectoryFile df; - df.filename = files[i].filename; - df.lastmod = files[i].lastmod; - df.size = files[i].size; - df.flags = files[i].flags; - sendSer.Serialise("", df); - } + sendSer.Serialise("", files); } else if(type == eRemoteServer_CopyCaptureFromRemote) { @@ -842,9 +831,9 @@ public: return ret; } - rdctype::array ListFolder(const char *path) + rdctype::array ListFolder(const char *path) { - rdctype::array ret; + rdctype::array ret; if(Android::IsHostADB(m_hostname.c_str())) { @@ -852,18 +841,18 @@ public: using namespace std; istringstream stdoutStream(adbStdout); string line; - vector packages; + vector packages; while(getline(stdoutStream, line)) { vector tokens; split(line, tokens, ':'); if(tokens.size() == 2 && tokens[0] == "package") { - DirectoryFile package; + PathEntry package; package.filename = trim(tokens[1]); package.size = 0; package.lastmod = 0; - package.flags = FileProperty::Executable; + package.flags = PathProperty::Executable; packages.push_back(package); } } @@ -901,7 +890,7 @@ public: { create_array_uninit(ret, 1); ret.elems[0].filename = path; - ret.elems[0].flags = FileProperty::ErrorUnknown; + ret.elems[0].flags = PathProperty::ErrorUnknown; } return ret; @@ -1175,10 +1164,11 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RemoteServer_GetHomeFolder(IRemoteSer *home = path; } -extern "C" RENDERDOC_API void RENDERDOC_CC RemoteServer_ListFolder( - IRemoteServer *remote, const char *path, rdctype::array *dirlist) +extern "C" RENDERDOC_API void RENDERDOC_CC RemoteServer_ListFolder(IRemoteServer *remote, + const char *path, + rdctype::array *dirlist) { - rdctype::array files = remote->ListFolder(path); + rdctype::array files = remote->ListFolder(path); if(dirlist) *dirlist = files; } diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index 2d2c280e1..9f53e8b78 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -256,18 +256,7 @@ uint64_t GetModifiedTimestamp(const string &filename); void Copy(const char *from, const char *to, bool allowOverwrite); void Delete(const char *path); - -struct FoundFile -{ - FoundFile() : flags(FileProperty::NoFlags) {} - FoundFile(string fn, FileProperty f) : filename(fn), flags(f), lastmod(0), size(0) {} - string filename; - FileProperty flags; - uint32_t lastmod; - uint64_t size; -}; - -vector GetFilesInDirectory(const char *path); +std::vector GetFilesInDirectory(const char *path); FILE *fopen(const char *filename, const char *mode); diff --git a/renderdoc/os/posix/posix_stringio.cpp b/renderdoc/os/posix/posix_stringio.cpp index ad250eac6..83332eb78 100644 --- a/renderdoc/os/posix/posix_stringio.cpp +++ b/renderdoc/os/posix/posix_stringio.cpp @@ -251,22 +251,22 @@ void Delete(const char *path) unlink(path); } -vector GetFilesInDirectory(const char *path) +std::vector GetFilesInDirectory(const char *path) { - vector ret; + std::vector ret; DIR *d = opendir(path); if(d == NULL) { - FileProperty flags = FileProperty::ErrorUnknown; + PathProperty flags = PathProperty::ErrorUnknown; if(errno == ENOENT) - flags = FileProperty::ErrorInvalidPath; + flags = PathProperty::ErrorInvalidPath; else if(errno == EACCES) - flags = FileProperty::ErrorAccessDenied; + flags = PathProperty::ErrorAccessDenied; - ret.push_back(FoundFile(path, flags)); + ret.push_back(PathEntry(path, flags)); return ret; } @@ -294,18 +294,18 @@ vector GetFilesInDirectory(const char *path) if(res != 0) continue; - FileProperty flags = FileProperty::NoFlags; + PathProperty flags = PathProperty::NoFlags; // make directory/executable mutually exclusive for clarity's sake if(S_ISDIR(st.st_mode)) - flags |= FileProperty::Directory; + flags |= PathProperty::Directory; else if(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) - flags |= FileProperty::Executable; + flags |= PathProperty::Executable; if(ent->d_name[0] == '.') - flags |= FileProperty::Hidden; + flags |= PathProperty::Hidden; - FoundFile f(ent->d_name, flags); + PathEntry f(ent->d_name, flags); f.lastmod = (uint32_t)st.st_mtime; f.size = (uint64_t)st.st_size; diff --git a/renderdoc/os/win32/win32_stringio.cpp b/renderdoc/os/win32/win32_stringio.cpp index 864acc62d..ee24dabfd 100644 --- a/renderdoc/os/win32/win32_stringio.cpp +++ b/renderdoc/os/win32/win32_stringio.cpp @@ -347,9 +347,9 @@ void Delete(const char *path) ::DeleteFileW(wpath.c_str()); } -vector GetFilesInDirectory(const char *path) +std::vector GetFilesInDirectory(const char *path) { - vector ret; + std::vector ret; if(path[0] == '/' && path[1] == 0) { @@ -364,7 +364,7 @@ vector GetFilesInDirectory(const char *path) string fn = "A:/"; fn[0] = char('A' + i); - ret.push_back(FoundFile(fn, FileProperty::Directory)); + ret.push_back(PathEntry(fn.c_str(), PathProperty::Directory)); } } @@ -394,14 +394,14 @@ vector GetFilesInDirectory(const char *path) { DWORD err = GetLastError(); - FileProperty flags = FileProperty::ErrorUnknown; + PathProperty flags = PathProperty::ErrorUnknown; if(err == ERROR_FILE_NOT_FOUND) - flags = FileProperty::ErrorInvalidPath; + flags = PathProperty::ErrorInvalidPath; else if(err == ERROR_ACCESS_DENIED) - flags = FileProperty::ErrorAccessDenied; + flags = PathProperty::ErrorAccessDenied; - ret.push_back(FoundFile(path, flags)); + ret.push_back(PathEntry(path, flags)); return ret; } @@ -418,21 +418,21 @@ vector GetFilesInDirectory(const char *path) } else { - FileProperty flags = FileProperty::NoFlags; + PathProperty flags = PathProperty::NoFlags; if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - flags |= FileProperty::Directory; + flags |= PathProperty::Directory; if(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - flags |= FileProperty::Hidden; + flags |= PathProperty::Hidden; if(wcsstr(findData.cFileName, L".EXE") || wcsstr(findData.cFileName, L".exe") || wcsstr(findData.cFileName, L".Exe")) { - flags |= FileProperty::Executable; + flags |= PathProperty::Executable; } - FoundFile f(StringFormat::Wide2UTF8(findData.cFileName), flags); + PathEntry f(StringFormat::Wide2UTF8(findData.cFileName).c_str(), flags); uint64_t nanosecondsSinceWindowsEpoch = uint64_t(findData.ftLastWriteTime.dwHighDateTime) << 8 | uint64_t(findData.ftLastWriteTime.dwLowDateTime);