MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / rename

Method rename

launcher/minecraft/World.cpp:354–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352}
353
354bool World::rename(const QString &newName)
355{
356 if(m_containerFile.isFile())
357 {
358 return false;
359 }
360
361 auto data = getLevelDatDataFromFS(m_containerFile);
362 if(data.isEmpty())
363 {
364 return false;
365 }
366
367 auto worldData = parseLevelDat(data);
368 if(!worldData)
369 {
370 return false;
371 }
372 auto &val = worldData->at("Data");
373 if(val.get_type() != nbt::tag_type::Compound)
374 {
375 return false;
376 }
377 auto &dataCompound = val.as<nbt::tag_compound>();
378 dataCompound.put("LevelName", nbt::value_initializer(newName.toUtf8().data()));
379 data = serializeLevelDat(worldData.get());
380
381 putLevelDatDataToFS(m_containerFile, data);
382
383 m_actualName = newName;
384
385 QDir parentDir(m_containerFile.absoluteFilePath());
386 parentDir.cdUp();
387 QFile container(m_containerFile.absoluteFilePath());
388 auto dirName = FS::DirNameFromString(m_actualName, parentDir.absolutePath());
389 container.rename(parentDir.absoluteFilePath(dirName));
390
391 return true;
392}
393
394namespace {
395

Callers 8

undoTrashInstanceMethod · 0.80
commitStagedInstanceMethod · 0.80
updateModIndexMethod · 0.80
installMethod · 0.80
installMethod · 0.80
loadListMethod · 0.80
enableMethod · 0.80

Calls 10

getLevelDatDataFromFSFunction · 0.85
parseLevelDatFunction · 0.85
serializeLevelDatFunction · 0.85
putLevelDatDataToFSFunction · 0.85
DirNameFromStringFunction · 0.85
isEmptyMethod · 0.80
putMethod · 0.80
atMethod · 0.45
dataMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected