Convert from Rizin commands to the API for w (#2926)

This commit is contained in:
billow 2022-04-10 11:43:42 +08:00 committed by Anton Kochkov
parent a48399f73b
commit 7d42a5c7e6
3 changed files with 16 additions and 3 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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