1
0
mirror of synced 2024-09-24 11:38:26 +02:00

feat: move PerProvider data to new provider when saving memory provider into file provider (#1264)

This commit is contained in:
iTrooz 2023-08-26 01:47:44 +02:00 committed by GitHub
parent 758cdd91f3
commit 32d6ac2241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -245,4 +245,10 @@ namespace hex {
* @brief Send an event to the main Imhex instance
*/
EVENT_DEF(SendMessageToMainInstance, const std::string, const std::vector<u8>&);
/**
* Move the data from all PerProvider instances from one provider to another.
* The 'from' provider should not have any per provider data after this, and should be immediately deleted
*/
EVENT_DEF(MovePerProviderData, prv::Provider *, prv::Provider *);
}

View File

@ -82,6 +82,22 @@ namespace hex {
EventManager::subscribe<EventImHexClosing>(this, [this] {
this->m_data.clear();
});
// moves the data of this PerProvider instance from one provider to another
EventManager::subscribe<MovePerProviderData>(this, [this](prv::Provider *from, prv::Provider *to) {
// get the value from the old provider, (removes it from the map)
auto node = m_data.extract(from);
// ensure the value existed
if (node.empty()) return;
// delete the value from the new provider, that we want to replace
this->m_data.erase(to);
// re-insert it with the key of the new provider
node.key() = to;
this->m_data.insert(std::move(node));
});
}
void onDestroy() {

View File

@ -53,6 +53,8 @@ namespace hex::plugin::builtin {
if (!fileProvider->open())
ImHexApi::Provider::remove(newProvider);
else {
EventManager::post<MovePerProviderData>(this, fileProvider);
fileProvider->markDirty(false);
EventManager::post<EventProviderOpened>(newProvider);
ImHexApi::Provider::remove(this, true);