Merge branch 'add-versionController' into merge-task-and-verController

# Conflicts:
#	InstructorsAndTrainees/CMakeLists.txt
#	InstructorsAndTrainees/connectorToServer/Core/recognizesystem.h
#	InstructorsAndTrainees/instructorsandtraineeswidget.cpp
#	ServerLMS/Systems/updatecontroller.cpp
#	ServerLMS/Systems/updatecontroller.h
This commit is contained in:
semenov
2025-01-21 15:52:20 +03:00
50 changed files with 1770 additions and 192 deletions

View File

@@ -41,16 +41,18 @@ void UpdateController::changeAssetVersion(QString versionName)
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
}
void UpdateController::createCopyVersion(QString versionName,QString newVersionName)
void UpdateController::createCopyVersion(QString versionName,QString newVersionName,QString author)
{
commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
assetManager->createCopyVersion(versionName,newVersionName);
assetManager->createCopyVersion(versionName,newVersionName,author);
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
}
void UpdateController::deleteAssetVersion(QString versionName)
{
commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY);
assetManager->deleteVersion(versionName);
commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
}
void UpdateController::compareFiles(ClientHandler* handler, QByteArray array)
@@ -59,7 +61,6 @@ void UpdateController::compareFiles(ClientHandler* handler, QByteArray array)
loadHash();
clientDataList.clear();
xmlFileDataParse(array);
clientDataList.append(*datas);
checkNeedUpdate(handler);
mutex->unlock();
}
@@ -182,8 +183,6 @@ QString UpdateController::getCommands()
}
void UpdateController::setUpCurrentServerHash()
{
QList<FileData> *fileList = new QList<FileData>;
@@ -296,61 +295,69 @@ QList<FileData>* UpdateController::calculateHash(QString path)
{
serverDataList.clear();
QDirIterator iterator(path,QDirIterator::Subdirectories);
if(!QDir(path).exists()){
QDir().mkdir(path);
}
QDir dir(path);
dir.setFilter(QDir::NoDotAndDotDot);
QString hashString;
QStringList filter;
filter << "*";
QList<FileData> *files = new QList<FileData>;
while (iterator.hasNext())
QDirIterator dirIterator(path,filter, QDir::AllEntries | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (dirIterator.hasNext())
{
iterator.next();
QFileInfo fileInfo = iterator.fileInfo();
QFileInfo fileInfo(dirIterator.next());
FileData currentFile;
QFile file(fileInfo.absoluteFilePath());
quint64 fileSize = file.size();
const quint64 bufferSize = 10240;
if (fileInfo.isHidden()) continue;
if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
if(fileInfo.isDir() && !fileInfo.fileName().startsWith(".") && fileInfo.fileName() != "RRJLoader")
{
char buffer[bufferSize];
int bytesRead;
int readSize = qMin(fileSize,bufferSize);
QCryptographicHash hash(QCryptographicHash::Md5);
while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0){
fileSize -= bytesRead;
hash.addData(buffer,bytesRead);
readSize = qMin(fileSize,bufferSize);
}
hashString = QString(hash.result().toHex());
currentFile.hash = hashString;
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
files->push_back(currentFile);
file.close();
}
else if(fileInfo.isDir() && fileInfo.fileName() != ".." && !fileInfo.isRoot())
{
currentFile.hash = "FOLDER";
currentFile.path = Tools::createLocalPath(fileInfo.path());
if(!files->contains(currentFile)){
if(!files->contains(currentFile))
{
files->push_back(currentFile);
}
}
}
std::sort(files->begin(),files->end());
QDirIterator fileIterator(path,filter,QDir::Files | QDir::NoDotAndDotDot,QDirIterator::Subdirectories);
while (fileIterator.hasNext())
{
fileIterator.next();
QFileInfo fileInfo = fileIterator.fileInfo();
FileData currentFile;
QFile file(fileInfo.absoluteFilePath());
quint64 fileSize = file.size(); //буффер для хэширования крупных файлов
const quint64 bufferSize = 10240;
if(fileInfo.isHidden()) continue;
if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
{
char buffer[bufferSize];
int bytesRead;
int readSize = qMin(fileSize,bufferSize);
QCryptographicHash hash(QCryptographicHash::Md5);
while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0)
{
fileSize -= bytesRead;
hash.addData(buffer,bytesRead);
readSize = qMin(fileSize,bufferSize);
}
hashString = QString(hash.result().toHex());
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
currentFile.hash = hashString;
files->push_back(currentFile);
file.close();
}
}
serverDataList.append(*files);
return files;
}
@@ -404,6 +411,12 @@ void UpdateController::CalculateSizeToSend(QList<FileData> diffList)
void UpdateController::calculateSharedHash()
{
QDir sharedDir(sharedDataPath);
if(!QDir(sharedDataPath).exists())
{
QDir().mkdir(sharedDataPath);
}
QDirIterator dirIterator(sharedDir);
QList<FileData> *fileList = new QList<FileData>;
QList<StreamingVersionData*> *versionList = new QList<StreamingVersionData*>;
@@ -424,74 +437,24 @@ void UpdateController::calculateSharedHash()
fileInfo.absoluteFilePath(),fileInfo.fileName(),
fileInfo.birthTime(),fileInfo.size());
// if(fileInfo.fileName() == baseNameVersion)
// {
// version->setIsChangeable(false);
// version->setAuthor(tr("Константа-дизайн"));
// }
// else
// {
// version->setIsChangeable(true);
// }
versionList->append(version);
}
createVersionListXmlAnswer(*versionList);
assetManager->setVersionList(versionList);
assetManager->createFirstVersionListXML(*versionList);
//assetManager->setVersionList(versionList);
}
void UpdateController::createVersionListXmlAnswer(QList<StreamingVersionData *> version) //TODO: переименовать и перебросить в AssetManager
{
QList<SXmlAnswerTag> listTag;
foreach(StreamingVersionData* ver,version)
{
SAttribute attribute1 = {"Version", ver->getViewName()};
SAttribute attribute2 = {"Created", ver->getCreateData().toString()};
QList<SAttribute> listAttr = {attribute1, attribute2};
SXmlAnswerTag tag = {"VersionData", listAttr};
listTag.append(tag);
}
QFile file(versionListFile);
file.open(QIODevice::WriteOnly);
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("VersionList");
foreach(SXmlAnswerTag tag,listTag)
{
xmlWriter.writeStartElement(tag.elementName);
foreach(SAttribute attribute,tag.attr)
{
xmlWriter.writeAttribute(attribute.name,attribute.value);
}
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
}
void UpdateController::saveVersionToFile(StreamingVersionData *streamingVersion) //TODO: переименовать и перебросить в AssetManager
{
QFile file(version);
file.open(QFile::WriteOnly);
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("VersionData");
xmlWriter.writeAttribute("Version",streamingVersion->getViewName());
xmlWriter.writeAttribute("Created",streamingVersion->getCreateData().toString());
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
}
void UpdateController::sendNewVersionList()
{
commonClientHandler->sendNewVersionListToAllClient();
@@ -505,7 +468,6 @@ bool UpdateController::checkDuplicate(QString versionName)
void UpdateController::xmlFileDataParse(QByteArray array)
{
QXmlStreamReader xmlReader(array);
datas = new QList<FileData>;
xmlReader.readNext();
//Крутимся в цикле до тех пор, пока не достигнем конца документа
@@ -529,7 +491,7 @@ void UpdateController::xmlFileDataParse(QByteArray array)
data.hash = value;
}
datas->append(data);
clientDataList.append(data);
}
}
@@ -537,6 +499,11 @@ void UpdateController::xmlFileDataParse(QByteArray array)
}
}
StreamingVersionData* UpdateController::getCurrentVersion()
{
return assetManager->getCurrentVersionData();
}
void UpdateController::printFileList(QList<FileData> fileData)
{
QListIterator<FileData> iterator(fileData);
@@ -571,11 +538,6 @@ DataInfo *UpdateController::getCurrentDataInfo()
return dataInfo;
}
QList<FileData> *UpdateController::getDatas() const
{
return datas;
}
void UpdateController::clearCurrentDataInfo()
{
delete dataInfo;