mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Automatically migrate client mod storage (#11960)
This commit is contained in:
parent
47735c273c
commit
fc161e757c
3 changed files with 43 additions and 5 deletions
|
@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "clientmap.h"
|
||||
#include "clientmedia.h"
|
||||
#include "version.h"
|
||||
#include "database/database-files.h"
|
||||
#include "database/database-sqlite3.h"
|
||||
#include "serialization.h"
|
||||
#include "guiscalingfilter.h"
|
||||
|
@ -140,6 +141,33 @@ Client::Client(
|
|||
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
|
||||
}
|
||||
|
||||
void Client::migrateModStorage()
|
||||
{
|
||||
std::string mod_storage_dir = porting::path_user + DIR_DELIM + "client";
|
||||
std::string old_mod_storage = mod_storage_dir + DIR_DELIM + "mod_storage";
|
||||
if (fs::IsDir(old_mod_storage)) {
|
||||
infostream << "Migrating client mod storage to SQLite3 database" << std::endl;
|
||||
{
|
||||
ModMetadataDatabaseFiles files_db(mod_storage_dir);
|
||||
std::vector<std::string> mod_list;
|
||||
files_db.listMods(&mod_list);
|
||||
for (const std::string &modname : mod_list) {
|
||||
infostream << "Migrating client mod storage for mod " << modname << std::endl;
|
||||
StringMap meta;
|
||||
files_db.getModEntries(modname, &meta);
|
||||
for (const auto &pair : meta) {
|
||||
m_mod_storage_database->setModEntry(modname, pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!fs::Rename(old_mod_storage, old_mod_storage + ".bak")) {
|
||||
// Execution cannot move forward if the migration does not complete.
|
||||
throw BaseException("Could not finish migrating client mod storage");
|
||||
}
|
||||
infostream << "Finished migration of client mod storage" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Client::loadMods()
|
||||
{
|
||||
// Don't load mods twice.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue