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 GitHub
parent 861c784600
commit de5c1a5154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -100,7 +100,7 @@ bool IOModesController::askCommitUnsavedChanges()
if (ret == QMessageBox::Save) { if (ret == QMessageBox::Save) {
Core()->commitWriteCache(); Core()->commitWriteCache();
} else if (ret == QMessageBox::Discard) { } else if (ret == QMessageBox::Discard) {
Core()->cmdRaw("wcr"); Core()->resetWriteCache();
emit Core()->refreshCodeViews(); emit Core()->refreshCodeViews();
} else if (ret == QMessageBox::Cancel) { } else if (ret == QMessageBox::Cancel) {
return false; return false;

View File

@ -4126,18 +4126,27 @@ bool CutterCore::isIOCacheEnabled() const
void CutterCore::commitWriteCache() void CutterCore::commitWriteCache()
{ {
CORE_LOCK();
// Temporarily disable cache mode // Temporarily disable cache mode
TempConfig tempConfig; TempConfig tempConfig;
tempConfig.set("io.cache", false); tempConfig.set("io.cache", false);
if (!isWriteModeEnabled()) { if (!isWriteModeEnabled()) {
cmdRaw("oo+"); cmdRaw("oo+");
cmdRaw("wci"); rz_io_cache_commit(core->io, 0, UT64_MAX);
rz_core_block_read(core);
cmdRaw("oo"); cmdRaw("oo");
} else { } 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. // Enable or disable write-mode. Avoid unecessary changes if not need.
void CutterCore::setWriteMode(bool enabled) void CutterCore::setWriteMode(bool enabled)
{ {

View File

@ -721,6 +721,10 @@ public:
* @brief Commit write cache to the file on disk. * @brief Commit write cache to the file on disk.
*/ */
void commitWriteCache(); 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 * @brief Enable or disable Write mode. When the file is opened in write mode, any changes to it