1
0
mirror of synced 2025-02-26 14:21:39 +01:00

fix: Crashes when resizing file

Fixes #721
This commit is contained in:
WerWolv 2022-09-04 11:16:20 +02:00
parent 45e987b413
commit d9a47fe815
13 changed files with 27 additions and 25 deletions

View File

@ -70,8 +70,8 @@ namespace hex::prv {
[[nodiscard]] virtual std::string getName() const = 0; [[nodiscard]] virtual std::string getName() const = 0;
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0; [[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
[[nodiscard]] virtual bool open(); [[nodiscard]] virtual bool open() = 0;
virtual void close(); virtual void close() = 0;
void addPatch(u64 offset, const void *buffer, size_t size, bool createUndo = false); void addPatch(u64 offset, const void *buffer, size_t size, bool createUndo = false);
void createUndoPoint(); void createUndoPoint();

View File

@ -308,6 +308,8 @@ namespace hex {
setCurrentProvider(0); setCurrentProvider(0);
provider->close(); provider->close();
EventManager::post<EventProviderClosed>(provider);
delete provider; delete provider;
} }

View File

@ -170,14 +170,6 @@ namespace hex::prv {
return page; return page;
} }
bool Provider::open() {
EventManager::post<EventProviderOpened>(this);
return true;
}
void Provider::close() {
EventManager::post<EventProviderClosed>(this);
}
void Provider::addPatch(u64 offset, const void *buffer, size_t size, bool createUndo) { void Provider::addPatch(u64 offset, const void *buffer, size_t size, bool createUndo) {
if (this->m_patchTreeOffset > 0) { if (this->m_patchTreeOffset > 0) {
auto iter = this->m_patches.end(); auto iter = this->m_patches.end();

View File

@ -15,6 +15,9 @@ namespace hex::plugin::builtin::prv {
[[nodiscard]] bool isResizable() const override { return false; } [[nodiscard]] bool isResizable() const override { return false; }
[[nodiscard]] bool isSavable() const override { return false; } [[nodiscard]] bool isSavable() const override { return false; }
[[nodiscard]] bool open() override { return true; }
void close() override { }
void readRaw(u64 offset, void *buffer, size_t size) override { hex::unused(offset, buffer, size); } void readRaw(u64 offset, void *buffer, size_t size) override { hex::unused(offset, buffer, size); }
void writeRaw(u64 offset, const void *buffer, size_t size) override { hex::unused(offset, buffer, size); } void writeRaw(u64 offset, const void *buffer, size_t size) override { hex::unused(offset, buffer, size); }
[[nodiscard]] size_t getActualSize() const override { return 0x00; } [[nodiscard]] size_t getActualSize() const override { return 0x00; }

View File

@ -21,7 +21,8 @@ namespace hex::plugin::builtin {
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.file", true); auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.file", true);
if (auto *fileProvider = dynamic_cast<prv::FileProvider*>(provider); fileProvider != nullptr) { if (auto *fileProvider = dynamic_cast<prv::FileProvider*>(provider); fileProvider != nullptr) {
fileProvider->setPath(path); fileProvider->setPath(path);
(void)fileProvider->open(); if (fileProvider->open())
EventManager::post<EventProviderOpened>(fileProvider);
} }
} }
@ -100,6 +101,8 @@ namespace hex::plugin::builtin {
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); }); TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
return; return;
} }
EventManager::post<EventProviderOpened>(provider);
} }
else if (provider->hasLoadInterface()) else if (provider->hasLoadInterface())
EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup")); EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup"));
@ -107,7 +110,10 @@ namespace hex::plugin::builtin {
if (!provider->open() || !provider->isAvailable()) { if (!provider->open() || !provider->isAvailable()) {
View::showErrorPopup("hex.builtin.popup.error.open"_lang); View::showErrorPopup("hex.builtin.popup.error.open"_lang);
TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); }); TaskManager::doLater([provider] { ImHexApi::Provider::remove(provider); });
return;
} }
EventManager::post<EventProviderOpened>(provider);
} }
}); });

View File

@ -41,6 +41,8 @@ namespace hex::plugin::builtin {
provider->loadSettings(providerSettings["settings"]); provider->loadSettings(providerSettings["settings"]);
if (!provider->open()) if (!provider->open())
success = false; success = false;
else
EventManager::post<EventProviderOpened>(provider);
} }
return success; return success;

View File

@ -137,7 +137,7 @@ namespace hex::plugin::builtin::prv {
#endif #endif
return Provider::open(); return true;
} }
void DiskProvider::close() { void DiskProvider::close() {
@ -156,8 +156,6 @@ namespace hex::plugin::builtin::prv {
this->m_diskHandle = -1; this->m_diskHandle = -1;
#endif #endif
Provider::close();
} }
void DiskProvider::readRaw(u64 offset, void *buffer, size_t size) { void DiskProvider::readRaw(u64 offset, void *buffer, size_t size) {

View File

@ -300,7 +300,7 @@ namespace hex::plugin::builtin::prv {
#endif #endif
return Provider::open(); return true;
} }
void FileProvider::close() { void FileProvider::close() {
@ -319,8 +319,6 @@ namespace hex::plugin::builtin::prv {
::close(this->m_file); ::close(this->m_file);
#endif #endif
Provider::close();
} }
void FileProvider::loadSettings(const nlohmann::json &settings) { void FileProvider::loadSettings(const nlohmann::json &settings) {

View File

@ -273,7 +273,7 @@ namespace hex::plugin::builtin::prv {
} }
}); });
return Provider::open(); return true;
} else { } else {
return false; return false;
} }
@ -285,8 +285,6 @@ namespace hex::plugin::builtin::prv {
if (this->m_cacheUpdateThread.joinable()) { if (this->m_cacheUpdateThread.joinable()) {
this->m_cacheUpdateThread.join(); this->m_cacheUpdateThread.join();
} }
Provider::close();
} }
bool GDBProvider::isConnected() const { bool GDBProvider::isConnected() const {

View File

@ -210,12 +210,11 @@ namespace hex::plugin::builtin::prv {
this->m_dataSize = maxAddress + 1; this->m_dataSize = maxAddress + 1;
this->m_dataValid = true; this->m_dataValid = true;
return Provider::open(); return true;
} }
void IntelHexProvider::close() { void IntelHexProvider::close() {
Provider::close();
} }
[[nodiscard]] std::string IntelHexProvider::getName() const { [[nodiscard]] std::string IntelHexProvider::getName() const {

View File

@ -190,11 +190,11 @@ namespace hex::plugin::builtin::prv {
this->m_dataSize = maxAddress + 1; this->m_dataSize = maxAddress + 1;
this->m_dataValid = true; this->m_dataValid = true;
return Provider::open(); return true;
} }
void MotorolaSRECProvider::close() { void MotorolaSRECProvider::close() {
Provider::close();
} }
[[nodiscard]] std::string MotorolaSRECProvider::getName() const { [[nodiscard]] std::string MotorolaSRECProvider::getName() const {

View File

@ -36,6 +36,7 @@ namespace hex::plugin::builtin {
if (ImGui::Button("hex.builtin.common.open"_lang)) { if (ImGui::Button("hex.builtin.common.open"_lang)) {
if (provider->open()) { if (provider->open()) {
EventManager::post<EventProviderOpened>(provider);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
else { else {

View File

@ -99,6 +99,8 @@ namespace hex::plugin::builtin {
return; return;
} }
EventManager::post<EventProviderOpened>(provider);
updateRecentProviders(); updateRecentProviders();
} }
} }
@ -340,7 +342,8 @@ namespace hex::plugin::builtin {
if (ImGui::Hyperlink("X")) { if (ImGui::Hyperlink("X")) {
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.null"); auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.null");
if (provider != nullptr) if (provider != nullptr)
(void)provider->open(); if (provider->open())
EventManager::post<EventProviderOpened>(provider);
} }
} }