Files
RRJClient/Core/hashcomparer.cpp
2026-03-11 15:53:08 +03:00

106 lines
2.8 KiB
C++

#include "hashcomparer.h"
HashComparer::HashComparer(QObject *) :
updateWidget(nullptr),
filesForUpdate(nullptr),
versionContainer(nullptr)
{
}
void HashComparer::initialize(VersionContainer *versionContainer,UpdateNotifyWidget* updateWidget)
{
this->versionContainer = versionContainer;
this->updateWidget = updateWidget;
filesForUpdate = new QList<FileData>;
connect(this,&HashComparer::sigAddToList,updateWidget,&UpdateNotifyWidget::addToList,Qt::QueuedConnection);
connect(this,&HashComparer::sigGetUpdateList,updateWidget,&UpdateNotifyWidget::getUpdateList,Qt::DirectConnection);
}
void HashComparer::CompareDeltas(QList<FileData> *serverStreamingHash, QList<FileData> localStreamingHash)
{
QList<FileData> *files = new QList<FileData>;
serverFiles = new QList<FileData>;
QMutableListIterator<FileData> iterator(localStreamingHash);
for (auto &item:localStreamingHash)
{
if(!serverStreamingHash->contains(item))
{
if (item.path.contains("docs.xml")) continue; //фильтр на docs
if (item.path.contains("CfiList.xml")) continue;
qint32 fileDataIndex = findIndexByPath(*serverStreamingHash, item.path);
if (fileDataIndex != -1)
{
serverFiles->append(serverStreamingHash->at(fileDataIndex));
}
files->append(item);
}
}
filesForUpdate = files;
showDeltas();
}
quint32 HashComparer::findIndexByPath(const QList<FileData> &serverStreamingHash,QString path)
{
for(int i = 0; i < serverStreamingHash.size(); i++)
{
if(serverStreamingHash.at(i).path == path)
return i;
}
return -1;
}
void HashComparer::showDeltas()
{
if (filesForUpdate->length() <= 0)
{
emit sigCallCheck();
return;
}
for (int i = 0; i < filesForUpdate->size(); i++)
{
FileData local = filesForUpdate->at(i);
FileData server = FileData();
server.lastUpdate = "нет";
if (serverFiles->size() > i)
{
server = serverFiles->at(i);
}
emit sigAddToList(local,server);
}
emit sigHaveDelta();
}
quint16 HashComparer::getFileUpdateCount() const
{
return filesForUpdate->count();
}
QList<FileData> *HashComparer::getFilesForUpdate() const
{
QList<FileData> *completeList = emit sigGetUpdateList();
for (int i = 0; i < completeList->count();i++)
{
FileData data = completeList->at(i);
QString streamingAssetsName = "StreamingAssets";
quint16 baseIndex = data.path.indexOf("StreamingAssets");
data.path = data.path.remove(0,baseIndex + streamingAssetsName.length());
data.path.prepend("/SharedData/" + versionContainer->getLocalVersion());
completeList->replace(i,data);
}
return completeList;
}