Show an error message if saving changes fails

This commit is contained in:
baldurk
2018-02-18 20:34:59 +00:00
parent 1b5e96f363
commit 1792673864
5 changed files with 61 additions and 18 deletions
+18 -9
View File
@@ -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)
+3 -3
View File
@@ -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();
+3 -1
View File
@@ -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.
+32 -2
View File
@@ -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<RemoteServerPacket>();
if(type == eRemoteServer_WriteSection)
{
SERIALISE_ELEMENT(success);
}
else
{
RDCERR("Unexpected response to has write section request");
}
ser.EndChunk();
}
return success;
}
bool HasCallstacks()
+5 -3
View File
@@ -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()