From 17926738641f651256496c9ebac6e157e5abf51b Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 18 Feb 2018 20:34:59 +0000 Subject: [PATCH] Show an error message if saving changes fails --- qrenderdoc/Code/CaptureContext.cpp | 27 +++++++++++++------- qrenderdoc/Code/CaptureContext.h | 6 ++--- renderdoc/api/replay/renderdoc_replay.h | 4 ++- renderdoc/core/remote_server.cpp | 34 +++++++++++++++++++++++-- renderdoc/replay/capture_file.cpp | 8 +++--- 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/qrenderdoc/Code/CaptureContext.cpp b/qrenderdoc/Code/CaptureContext.cpp index 3b70a787a..62c4acbe9 100644 --- a/qrenderdoc/Code/CaptureContext.cpp +++ b/qrenderdoc/Code/CaptureContext.cpp @@ -1107,19 +1107,28 @@ void CaptureContext::RemoveBookmark(uint32_t EID) void CaptureContext::SaveChanges() { + bool success = true; + if(m_CaptureMods & CaptureModifications::Renames) - SaveRenames(); + success &= SaveRenames(); if(m_CaptureMods & CaptureModifications::Bookmarks) - SaveBookmarks(); + success &= SaveBookmarks(); if(m_CaptureMods & CaptureModifications::Notes) - SaveNotes(); + success &= SaveNotes(); + + if(!success) + { + RDDialog::critical(m_MainWindow, tr("Can't save file"), + tr("Error saving file.\n" + "Check for permissions and that it's not open elsewhere")); + } m_CaptureMods = CaptureModifications::NoModifications; } -void CaptureContext::SaveRenames() +bool CaptureContext::SaveRenames() { QVariantMap resources; for(ResourceId id : m_CustomNames.keys()) @@ -1136,7 +1145,7 @@ void CaptureContext::SaveRenames() props.type = SectionType::ResourceRenames; props.version = 1; - Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); + return Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); } void CaptureContext::LoadRenames(const QString &data) @@ -1167,7 +1176,7 @@ void CaptureContext::LoadRenames(const QString &data) } } -void CaptureContext::SaveBookmarks() +bool CaptureContext::SaveBookmarks() { QVariantList bookmarks; for(const EventBookmark &mark : m_Bookmarks) @@ -1188,7 +1197,7 @@ void CaptureContext::SaveBookmarks() props.type = SectionType::Bookmarks; props.version = 1; - Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); + return Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); } void CaptureContext::LoadBookmarks(const QString &data) @@ -1213,7 +1222,7 @@ void CaptureContext::LoadBookmarks(const QString &data) } } -void CaptureContext::SaveNotes() +bool CaptureContext::SaveNotes() { QVariantMap root; for(const QString &key : m_Notes.keys()) @@ -1227,7 +1236,7 @@ void CaptureContext::SaveNotes() ANALYTIC_SET(UIFeatures.CaptureComments, true); - Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); + return Replay().GetCaptureAccess()->WriteSection(props, json.toUtf8()); } void CaptureContext::LoadNotes(const QString &data) diff --git a/qrenderdoc/Code/CaptureContext.h b/qrenderdoc/Code/CaptureContext.h index eee127fb3..06b5bbdd6 100644 --- a/qrenderdoc/Code/CaptureContext.h +++ b/qrenderdoc/Code/CaptureContext.h @@ -270,13 +270,13 @@ private: void SaveChanges(); - void SaveRenames(); + bool SaveRenames(); void LoadRenames(const QString &data); - void SaveBookmarks(); + bool SaveBookmarks(); void LoadBookmarks(const QString &data); - void SaveNotes(); + bool SaveNotes(); void LoadNotes(const QString &data); void CacheResources(); diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 957edc542..959a33921 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -1273,8 +1273,10 @@ or name). :param SectionProperties props: The properties of the section to be written. :param bytes contents: The raw contents of the section. +:return: ``True`` if the section was written successfully, ``False`` otherwise. +:rtype: ``bool`` )"); - virtual void WriteSection(const SectionProperties &props, const bytebuf &contents) = 0; + virtual bool WriteSection(const SectionProperties &props, const bytebuf &contents) = 0; DOCUMENT(R"(Query if callstacks are available. diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index d8f2efc20..a46f5522d 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -695,6 +695,8 @@ static void ActiveRemoteClientThread(ClientThread *threadData, reader.EndChunk(); + bool success = false; + if(rdc) { StreamWriter *sectionWriter = rdc->WriteSection(props); @@ -703,8 +705,16 @@ static void ActiveRemoteClientThread(ClientThread *threadData, { sectionWriter->Write(contents.data(), contents.size()); delete sectionWriter; + + success = true; } } + + { + WRITE_DATA_SCOPE(); + SCOPED_SERIALISE_CHUNK(eRemoteServer_WriteSection); + SERIALISE_ELEMENT(success); + } } else if(type == eRemoteServer_CloseLog) { @@ -1640,10 +1650,10 @@ public: return contents; } - void WriteSection(const SectionProperties &props, const bytebuf &contents) + bool WriteSection(const SectionProperties &props, const bytebuf &contents) { if(!Connected()) - return; + return false; { WRITE_DATA_SCOPE(); @@ -1651,6 +1661,26 @@ public: SERIALISE_ELEMENT(props); SERIALISE_ELEMENT(contents); } + + bool success = false; + + { + READ_DATA_SCOPE(); + RemoteServerPacket type = ser.ReadChunk(); + + if(type == eRemoteServer_WriteSection) + { + SERIALISE_ELEMENT(success); + } + else + { + RDCERR("Unexpected response to has write section request"); + } + + ser.EndChunk(); + } + + return success; } bool HasCallstacks() diff --git a/renderdoc/replay/capture_file.cpp b/renderdoc/replay/capture_file.cpp index 49f64ec1b..6e4d2a68a 100644 --- a/renderdoc/replay/capture_file.cpp +++ b/renderdoc/replay/capture_file.cpp @@ -167,7 +167,7 @@ public: int FindSectionByType(SectionType type); SectionProperties GetSectionProperties(int index); bytebuf GetSectionContents(int index); - void WriteSection(const SectionProperties &props, const bytebuf &contents); + bool WriteSection(const SectionProperties &props, const bytebuf &contents); bool HasCallstacks(); bool InitResolver(RENDERDOC_ProgressCallback progress); @@ -715,17 +715,19 @@ bytebuf CaptureFile::GetSectionContents(int index) return ret; } -void CaptureFile::WriteSection(const SectionProperties &props, const bytebuf &contents) +bool CaptureFile::WriteSection(const SectionProperties &props, const bytebuf &contents) { StreamWriter *writer = m_RDC->WriteSection(props); if(!writer) - return; + return false; writer->Write(contents.data(), contents.size()); writer->Finish(); delete writer; + + return true; } bool CaptureFile::HasCallstacks()