mirror of https://github.com/WerWolv/ImHex.git
impr: Added default saveAs implementation for all providers
This commit is contained in:
parent
7cdba75bef
commit
5097a223e3
|
@ -9,6 +9,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <hex/helpers/magic.hpp>
|
#include <hex/helpers/magic.hpp>
|
||||||
|
#include <wolv/io/file.hpp>
|
||||||
|
|
||||||
namespace hex::prv {
|
namespace hex::prv {
|
||||||
|
|
||||||
|
@ -36,7 +37,20 @@ namespace hex::prv {
|
||||||
|
|
||||||
void Provider::save() { }
|
void Provider::save() { }
|
||||||
void Provider::saveAs(const std::fs::path &path) {
|
void Provider::saveAs(const std::fs::path &path) {
|
||||||
hex::unused(path);
|
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
||||||
|
|
||||||
|
if (file.isValid()) {
|
||||||
|
std::vector<u8> buffer(std::min<size_t>(0xFF'FFFF, this->getActualSize()), 0x00);
|
||||||
|
size_t bufferSize = buffer.size();
|
||||||
|
|
||||||
|
for (u64 offset = 0; offset < this->getActualSize(); offset += bufferSize) {
|
||||||
|
if (bufferSize > this->getActualSize() - offset)
|
||||||
|
bufferSize = this->getActualSize() - offset;
|
||||||
|
|
||||||
|
this->read(offset + this->getBaseAddress(), buffer.data(), bufferSize, true);
|
||||||
|
file.write(buffer.data(), bufferSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::resize(size_t newSize) {
|
void Provider::resize(size_t newSize) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ namespace hex::plugin::builtin {
|
||||||
[[nodiscard]] size_t getActualSize() const override;
|
[[nodiscard]] size_t getActualSize() const override;
|
||||||
|
|
||||||
void save() override;
|
void save() override;
|
||||||
void saveAs(const std::fs::path &path) override;
|
|
||||||
|
|
||||||
[[nodiscard]] std::string getName() const override;
|
[[nodiscard]] std::string getName() const override;
|
||||||
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
|
||||||
|
|
|
@ -30,7 +30,6 @@ namespace hex::plugin::builtin {
|
||||||
[[nodiscard]] size_t getActualSize() const override;
|
[[nodiscard]] size_t getActualSize() const override;
|
||||||
|
|
||||||
void save() override;
|
void save() override;
|
||||||
void saveAs(const std::fs::path &path) override;
|
|
||||||
|
|
||||||
[[nodiscard]] std::string getName() const override;
|
[[nodiscard]] std::string getName() const override;
|
||||||
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override;
|
||||||
|
|
|
@ -28,7 +28,6 @@ namespace hex::plugin::builtin {
|
||||||
void remove(u64 offset, size_t size) override;
|
void remove(u64 offset, size_t size) override;
|
||||||
|
|
||||||
void save() override;
|
void save() override;
|
||||||
void saveAs(const std::fs::path &path) override;
|
|
||||||
|
|
||||||
[[nodiscard]] std::string getName() const override { return LangEntry("hex.builtin.provider.mem_file.unsaved"); }
|
[[nodiscard]] std::string getName() const override { return LangEntry("hex.builtin.provider.mem_file.unsaved"); }
|
||||||
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override { return { }; }
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override { return { }; }
|
||||||
|
|
|
@ -91,25 +91,6 @@ namespace hex::plugin::builtin {
|
||||||
this->applyPatches();
|
this->applyPatches();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileProvider::saveAs(const std::fs::path &path) {
|
|
||||||
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
|
||||||
|
|
||||||
if (file.isValid()) {
|
|
||||||
auto provider = ImHexApi::Provider::get();
|
|
||||||
|
|
||||||
std::vector<u8> buffer(std::min<size_t>(0xFF'FFFF, provider->getActualSize()), 0x00);
|
|
||||||
size_t bufferSize = buffer.size();
|
|
||||||
|
|
||||||
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
|
|
||||||
if (bufferSize > provider->getActualSize() - offset)
|
|
||||||
bufferSize = provider->getActualSize() - offset;
|
|
||||||
|
|
||||||
provider->read(offset + this->getBaseAddress(), buffer.data(), bufferSize);
|
|
||||||
file.write(buffer.data(), bufferSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileProvider::resize(size_t newSize) {
|
void FileProvider::resize(size_t newSize) {
|
||||||
this->close();
|
this->close();
|
||||||
|
|
||||||
|
|
|
@ -221,10 +221,6 @@ namespace hex::plugin::builtin {
|
||||||
this->applyPatches();
|
this->applyPatches();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDBProvider::saveAs(const std::fs::path &path) {
|
|
||||||
hex::unused(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t GDBProvider::getActualSize() const {
|
size_t GDBProvider::getActualSize() const {
|
||||||
return this->m_size;
|
return this->m_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,25 +50,6 @@ namespace hex::plugin::builtin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryFileProvider::saveAs(const std::fs::path &path) {
|
|
||||||
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
|
||||||
|
|
||||||
if (file.isValid()) {
|
|
||||||
auto provider = ImHexApi::Provider::get();
|
|
||||||
|
|
||||||
std::vector<u8> buffer(std::min<size_t>(0xFF'FFFF, provider->getActualSize()), 0x00);
|
|
||||||
size_t bufferSize = buffer.size();
|
|
||||||
|
|
||||||
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
|
|
||||||
if (bufferSize > provider->getActualSize() - offset)
|
|
||||||
bufferSize = provider->getActualSize() - offset;
|
|
||||||
|
|
||||||
provider->read(offset + this->getBaseAddress(), buffer.data(), bufferSize);
|
|
||||||
file.write(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryFileProvider::resize(size_t newSize) {
|
void MemoryFileProvider::resize(size_t newSize) {
|
||||||
this->m_data.resize(newSize);
|
this->m_data.resize(newSize);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ namespace hex::plugin::windows {
|
||||||
[[nodiscard]] size_t getActualSize() const override { return 0xFFFF'FFFF'FFFF; }
|
[[nodiscard]] size_t getActualSize() const override { return 0xFFFF'FFFF'FFFF; }
|
||||||
|
|
||||||
void save() override {}
|
void save() override {}
|
||||||
void saveAs(const std::fs::path &) override {}
|
|
||||||
|
|
||||||
[[nodiscard]] std::string getName() const override { return hex::format("hex.windows.provider.process_memory.name"_lang, this->m_selectedProcess != nullptr ? this->m_selectedProcess->name : ""); }
|
[[nodiscard]] std::string getName() const override { return hex::format("hex.windows.provider.process_memory.name"_lang, this->m_selectedProcess != nullptr ? this->m_selectedProcess->name : ""); }
|
||||||
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
|
||||||
|
|
Loading…
Reference in New Issue