sys: Clean up properly after file is closed

Addresses another issue in #362
This commit is contained in:
WerWolv 2021-12-05 22:09:43 +01:00
parent 73604e90c8
commit 8385b88ce8
5 changed files with 26 additions and 0 deletions

View File

@ -37,12 +37,17 @@ namespace hex {
EventManager::subscribe<EventProjectFileStore>(this, []{ EventManager::subscribe<EventProjectFileStore>(this, []{
ProjectFile::setBookmarks(SharedData::bookmarkEntries); ProjectFile::setBookmarks(SharedData::bookmarkEntries);
}); });
EventManager::subscribe<EventFileUnloaded>(this, []{
ImHexApi::Bookmarks::getEntries().clear();
});
} }
ViewBookmarks::~ViewBookmarks() { ViewBookmarks::~ViewBookmarks() {
EventManager::unsubscribe<RequestAddBookmark>(this); EventManager::unsubscribe<RequestAddBookmark>(this);
EventManager::unsubscribe<EventProjectFileLoad>(this); EventManager::unsubscribe<EventProjectFileLoad>(this);
EventManager::unsubscribe<EventProjectFileStore>(this); EventManager::unsubscribe<EventProjectFileStore>(this);
EventManager::unsubscribe<EventFileUnloaded>(this);
} }
void ViewBookmarks::drawContent() { void ViewBookmarks::drawContent() {

View File

@ -27,11 +27,16 @@ namespace hex {
} }
} }
}); });
EventManager::subscribe<EventFileUnloaded>(this, [this]{
this->m_disassembly.clear();
});
} }
ViewDisassembler::~ViewDisassembler() { ViewDisassembler::~ViewDisassembler() {
EventManager::unsubscribe<EventDataChanged>(this); EventManager::unsubscribe<EventDataChanged>(this);
EventManager::unsubscribe<EventRegionSelected>(this); EventManager::unsubscribe<EventRegionSelected>(this);
EventManager::unsubscribe<EventFileUnloaded>(this);
} }
void ViewDisassembler::disassemble() { void ViewDisassembler::disassemble() {

View File

@ -39,11 +39,16 @@ namespace hex {
if (this->m_blockSize != 0) if (this->m_blockSize != 0)
this->m_entropyHandlePosition = region.address / this->m_blockSize; this->m_entropyHandlePosition = region.address / this->m_blockSize;
}); });
EventManager::subscribe<EventFileUnloaded>(this, [this]{
this->m_dataValid = false;
});
} }
ViewInformation::~ViewInformation() { ViewInformation::~ViewInformation() {
EventManager::unsubscribe<EventDataChanged>(this); EventManager::unsubscribe<EventDataChanged>(this);
EventManager::unsubscribe<EventRegionSelected>(this); EventManager::unsubscribe<EventRegionSelected>(this);
EventManager::unsubscribe<EventFileUnloaded>(this);
} }
static float calculateEntropy(std::array<ImU64, 256> &valueCounts, size_t numBytes) { static float calculateEntropy(std::array<ImU64, 256> &valueCounts, size_t numBytes) {

View File

@ -152,6 +152,11 @@ namespace hex {
} }
}); });
EventManager::subscribe<EventFileUnloaded>(this, [this]{
this->m_textEditor.SetText("");
this->m_patternLanguageRuntime->abort();
});
/* Settings */ /* Settings */
{ {
@ -181,6 +186,7 @@ namespace hex {
EventManager::unsubscribe<RequestSetPatternLanguageCode>(this); EventManager::unsubscribe<RequestSetPatternLanguageCode>(this);
EventManager::unsubscribe<EventFileLoaded>(this); EventManager::unsubscribe<EventFileLoaded>(this);
EventManager::unsubscribe<RequestChangeTheme>(this); EventManager::unsubscribe<RequestChangeTheme>(this);
EventManager::unsubscribe<EventFileUnloaded>(this);
} }
void ViewPatternEditor::drawMenu() { void ViewPatternEditor::drawMenu() {

View File

@ -21,10 +21,15 @@ namespace hex {
this->m_filter.reserve(0xFFFF); this->m_filter.reserve(0xFFFF);
std::memset(this->m_filter.data(), 0x00, this->m_filter.capacity()); std::memset(this->m_filter.data(), 0x00, this->m_filter.capacity());
EventManager::subscribe<EventFileUnloaded>(this, [this]{
this->m_foundStrings.clear();
});
} }
ViewStrings::~ViewStrings() { ViewStrings::~ViewStrings() {
EventManager::unsubscribe<EventDataChanged>(this); EventManager::unsubscribe<EventDataChanged>(this);
EventManager::unsubscribe<EventFileUnloaded>(this);
} }
std::string readString(const FoundString &foundString) { std::string readString(const FoundString &foundString) {