diff options
| author | Glenn Smith <glenn@vector35.com> | 2023-05-30 19:53:03 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2023-06-08 17:18:30 -0400 |
| commit | 1509435163893916647427200437885127141494 (patch) | |
| tree | 769f54599dcaa07f8088f7b4a191d6c8f7196ffe /filemetadata.cpp | |
| parent | 0882343191078862361937493035030128230878 (diff) | |
Undo transactions / context manager
Diffstat (limited to 'filemetadata.cpp')
| -rw-r--r-- | filemetadata.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/filemetadata.cpp b/filemetadata.cpp index 4f75129e..318da70d 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -270,9 +270,33 @@ bool FileMetadata::CreateSnapshotedView(BinaryView* data, const std::string& vie } -std::string FileMetadata::BeginUndoActions() +bool FileMetadata::RunUndoableTransaction(std::function<bool()> func) { - char* id = BNBeginUndoActions(m_object); + auto undo = BeginUndoActions(false); + try + { + bool result = func(); + if (result) + { + CommitUndoActions(undo); + } + else + { + RevertUndoActions(undo); + } + return result; + } + catch (...) + { + RevertUndoActions(undo); + throw; + } +} + + +std::string FileMetadata::BeginUndoActions(bool anonymousAllowed) +{ + char* id = BNBeginUndoActions(m_object, anonymousAllowed); std::string result = id; BNFreeString(id); return result; |
