Переделано под один мега-проект LMS с общим CMakeLists.txt

This commit is contained in:
krivoshein
2025-01-15 12:34:56 +03:00
parent 3064818931
commit 1c93b1f94d
219 changed files with 68 additions and 51 deletions

View File

@@ -0,0 +1,220 @@
#include "assetsmanager.h"
AssetsManager::AssetsManager(QObject *parent) : QObject(parent)
{
}
void AssetsManager::initialize(UpdateController* updateContoller,DataParser *dataParser)
{
this->updateController = updateContoller;
connect(this,&AssetsManager::sigSaveVersion,updateContoller,&UpdateController::saveVersionToFile);
datas = new QList<StreamingVersionData*>;
}
void AssetsManager::setVersionList(QList<StreamingVersionData*> *streamingVersion)
{
datas->clear();
datas = streamingVersion;
}
bool AssetsManager::findDuplicate(QString name)
{
QListIterator<StreamingVersionData*> iterator(*datas);
while (iterator.hasNext())
{
if (iterator.next()->getViewName() == name) return true;
}
return false;
}
QString AssetsManager::setVersion(QString versionName)
{
QListIterator<StreamingVersionData*> iterator(*datas);
while (iterator.hasNext())
{
StreamingVersionData *version = iterator.next();
if (version->getViewName() == versionName)
{
currentVersionData = version;
emit sigSaveVersion(currentVersionData);
return version->getAbsolutPath();
}
}
return "none";
}
QList<FileData> *AssetsManager::prepareLocalPathList(QList<FileData> *fileData)
{
QList<FileData> *completeList = fileData;
for(int i = 0; i < completeList->count();i++)
{
FileData fileData = completeList->at(i);
int index = fileData.path.indexOf(currentVersionData->getViewName());
if(index != -1)
{
fileData.path = Tools::createRealPath(fileData.path,currentVersionData); //делаем в полный путь
completeList->replace(i,fileData);
}
else
{
fileData.path = Tools::createRootPath(fileData.path);
}
}
return completeList;
}
QList<FileData> *AssetsManager::prepareRealPathList(QList<FileData> *fileData)
{
QList<FileData> *completeList = fileData;
for(int i = 0; i < completeList->count();i++)
{
FileData fileData = completeList->at(i);
if(fileData.path.contains(streamingAssetsFolderName))
{
fileData.path = Tools::createStreamingToRealPath(fileData.path,currentVersionData);
}
else
{
fileData.path = Tools::createRealPath(fileData.path,currentVersionData); //делаем в полный путь
}
completeList->replace(i,fileData);
}
return completeList;
}
void AssetsManager::addVersion(StreamingVersionData *data)
{
datas->push_back(data);
}
void AssetsManager::createCopyVersion(QString versionName,QString newVersionName)
{
qDebug() << "assetManager thread ID " << QThread::currentThreadId();
QListIterator<StreamingVersionData*> iterator(*datas);
StreamingVersionData* data;
while (iterator.hasNext())
{
StreamingVersionData *version = iterator.next();
if (version->getViewName() == versionName)
{
data = version;
}
}
qDebug() << "Version for copy " << versionName;
qDebug() << "New version name " << newVersionName;
//берем путь до копии
//преобразуем в реальный путь
QString sourcePath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + versionName;
QString destinationPath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + newVersionName;
QDir sourceDir(sourcePath);
if(!sourceDir.exists())
{
qDebug() << "Версии нет в SharedData";
return;
}
QDir destinationDir(destinationPath);
if(destinationDir.exists())
{
qDebug() << "Папка уже существует";
return;
}
//Создаем папку в Shared с новым именем
QDir().mkdir(destinationPath);
copyAllRecurse(sourcePath,destinationPath);
//добавляем в список текущих ассетов
updateController->calculateFullHash();
updateController->changeAssetVersion(newVersionName);
updateController->sendNewVersionList();
//повторно отправляем список версий из папки shared
}
void AssetsManager::deleteVersion(QString versionName)
{
QMutableListIterator<StreamingVersionData*> iterator(*datas);
//если версия равна текущей - игнор
if (currentVersionData->getViewName() == versionName)
return;
while (iterator.hasNext())
{
StreamingVersionData *version = iterator.next();
//проверка на наличие указанной версии
if (version->getViewName() == versionName)
{
//удаление папки
QString verFolderPath = QDir::currentPath() + "/" + sharedDataFolderName + "/" + versionName;
QDir dir(verFolderPath);
dir.removeRecursively();
//удаление хэша
QString hashPath = QDir::currentPath() + "/" + staticDataFolderName + "/" + versionName + "Hash.xml";
QFile file(hashPath);
if(file.exists()){
file.remove();
}
//удаление
datas->removeOne(version);
break;
}
}
updateController->calculateSharedHash();
updateController->sendNewVersionList();
}
void AssetsManager::copyAllRecurse(QString source,QString destination)
{
//Копируем все объекты туда
QDir sourceDir(source);
foreach(QString folder,sourceDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
QString destPath = destination + QDir::separator() + folder;
sourceDir.mkpath(destPath);
copyAllRecurse(source + QDir::separator() + folder,destPath);
}
foreach(QString file,sourceDir.entryList(QDir::Files))
{
QFile::copy(source + QDir::separator() + file,destination + QDir::separator() + file);
}
}
AssetsManager::~AssetsManager()
{
}
StreamingVersionData *AssetsManager::getCurrentVersionData() const
{
return currentVersionData;
}