fix: Issues where files are only being partially overwritten instead of truncated
This commit is contained in:
parent
adc51d3773
commit
74d59705ad
@ -237,8 +237,7 @@ namespace hex {
|
|||||||
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
|
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
|
||||||
auto path = directory / AchievementsFile;
|
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()) {
|
if (!file.isValid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -254,7 +253,6 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto result = json.dump(4);
|
const auto result = json.dump(4);
|
||||||
file.setSize(0);
|
|
||||||
file.writeString(result);
|
file.writeString(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -130,10 +130,9 @@ namespace hex {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
|
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()) {
|
if (file.isValid()) {
|
||||||
file.setSize(0);
|
|
||||||
file.writeString(result);
|
file.writeString(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ namespace hex {
|
|||||||
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
||||||
if (!file.isValid()) {
|
if (!file.isValid()) {
|
||||||
log::error("Failed to load workspace from file '{}'", path.string());
|
log::error("Failed to load workspace from file '{}'", path.string());
|
||||||
|
file.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ namespace hex {
|
|||||||
};
|
};
|
||||||
} catch (nlohmann::json::exception &e) {
|
} catch (nlohmann::json::exception &e) {
|
||||||
log::error("Failed to load workspace from file '{}': {}", path.string(), e.what());
|
log::error("Failed to load workspace from file '{}': {}", path.string(), e.what());
|
||||||
|
file.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,15 +83,7 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileProvider::resizeRaw(u64 newSize) {
|
void FileProvider::resizeRaw(u64 newSize) {
|
||||||
this->close();
|
m_file.setSize(newSize);
|
||||||
|
|
||||||
{
|
|
||||||
wolv::io::File file(m_path, wolv::io::File::Mode::Write);
|
|
||||||
|
|
||||||
file.setSize(newSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)this->open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileProvider::insertRaw(u64 offset, u64 size) {
|
void FileProvider::insertRaw(u64 offset, u64 size) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user