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.
This commit is contained in:
baldurk
2017-03-29 17:19:54 +01:00
parent 637d4089e2
commit 587fba0b68
9 changed files with 77 additions and 98 deletions
+3 -3
View File
@@ -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<DirectoryFile>());
cb(m_Remote->GetHomeFolder().c_str(), rdctype::array<PathEntry>());
};
if(synchronous)
@@ -125,7 +125,7 @@ void RenderManager::GetHomeFolder(bool synchronous, DirectoryBrowseMethod cb)
home = m_Remote->GetHomeFolder();
}
cb(home.c_str(), rdctype::array<DirectoryFile>());
cb(home.c_str(), rdctype::array<PathEntry>());
}
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<DirectoryFile> contents;
rdctype::array<PathEntry> contents;
// prevent pings while fetching remote FS data
{
@@ -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<DirectoryFile> &files) {
Renderer.GetHomeFolder(true, [this](const char *path, const rdctype::array<PathEntry> &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<DirectoryFile> &files) {
"/", true, [this, homeDir](const char *path, const rdctype::array<PathEntry> &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<FSNode *> 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<DirectoryFile> &files) {
makePath(node), true, [this, node](const char *path, const rdctype::array<PathEntry> &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<DirectoryFile> sortedFiles;
QVector<PathEntry> 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++)
{
+5 -3
View File
@@ -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
{
+1 -1
View File
@@ -296,7 +296,7 @@ struct IRemoteServer
virtual bool RemoteSupportedReplays(rdctype::array<rdctype::str> *out) = 0;
virtual rdctype::str GetHomeFolder() = 0;
virtual rdctype::array<DirectoryFile> ListFolder(const char *path) = 0;
virtual rdctype::array<PathEntry> ListFolder(const char *path) = 0;
virtual uint32_t ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine,
void *env, const CaptureOptions *opts) = 0;
+2 -2
View File
@@ -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
+14 -24
View File
@@ -37,7 +37,7 @@
using std::pair;
template <>
string ToStrHelper<false, FileProperty>::Get(const FileProperty &el)
string ToStrHelper<false, PathProperty>::Get(const PathProperty &el)
{
return "<...>";
}
@@ -49,7 +49,7 @@ string ToStrHelper<false, CaptureOptions>::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<FileIO::FoundFile> files = FileIO::GetFilesInDirectory(path.c_str());
std::vector<PathEntry> 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<DirectoryFile> ListFolder(const char *path)
rdctype::array<PathEntry> ListFolder(const char *path)
{
rdctype::array<DirectoryFile> ret;
rdctype::array<PathEntry> ret;
if(Android::IsHostADB(m_hostname.c_str()))
{
@@ -852,18 +841,18 @@ public:
using namespace std;
istringstream stdoutStream(adbStdout);
string line;
vector<DirectoryFile> packages;
vector<PathEntry> packages;
while(getline(stdoutStream, line))
{
vector<string> 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<DirectoryFile> *dirlist)
extern "C" RENDERDOC_API void RENDERDOC_CC RemoteServer_ListFolder(IRemoteServer *remote,
const char *path,
rdctype::array<PathEntry> *dirlist)
{
rdctype::array<DirectoryFile> files = remote->ListFolder(path);
rdctype::array<PathEntry> files = remote->ListFolder(path);
if(dirlist)
*dirlist = files;
}
+1 -12
View File
@@ -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<FoundFile> GetFilesInDirectory(const char *path);
std::vector<PathEntry> GetFilesInDirectory(const char *path);
FILE *fopen(const char *filename, const char *mode);
+11 -11
View File
@@ -251,22 +251,22 @@ void Delete(const char *path)
unlink(path);
}
vector<FoundFile> GetFilesInDirectory(const char *path)
std::vector<PathEntry> GetFilesInDirectory(const char *path)
{
vector<FoundFile> ret;
std::vector<PathEntry> 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<FoundFile> 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;
+12 -12
View File
@@ -347,9 +347,9 @@ void Delete(const char *path)
::DeleteFileW(wpath.c_str());
}
vector<FoundFile> GetFilesInDirectory(const char *path)
std::vector<PathEntry> GetFilesInDirectory(const char *path)
{
vector<FoundFile> ret;
std::vector<PathEntry> ret;
if(path[0] == '/' && path[1] == 0)
{
@@ -364,7 +364,7 @@ vector<FoundFile> 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<FoundFile> 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<FoundFile> 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);