1
0
mirror of synced 2025-01-30 19:43:43 +01:00

fix: Issues where files are only being partially overwritten instead of truncated

This commit is contained in:
WerWolv 2024-02-19 22:22:59 +01:00
parent adc51d3773
commit 74d59705ad
4 changed files with 5 additions and 14 deletions

View File

@ -237,8 +237,7 @@ namespace hex {
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile;
wolv::io::File file(path, wolv::io::File::Mode::Write);
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid()) {
continue;
}
@ -254,7 +253,6 @@ namespace hex {
}
const auto result = json.dump(4);
file.setSize(0);
file.writeString(result);
break;
}

View File

@ -130,10 +130,9 @@ namespace hex {
return;
}
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Write);
wolv::io::File file(dir / SettingsFile, wolv::io::File::Mode::Create);
if (file.isValid()) {
file.setSize(0);
file.writeString(result);
break;
}

View File

@ -40,6 +40,7 @@ namespace hex {
wolv::io::File file(path, wolv::io::File::Mode::Read);
if (!file.isValid()) {
log::error("Failed to load workspace from file '{}'", path.string());
file.remove();
return;
}
@ -56,6 +57,7 @@ namespace hex {
};
} catch (nlohmann::json::exception &e) {
log::error("Failed to load workspace from file '{}': {}", path.string(), e.what());
file.remove();
}
}

View File

@ -83,15 +83,7 @@ namespace hex::plugin::builtin {
}
void FileProvider::resizeRaw(u64 newSize) {
this->close();
{
wolv::io::File file(m_path, wolv::io::File::Mode::Write);
file.setSize(newSize);
}
(void)this->open();
m_file.setSize(newSize);
}
void FileProvider::insertRaw(u64 offset, u64 size) {