From ada7306e1a50bdce0939c48b072502ac32a05ff8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 31 Jul 2015 22:24:37 +0200 Subject: [PATCH] Expand capture pathnames to full before passing over remote access * This fixes the issue where an application might have set the capture path as relative, and a relative path is passed to the UI which has no idea what working directory the path is relative to. --- renderdoc/core/remote_access.cpp | 4 +++- renderdoc/os/linux/linux_stringio.cpp | 14 +++++++++++--- renderdoc/os/os_specific.h | 6 ++++-- renderdoc/os/win32/win32_stringio.cpp | 16 +++++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/renderdoc/core/remote_access.cpp b/renderdoc/core/remote_access.cpp index 057269cb1..81c18ad59 100644 --- a/renderdoc/core/remote_access.cpp +++ b/renderdoc/core/remote_access.cpp @@ -120,9 +120,11 @@ void RenderDoc::RemoteAccessClientThread(void *s) packetType = ePacket_NewCapture; + std::string path = FileIO::GetFullPathname(captures.back().path); + ser.Serialise("", idx); ser.Serialise("", captures.back().timestamp); - ser.Serialise("", captures.back().path); + ser.Serialise("", path); uint32_t len = 0; RENDERDOC_GetThumbnail(captures.back().path.c_str(), NULL, len); diff --git a/renderdoc/os/linux/linux_stringio.cpp b/renderdoc/os/linux/linux_stringio.cpp index 822236890..184058e9b 100644 --- a/renderdoc/os/linux/linux_stringio.cpp +++ b/renderdoc/os/linux/linux_stringio.cpp @@ -133,7 +133,7 @@ namespace Keyboard namespace FileIO { - string GetAppFolderFilename(string filename) + string GetAppFolderFilename(const string &filename) { passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; @@ -145,6 +145,14 @@ namespace FileIO return ret + filename; } + string GetFullPathname(const string &filename) + { + char path[512] = {0}; + readlink(filename.c_str(), path, 511); + + return string(path); + } + void GetExecutableFilename(string &selfName) { char path[512] = {0}; @@ -238,10 +246,10 @@ namespace FileIO logging_filename = string(temp_filename); } - uint64_t GetModifiedTimestamp(const char *filename) + uint64_t GetModifiedTimestamp(const string &filename) { struct ::stat st; - int res = stat(filename, &st); + int res = stat(filename.c_str(), &st); if(res == 0) { diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index 754da391a..7b0fc563f 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -174,12 +174,14 @@ namespace Callstack namespace FileIO { void GetDefaultFiles(const char *logBaseName, string &capture_filename, string &logging_filename, string &target); - string GetAppFolderFilename(string filename); + string GetAppFolderFilename(const string &filename); string GetReplayAppFilename(); + string GetFullPathname(const string &filename); + void GetExecutableFilename(string &selfName); - uint64_t GetModifiedTimestamp(const char *filename); + uint64_t GetModifiedTimestamp(const string &filename); void Copy(const char *from, const char *to, bool allowOverwrite); void Delete(const char *path); diff --git a/renderdoc/os/win32/win32_stringio.cpp b/renderdoc/os/win32/win32_stringio.cpp index f0f809a75..436f9c585 100644 --- a/renderdoc/os/win32/win32_stringio.cpp +++ b/renderdoc/os/win32/win32_stringio.cpp @@ -160,6 +160,16 @@ namespace FileIO selfName = StringFormat::Wide2UTF8(wstring(curFile)); } + string GetFullPathname(const string &filename) + { + wstring wfn = StringFormat::UTF82Wide(filename); + + wchar_t path[512] = {0}; + GetFullPathNameW(wfn.c_str(), ARRAY_COUNT(path)-1, path, NULL); + + return StringFormat::Wide2UTF8(wstring(path)); + } + string GetReplayAppFilename() { HMODULE hModule = NULL; @@ -251,7 +261,7 @@ namespace FileIO logging_filename = StringFormat::Wide2UTF8(wstring(temp_filename)); } - string GetAppFolderFilename(string filename) + string GetAppFolderFilename(const string &filename) { PWSTR appDataPath; SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_SIMPLE_IDLIST|KF_FLAG_DONT_UNEXPAND, NULL, &appDataPath); @@ -268,9 +278,9 @@ namespace FileIO return ret; } - uint64_t GetModifiedTimestamp(const char *filename) + uint64_t GetModifiedTimestamp(const string &filename) { - wstring wfn = StringFormat::UTF82Wide(string(filename)); + wstring wfn = StringFormat::UTF82Wide(filename); struct _stat st; int res = _wstat(wfn.c_str(), &st);