Xong phần map viewer
Some checks failed
Test / test (push) Has been cancelled

This commit is contained in:
2026-06-20 09:18:19 +02:00
parent 819323f8c8
commit 90e8e9d252
13 changed files with 431 additions and 32 deletions

View File

@@ -193,6 +193,48 @@ bool Database::ensureDataDirs(std::string& err)
return true;
}
bool Database::migrateLegacyMapsDir(std::string& err)
{
if (data_dir_.filename() != "data")
return true;
const std::filesystem::path legacy = "maps";
const auto target = mapsDir();
if (!std::filesystem::is_directory(legacy) || legacy == target)
return true;
std::error_code ec;
std::filesystem::create_directories(target, ec);
if (ec)
{
err = "failed to create maps directory: " + target.string();
return false;
}
for (const auto& entry : std::filesystem::directory_iterator(legacy, ec))
{
if (ec || !entry.is_directory())
continue;
const auto dest = target / entry.path().filename();
if (std::filesystem::exists(dest))
continue;
std::filesystem::rename(entry.path(), dest, ec);
if (ec)
{
ec.clear();
std::filesystem::copy(entry.path(), dest, std::filesystem::copy_options::recursive, ec);
if (ec)
{
err = "failed to migrate map directory: " + entry.path().string();
return false;
}
std::filesystem::remove_all(entry.path(), ec);
ec.clear();
}
}
return true;
}
bool Database::applySchema(std::string& err)
{
return execSql(db_, kSchemaSql, err);
@@ -494,6 +536,8 @@ bool Database::init(std::string& err)
return false;
if (!ensureDataDirs(err))
return false;
if (!migrateLegacyMapsDir(err))
return false;
if (!migrateFromJsonIfNeeded(err))
return false;
if (!getMeta("schema_version"))