mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
feat: add version container
This commit is contained in:
@@ -9,8 +9,9 @@ UpdateController::UpdateController(DataParser *parser,SendSystem *sendSystem, QO
|
||||
applicationFolderPath = QDir::currentPath() + applicationFolderName;
|
||||
}
|
||||
|
||||
void UpdateController::initialize(MainWindow *mainWindow)
|
||||
void UpdateController::initialize(MainWindow *mainWindow,VersionContainer *versionContainer)
|
||||
{
|
||||
this->versionContainer = versionContainer;
|
||||
connect(this,&UpdateController::sigUpdateComplete,mainWindow,&MainWindow::showCompleteDialogBox);
|
||||
}
|
||||
|
||||
@@ -32,11 +33,6 @@ void UpdateController::calculateStreamingHash()
|
||||
dataParser->createFileDataList(streamingDataList,streamingHashFilename);
|
||||
}
|
||||
|
||||
void UpdateController::setServerVersion(StreamingVersionData *version)
|
||||
{
|
||||
serverVersion = version;
|
||||
}
|
||||
|
||||
QList<FileData> UpdateController::calculateHash(QString path,QString ignoreName)
|
||||
{
|
||||
qDebug() << "Try calculate";
|
||||
@@ -136,11 +132,6 @@ void UpdateController::updateFilesOnServer(QList<FileData> *fileSendList){
|
||||
|
||||
}
|
||||
|
||||
StreamingVersionData *UpdateController::getServerVersion() const
|
||||
{
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
class SendSystem;
|
||||
class MainWindow;
|
||||
class DataParser;
|
||||
class VersionContainer;
|
||||
|
||||
class UpdateController : public QObject
|
||||
{
|
||||
@@ -28,26 +29,26 @@ class UpdateController : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdateController(DataParser *parser,SendSystem *sendSystem,QObject *parent = 0);
|
||||
void initialize(MainWindow *mainWindow);
|
||||
explicit UpdateController(DataParser *parser,
|
||||
SendSystem *sendSystem,
|
||||
QObject *parent = 0);
|
||||
|
||||
void initialize(MainWindow *mainWindow,VersionContainer *versionContainer);
|
||||
void calculateCommonHash();
|
||||
void calculateStreamingHash();
|
||||
void setServerVersion(StreamingVersionData *version);
|
||||
~UpdateController();
|
||||
|
||||
void updateFilesOnServer(QList<FileData> *fileSendList);
|
||||
|
||||
StreamingVersionData *getServerVersion() const;
|
||||
|
||||
signals:
|
||||
void sigUpdateComplete(bool flag);
|
||||
private:
|
||||
DataParser *dataParser;
|
||||
SendSystem *sendSystem;
|
||||
QString applicationFolderPath;
|
||||
VersionContainer *versionContainer;
|
||||
QList<FileData> appDataList;
|
||||
QList<FileData> streamingDataList;
|
||||
StreamingVersionData *serverVersion;
|
||||
|
||||
QList<FileData> calculateHash(QString path,QString ignoreName);
|
||||
};
|
||||
|
||||
@@ -88,9 +88,19 @@ void DataParser::createServerSettings(ServerSettings* serverSettings)
|
||||
xmlWriter.writeAttribute("AutoStart",QString::number(false));
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
xmlWriter.writeStartElement("VersionData");
|
||||
xmlWriter.writeAttribute("Version","NONE");
|
||||
xmlWriter.writeEndElement();
|
||||
|
||||
if(serverSettings->LocalVersionName == "")
|
||||
{
|
||||
xmlWriter.writeStartElement("VersionData");
|
||||
xmlWriter.writeAttribute("Version","NONE");
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlWriter.writeStartElement("VersionData");
|
||||
xmlWriter.writeAttribute("Version",serverSettings->LocalVersionName);
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
|
||||
@@ -197,11 +207,13 @@ ServerSettings *DataParser::getServerSettings()
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
while (!xmlReader.atEnd()){
|
||||
while (!xmlReader.atEnd())
|
||||
{
|
||||
|
||||
if(xmlReader.isStartElement()){
|
||||
|
||||
if(xmlReader.name() == "ServerSettings"){
|
||||
if(xmlReader.name() == "ServerSettings")
|
||||
{
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()){
|
||||
QString name = attr.name().toString();
|
||||
@@ -222,6 +234,20 @@ ServerSettings *DataParser::getServerSettings()
|
||||
if(name == "AutoStart"){
|
||||
settings->isAutoStart = value.toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlReader.name() == "VersionData")
|
||||
{
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if (name == "Version")
|
||||
{
|
||||
settings->LocalVersionName = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@ HashComparer::HashComparer(DataParser *dataParser,QObject *)
|
||||
this->dataParser = dataParser;
|
||||
}
|
||||
|
||||
void HashComparer::initialize(MainWindow* mainWindow)
|
||||
void HashComparer::initialize(MainWindow* mainWindow,VersionContainer *versionContainer)
|
||||
{
|
||||
connect(this,&HashComparer::sigCallCheck,mainWindow,&MainWindow::checkUpdate);
|
||||
connect(this,&HashComparer::sigHaveDelta,mainWindow,&MainWindow::showUpdateInfo);
|
||||
this->versionContainer = versionContainer;
|
||||
}
|
||||
|
||||
void HashComparer::CompareDeltas()
|
||||
@@ -68,8 +69,26 @@ void HashComparer::setWidget(UpdateNotifyWidget* updateWidget)
|
||||
this->updateWidget = updateWidget;
|
||||
}
|
||||
|
||||
quint16 HashComparer::getFileUpdateCount() const
|
||||
{
|
||||
return filesForUpdate->count();
|
||||
}
|
||||
|
||||
QList<FileData> *HashComparer::getFilesForUpdate() const
|
||||
{
|
||||
QList<FileData> *completeList = filesForUpdate;
|
||||
|
||||
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 filesForUpdate;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,20 @@
|
||||
#include <updatenotifywidget.h>
|
||||
|
||||
class UpdateNotifyWidget;
|
||||
class VersionContainer;
|
||||
class HashComparer :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HashComparer(DataParser *dataParser,QObject *parent = nullptr);
|
||||
void initialize(MainWindow* mainWindow);
|
||||
void initialize(MainWindow* mainWindow,VersionContainer *versionContainer);
|
||||
void CompareDeltas();
|
||||
~HashComparer();
|
||||
|
||||
void showDeltas();
|
||||
void setWidget(UpdateNotifyWidget *updateWidget);
|
||||
quint16 getFileUpdateCount() const;
|
||||
QList<FileData> *getFilesForUpdate() const;
|
||||
|
||||
signals:
|
||||
void sigCallCheck();
|
||||
void sigHaveDelta();
|
||||
@@ -30,6 +31,7 @@ private:
|
||||
UpdateNotifyWidget* updateWidget;
|
||||
QList<FileData> *filesForUpdate;
|
||||
DataParser *dataParser;
|
||||
VersionContainer *versionContainer;
|
||||
};
|
||||
|
||||
#endif // HASHCOMPARER_H
|
||||
|
||||
@@ -26,11 +26,13 @@ void RecognizeSystem::initialize(UpdateController *updateController,
|
||||
DataParser *dataParser,
|
||||
MainWindow *mainWindow,
|
||||
HashComparer *hashComparer,
|
||||
TCPClient *client)
|
||||
TCPClient *client,
|
||||
VersionContainer* versionContainer)
|
||||
{
|
||||
this->updateController = updateController;
|
||||
this->dataParser = dataParser;
|
||||
this->mainWindow = mainWindow;
|
||||
this->versionContainer = versionContainer;
|
||||
|
||||
connect(this,&RecognizeSystem::sigSaveLoginData,dataParser,&DataParser::createAuthData);
|
||||
connect(this,&RecognizeSystem::sigStartCompare,hashComparer,&HashComparer::CompareDeltas);
|
||||
@@ -83,7 +85,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = Tools::createReceiveFullPath(filePath,updateController->getServerVersion());
|
||||
filePath = Tools::createReceiveFullPath(filePath,versionContainer->getServerVersionData());
|
||||
|
||||
QDir dir(filePath);
|
||||
if(!dir.exists()){
|
||||
@@ -118,7 +120,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
|
||||
}
|
||||
|
||||
filePath = Tools::createReceiveFullPath(filePath,updateController->getServerVersion());
|
||||
filePath = Tools::createReceiveFullPath(filePath,versionContainer->getServerVersionData());
|
||||
|
||||
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||
emit sigSendDebugLog("CLIENT: filePath: " + filePath);
|
||||
@@ -201,7 +203,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = Tools::createReceiveFullPath(filePath,updateController->getServerVersion());
|
||||
filePath = Tools::createReceiveFullPath(filePath,versionContainer->getServerVersionData());
|
||||
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
@@ -227,7 +229,8 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
|
||||
}
|
||||
|
||||
if(packetType ==PacketType::TYPE_FINISH){ //для повторного создания хэша после загрузки
|
||||
if (packetType ==PacketType::TYPE_FINISH) //для повторного создания хэша после загрузки
|
||||
{
|
||||
updateController->calculateCommonHash();
|
||||
emit sigLoadComplete();
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
@@ -238,17 +241,19 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
bool flag = false;
|
||||
quint64 size = 0;
|
||||
quint64 fileCount = 0;
|
||||
quint64 fileDelete = 0;
|
||||
|
||||
stream.startTransaction();
|
||||
stream >> flag;
|
||||
stream >> size;
|
||||
stream >> fileCount;
|
||||
stream >> fileDelete;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
emit sigNeedUpdate(flag,size,fileCount);
|
||||
emit sigNeedUpdate(flag,size,fileCount,fileDelete);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
@@ -284,9 +289,7 @@ void RecognizeSystem::checkAccessType(QString type)
|
||||
|
||||
void RecognizeSystem::setServerVersion(StreamingVersionData *serverVersion)
|
||||
{
|
||||
dataParser->changeVersion(serverVersion->getViewName());
|
||||
updateController->setServerVersion(serverVersion);
|
||||
mainWindow->setCurrentVersionName(serverVersion->getViewName());
|
||||
versionContainer->setServerVersonData(serverVersion);
|
||||
}
|
||||
|
||||
void RecognizeSystem::showServerDataList(QList<StreamingVersionData*> *showServerDataList)
|
||||
|
||||
@@ -26,7 +26,8 @@ public:
|
||||
DataParser *dataParser,
|
||||
MainWindow *mainWindow,
|
||||
HashComparer *hashComparer,
|
||||
TCPClient *client);
|
||||
TCPClient *client,
|
||||
VersionContainer* versionContainer);
|
||||
|
||||
void recognize(QTcpSocket *socket);
|
||||
void checkAccessType(QString type);
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
signals:
|
||||
void sigUpdateBytesAvailable();
|
||||
void sigLoadComplete();
|
||||
void sigNeedUpdate(bool flag,qint64 size,quint64 fileCount);
|
||||
void sigNeedUpdate(bool flag,qint64 size,quint64 fileCount,quint64 fileDelete);
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigSocketDisabled();
|
||||
void sigServerBlocked();
|
||||
@@ -50,6 +51,7 @@ private:
|
||||
MainWindow *mainWindow;
|
||||
UpdateController *updateController;
|
||||
DataParser *dataParser;
|
||||
VersionContainer *versionContainer;
|
||||
PacketType packetType;
|
||||
QString message;
|
||||
QString filePath;
|
||||
|
||||
@@ -26,6 +26,7 @@ static QString serverHash = fullStaticDataFolderName + "/serverHash.xml";
|
||||
static QString cmd_CheckVersionList = "CHECKVERSIONLIST";
|
||||
static QString cmd_GetServerHash = "GETSERVERDATALIST";
|
||||
static QString cmd_Disable = "DISABLE";
|
||||
static QString baseNamePackage = "base";
|
||||
|
||||
enum PacketType{
|
||||
TYPE_NONE = 0,
|
||||
|
||||
42
Core/versioncontainer.cpp
Normal file
42
Core/versioncontainer.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "versioncontainer.h"
|
||||
|
||||
VersionContainer::VersionContainer(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VersionContainer::~VersionContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString VersionContainer::getServerVersion() const
|
||||
{
|
||||
return serverVersionData->getViewName();
|
||||
}
|
||||
|
||||
QString VersionContainer::getLocalVersion() const
|
||||
{
|
||||
return localVersionData->getViewName();
|
||||
}
|
||||
|
||||
StreamingVersionData *VersionContainer::getLocalVersionData() const
|
||||
{
|
||||
return localVersionData;
|
||||
}
|
||||
|
||||
void VersionContainer::setLocalVersionData(StreamingVersionData *value)
|
||||
{
|
||||
localVersionData = value;
|
||||
}
|
||||
|
||||
StreamingVersionData *VersionContainer::getServerVersionData() const
|
||||
{
|
||||
return serverVersionData;
|
||||
}
|
||||
|
||||
void VersionContainer::setServerVersonData(StreamingVersionData *value)
|
||||
{
|
||||
serverVersionData = value;
|
||||
}
|
||||
31
Core/versioncontainer.h
Normal file
31
Core/versioncontainer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef VERSIONCONTAINER_H
|
||||
#define VERSIONCONTAINER_H
|
||||
|
||||
#include "streamingversiondata.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class VersionContainer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VersionContainer(QObject *parent = nullptr);
|
||||
~VersionContainer();
|
||||
|
||||
QString getServerVersion() const;
|
||||
QString getLocalVersion() const;
|
||||
|
||||
|
||||
StreamingVersionData *getLocalVersionData() const;
|
||||
void setLocalVersionData(StreamingVersionData *value);
|
||||
|
||||
StreamingVersionData *getServerVersionData() const;
|
||||
void setServerVersonData(StreamingVersionData *value);
|
||||
|
||||
private:
|
||||
StreamingVersionData *localVersionData;
|
||||
StreamingVersionData *serverVersionData;
|
||||
|
||||
};
|
||||
|
||||
#endif // VERSIONCONTAINER_H
|
||||
Reference in New Issue
Block a user