tools: Added file shredder, splitter and combiner

This commit is contained in:
WerWolv
2021-09-22 17:56:06 +02:00
parent 5601aab043
commit e57481b87c
13 changed files with 600 additions and 31 deletions
+20 -5
View File
@@ -3,7 +3,7 @@
namespace hex {
File::File(const std::string &path, Mode mode) {
File::File(const std::string &path, Mode mode) : m_path(path) {
if (mode == File::Mode::Read)
this->m_file = fopen64(path.c_str(), "rb");
else if (mode == File::Mode::Write)
@@ -23,14 +23,20 @@ namespace hex {
}
File::~File() {
if (isValid())
fclose(this->m_file);
this->close();
}
void File::seek(u64 offset) {
fseeko64(this->m_file, offset, SEEK_SET);
}
void File::close() {
if (isValid()) {
fclose(this->m_file);
this->m_file = nullptr;
}
}
size_t File::readBuffer(u8 *buffer, size_t size) {
if (!isValid()) return 0;
@@ -41,7 +47,7 @@ namespace hex {
if (!isValid()) return { };
std::vector<u8> bytes(numBytes ?: getSize());
auto bytesRead = fread(bytes.data(), bytes.size(), 1, this->m_file);
auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file);
bytes.resize(bytesRead);
@@ -63,7 +69,7 @@ namespace hex {
void File::write(const std::vector<u8> &bytes) {
if (!isValid()) return;
fwrite(bytes.data(), bytes.size(), 1, this->m_file);
fwrite(bytes.data(), 1, bytes.size(), this->m_file);
}
void File::write(const std::string &string) {
@@ -89,4 +95,13 @@ namespace hex {
ftruncate64(fileno(this->m_file), size);
}
void File::flush() {
fflush(this->m_file);
}
void File::remove() {
this->close();
std::remove(this->m_path.c_str());
}
}
@@ -17,7 +17,7 @@ namespace hex {
std::vector<ContentRegistry::Tools::Entry> SharedData::toolsEntries;
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
u32 SharedData::patternPaletteOffset;
std::string SharedData::errorPopupMessage;
std::string SharedData::popupMessage;
std::list<ImHexApi::Bookmarks::Entry> SharedData::bookmarkEntries;
std::vector<pl::PatternData*> SharedData::patternData;
+27 -8
View File
@@ -24,8 +24,9 @@ namespace hex {
}
void View::drawCommonInterfaces() {
if (ImGui::BeginPopupModal("hex.common.error"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
ImGui::SetNextWindowSize(ImVec2(200, 100) * SharedData::globalScale);
if (ImGui::BeginPopupModal("hex.common.info"_lang)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
ImGui::Separator();
if (ImGui::Button("hex.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape))
@@ -34,8 +35,20 @@ namespace hex {
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("hex.common.fatal"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
ImGui::SetNextWindowSize(ImVec2(200, 100) * SharedData::globalScale);
if (ImGui::BeginPopupModal("hex.common.error"_lang)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
ImGui::Separator();
if (ImGui::Button("hex.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
ImGui::SetNextWindowSize(ImVec2(200, 100) * SharedData::globalScale);
if (ImGui::BeginPopupModal("hex.common.fatal"_lang, nullptr)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
ImGui::Separator();
if (ImGui::Button("hex.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) {
@@ -47,14 +60,20 @@ namespace hex {
}
}
void View::showMessagePopup(const std::string &message) {
SharedData::popupMessage = message;
View::doLater([] { ImGui::OpenPopup("hex.common.info"_lang); });
}
void View::showErrorPopup(const std::string &errorMessage) {
SharedData::errorPopupMessage = errorMessage;
SharedData::popupMessage = errorMessage;
View::doLater([] { ImGui::OpenPopup("hex.common.error"_lang); });
}
void View::showFatalPopup(const std::string &errorMessage) {
SharedData::errorPopupMessage = errorMessage;
SharedData::popupMessage = errorMessage;
View::doLater([] { ImGui::OpenPopup("hex.common.fatal"_lang); });
}
@@ -64,11 +83,11 @@ namespace hex {
}
ImVec2 View::getMinSize() {
return ImVec2(480, 720);
return ImVec2(480, 720) * SharedData::globalScale;
}
ImVec2 View::getMaxSize() {
return ImVec2(FLT_MAX, FLT_MAX);
return { FLT_MAX, FLT_MAX };
}