From de5c1a5154ca2c150aa3b70e66f1664d86f323de Mon Sep 17 00:00:00 2001 From: billow Date: Sun, 10 Apr 2022 11:43:42 +0800 Subject: [PATCH] Convert from Rizin commands to the API for `w` (#2926) --- src/common/IOModesController.cpp | 2 +- src/core/Cutter.cpp | 13 +++++++++++-- src/core/Cutter.h | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/common/IOModesController.cpp b/src/common/IOModesController.cpp index 88378c10..26f0801f 100644 --- a/src/common/IOModesController.cpp +++ b/src/common/IOModesController.cpp @@ -100,7 +100,7 @@ bool IOModesController::askCommitUnsavedChanges() if (ret == QMessageBox::Save) { Core()->commitWriteCache(); } else if (ret == QMessageBox::Discard) { - Core()->cmdRaw("wcr"); + Core()->resetWriteCache(); emit Core()->refreshCodeViews(); } else if (ret == QMessageBox::Cancel) { return false; diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index b11c5ebf..bd801a0e 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -4126,18 +4126,27 @@ bool CutterCore::isIOCacheEnabled() const void CutterCore::commitWriteCache() { + CORE_LOCK(); // Temporarily disable cache mode TempConfig tempConfig; tempConfig.set("io.cache", false); if (!isWriteModeEnabled()) { cmdRaw("oo+"); - cmdRaw("wci"); + rz_io_cache_commit(core->io, 0, UT64_MAX); + rz_core_block_read(core); cmdRaw("oo"); } else { - cmdRaw("wci"); + rz_io_cache_commit(core->io, 0, UT64_MAX); + rz_core_block_read(core); } } +void CutterCore::resetWriteCache() +{ + CORE_LOCK(); + rz_io_cache_reset(core->io, core->io->cached); +} + // Enable or disable write-mode. Avoid unecessary changes if not need. void CutterCore::setWriteMode(bool enabled) { diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 4013f39e..f36796a4 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -721,6 +721,10 @@ public: * @brief Commit write cache to the file on disk. */ void commitWriteCache(); + /** + * @brief Reset write cache. + */ + void resetWriteCache(); /** * @brief Enable or disable Write mode. When the file is opened in write mode, any changes to it