mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
impr: Don't memory map files, never keep a write handle open for long
Closes #592
This commit is contained in:
@@ -8,12 +8,20 @@
|
||||
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(OS_MACOS)
|
||||
#include <unistd.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
#define off64_t off_t
|
||||
#define fopen64 fopen
|
||||
#define fseeko64 fseek
|
||||
#define ftello64 ftell
|
||||
#define ftruncate64 ftruncate
|
||||
#elif defined(OS_LINUX)
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
namespace hex::fs {
|
||||
@@ -65,6 +73,8 @@ namespace hex::fs {
|
||||
|
||||
void disableBuffering();
|
||||
|
||||
std::optional<struct stat> getFileInfo();
|
||||
|
||||
private:
|
||||
FILE *m_file;
|
||||
std::fs::path m_path;
|
||||
|
||||
@@ -168,4 +168,18 @@ namespace hex::fs {
|
||||
std::setvbuf(this->m_file, nullptr, _IONBF, 0);
|
||||
}
|
||||
|
||||
std::optional<struct stat> File::getFileInfo() {
|
||||
struct stat fileInfo = { };
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
if (wstat(this->m_path.c_str(), &fileInfo) != 0)
|
||||
return std::nullopt;
|
||||
#else
|
||||
if (stat(hex::toUTF8String(this->m_path).c_str(), &fileInfo) != 0)
|
||||
return std::nullopt;
|
||||
#endif
|
||||
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -114,6 +114,10 @@ namespace hex::prv {
|
||||
for (auto &[patchAddress, patch] : getPatches()) {
|
||||
this->writeRaw(patchAddress - this->getBaseAddress(), &patch, 1);
|
||||
}
|
||||
|
||||
if (!this->isWritable())
|
||||
return;
|
||||
|
||||
this->markDirty();
|
||||
|
||||
this->m_patches.emplace_back();
|
||||
|
||||
Reference in New Issue
Block a user