ref: change send command

This commit is contained in:
semenov
2025-01-17 10:49:27 +03:00
parent a9357415e6
commit 52ed028515
47 changed files with 7765 additions and 600 deletions

View File

@@ -104,67 +104,6 @@ QList<FileData> UpdateController::calculateHash(QString path,QString ignoreName)
}
}
// QDirIterator iterator(dir,QDirIterator::Subdirectories);
//
// if(!QDir(path).exists())
// { //проверка на наличие папки
// QDir().mkdir(path);
// }
// QString hashString;
// while (iterator.hasNext())
// {
// iterator.next();
// QFileInfo fileInfo = iterator.fileInfo();
// FileData currentFile;
// QFile file(fileInfo.absoluteFilePath());
// quint64 fileSize = file.size(); //буффер для хэширования крупных файлов
// const quint64 bufferSize = 10240;
// if(fileInfo.isHidden()) continue;
// if(ignoreName != "" && fileInfo.path().contains(ignoreName)) continue;
// if(fileInfo.isFile() && file.open(QIODevice::ReadOnly))
// {
// 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;
// hashes->push_back(currentFile);
// file.close();
// }
// else if (fileInfo.isDir() && !fileInfo.isRoot() && fileInfo.fileName() != "..")
// {
// currentFile.path = Tools::createLocalPath(fileInfo.path());
// currentFile.hash = "FOLDER";
// if(!hashes->contains(currentFile))
// {
// hashes->push_back(currentFile);
// }
// }
// }
//std::sort(hashes->begin(),hashes->end());
return *hashes;
}
@@ -183,7 +122,8 @@ void UpdateController::updateFilesOnServer(QList<FileData> *fileSendList){
}
else
{
sendSystem->sendFileBlock(data.path);
QString fullPath = Tools::createReceiveFullPath(data.path,versionContainer->getLocalVersionData());
sendSystem->sendFileBlockWithVersion(fullPath,data.path);
}
}

View File

@@ -9,6 +9,7 @@ void NotifyController::showWarning(QString text)
{
QMessageBox warning;
warning.setText(text);
warning.setIcon(QMessageBox::Warning);
warning.setWindowTitle(tr("Ошибка"));
warning.exec();

View File

@@ -297,7 +297,7 @@ void RecognizeSystem::checkAccessType(QString type)
void RecognizeSystem::setServerVersion(StreamingVersionData *serverVersion)
{
versionContainer->setServerVersonData(serverVersion);
versionContainer->setServerVersionData(serverVersion);
}
void RecognizeSystem::showServerDataList(QList<StreamingVersionData*> *showServerDataList)

View File

@@ -98,6 +98,46 @@ void SendSystem::sendFolderBlock(QString path)
socket->waitForReadyRead(100);
}
void SendSystem::sendFileBlockWithVersion(QString localPath,QString serverPath)
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
//QString fullPath = Tools::createLocalPath(localPath);
quint64 fileSize = 0;
int countSend = 0;
QFile file(localPath); //Открываем файл для чтения
QFileInfo fileInfo(file);
fileSize = fileInfo.size();
stream << PacketType::TYPE_FILE; //Отправляем тип блока
stream << serverPath << fileSize;
socket->waitForReadyRead(20);
//socket->waitForBytesWritten();
if(file.open(QFile::ReadOnly)){
while(!file.atEnd()){
QByteArray data = file.read(1025*250);
stream << data;
socket->waitForBytesWritten();
countSend++;
}
qDebug() << Tools::getTime() << "count end Final: " << countSend;
}
file.close();
emit sigSend();
//qDebug() << "Transaction after send file: " << socket->isTransactionStarted();
countSend = 0;
//socket->waitForBytesWritten();
socket->waitForReadyRead(20);
}
void SendSystem::sendQTConnect()
{
QString value = QString::number(PacketType::TYPE_QT);
@@ -158,6 +198,37 @@ void SendSystem::sendCopyVersion(QString streamingVersion)
stream << streamingVersion;
}
void SendSystem::sendPacketType(PacketType packetType)
{
QDataStream stream(socket);
QByteArray data;
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
stream << packetType;
}
void SendSystem::sendCheckHash()
{
QDataStream stream(socket);
QByteArray data;
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
sendFileBlock(staticDataFolderName + hashFilename);
socket->waitForReadyRead(2000);
stream << PacketType::TYPE_CHECK_VERSION;
//socket->waitForReadyRead(1000);
// else if(command == "update")
// {
// qDebug() << ("Update started");
// stream << PacketType::TYPE_COMMAND;
// stream << command;
// socket->waitForReadyRead(1000);
// }
}
SendSystem::~SendSystem()
{

View File

@@ -25,12 +25,15 @@ public:
void sendDisable();
void sendFileBlock(QString path);
void sendFolderBlock(QString path);
void sendFileBlockWithVersion(QString localPath, QString serverPath);
void sendQTConnect();
void sendXMLAnswer(QByteArray array);
void sendFinish();
void sendChangeVersion(StreamingVersionData *streamingVersion);
void sendDeleteVersion(StreamingVersionData *streamingVersion);
void sendCopyVersion(QString versionName);
void sendCheckHash();
void sendPacketType(PacketType packetType);
~SendSystem();
signals:

View File

@@ -68,39 +68,6 @@ QTcpSocket *TCPClient::getSocket()
return socket;
}
void TCPClient::slotSendCommand(QString command)
{
QDataStream stream(socket);
QByteArray data;
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
if(!command.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
if(command == "check")
{
stream << PacketType::TYPE_COMMAND;
stream << command;
socket->waitForBytesWritten();
sendSystem->sendFileBlock(staticDataFolderName + hashFilename);
emit sigSendDebugLog(Tools::getTime() + " Local checkFile sended");
socket->waitForReadyRead(1000);
}
else if(command == "update"){
emit sigSendDebugLog("Update started");
stream << PacketType::TYPE_COMMAND;
stream << command;
socket->waitForReadyRead(1000);
}
else if(command == "run"){
externalExecuter->callApp();
}
}else{
emit sigSendDebugLog("WRONG SOCKET AFTER ENTERED");
}
}
void TCPClient::slotConnectNotify()
{
if(socket->state() != QTcpSocket::ConnectedState)

View File

@@ -43,7 +43,6 @@ signals:
void sigConnectionState(bool flag);
public slots:
void slotSendCommand(QString message);
void slotConnectNotify();
private slots:

View File

@@ -41,6 +41,8 @@ enum PacketType{
TYPE_XMLANSWER = 8,
TYPE_QT = 9,
TYPE_DISABLE = 11,
TYPE_UPDATE = 12,
TYPE_CHECK_VERSION = 13,
HASH_READY = 150,
CHANGE_DATA_VERSION = 151,

View File

@@ -36,7 +36,7 @@ StreamingVersionData *VersionContainer::getServerVersionData() const
return serverVersionData;
}
void VersionContainer::setServerVersonData(StreamingVersionData *value)
void VersionContainer::setServerVersionData(StreamingVersionData *value)
{
serverVersionData = value;
}

View File

@@ -19,7 +19,7 @@ public:
void setLocalVersionData(StreamingVersionData *value);
StreamingVersionData *getServerVersionData() const;
void setServerVersonData(StreamingVersionData *value);
void setServerVersionData(StreamingVersionData *value);
private:
StreamingVersionData *localVersionData;