feat: move PerProvider data to new provider when saving memory provider into file provider (#1264)
This commit is contained in:
parent
758cdd91f3
commit
32d6ac2241
@ -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 *);
|
||||
}
|
@ -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() {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user