From 9e8a33c4110131d1a38bf2e35cb79e3ee609098b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 3 Oct 2024 18:07:19 +0300 Subject: [PATCH] delete blocksdata region file if there is no associated voxels region --- src/files/WorldRegions.cpp | 15 ++++++++++++++- src/files/WorldRegions.hpp | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/files/WorldRegions.cpp b/src/files/WorldRegions.cpp index fee124c0..a96fc61b 100644 --- a/src/files/WorldRegions.cpp +++ b/src/files/WorldRegions.cpp @@ -285,7 +285,8 @@ void WorldRegions::processBlocksData(int x, int z, const BlockDataProc& func) { if (voxRegfile == nullptr) { logger.warning() << "missing voxels region - discard blocks data for " << x << "_" << z; - abort(); // TODO: delete region file + deleteRegion(REGION_LAYER_BLOCKS_DATA, x, z); + return; } for (uint cz = 0; cz < REGION_SIZE; cz++) { for (uint cx = 0; cx < REGION_SIZE; cx++) { @@ -398,6 +399,18 @@ void WorldRegions::writeAll() { } } +void WorldRegions::deleteRegion(RegionLayerIndex layerid, int x, int z) { + auto& layer = layers[layerid]; + if (layer.getRegFile({x, z}, false)) { + throw std::runtime_error("region file is currently in use"); + } + auto file = layer.getRegionFilePath(x, z); + if (fs::exists(file)) { + logger.info() << "remove region file " << file.u8string(); + fs::remove(file); + } +} + bool WorldRegions::parseRegionFilename( const std::string& name, int& x, int& z ) { diff --git a/src/files/WorldRegions.hpp b/src/files/WorldRegions.hpp index 5bc3a5b2..ad0bc584 100644 --- a/src/files/WorldRegions.hpp +++ b/src/files/WorldRegions.hpp @@ -248,6 +248,8 @@ public: /// @brief Write all region layers void writeAll(); + void deleteRegion(RegionLayerIndex layerid, int x, int z); + /// @brief Extract X and Z from 'X_Z.bin' region file name. /// @param name source region file name /// @param x parsed X destination