1
0
mirror of synced 2024-11-28 09:30:51 +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::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
[[nodiscard]] virtual bool open();
virtual void close();
[[nodiscard]] virtual bool open() = 0;
virtual void close() = 0;
void addPatch(u64 offset, const void *buffer, size_t size, bool createUndo = false);
void createUndoPoint();

View File

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

View File

@ -170,14 +170,6 @@ namespace hex::prv {
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) {
if (this->m_patchTreeOffset > 0) {
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 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 writeRaw(u64 offset, const void *buffer, size_t size) override { hex::unused(offset, buffer, size); }
[[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);
if (auto *fileProvider = dynamic_cast<prv::FileProvider*>(provider); fileProvider != nullptr) {
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); });
return;
}
EventManager::post<EventProviderOpened>(provider);
}
else if (provider->hasLoadInterface())
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()) {
View::showErrorPopup("hex.builtin.popup.error.open"_lang);
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"]);
if (!provider->open())
success = false;
else
EventManager::post<EventProviderOpened>(provider);
}
return success;

View File

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

View File

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

View File

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

View File

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

View File

@ -190,11 +190,11 @@ namespace hex::plugin::builtin::prv {
this->m_dataSize = maxAddress + 1;
this->m_dataValid = true;
return Provider::open();
return true;
}
void MotorolaSRECProvider::close() {
Provider::close();
}
[[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 (provider->open()) {
EventManager::post<EventProviderOpened>(provider);
ImGui::CloseCurrentPopup();
}
else {

View File

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