mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
tools: Added file shredder, splitter and combiner
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user