mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
fix: reconnect with old connection
This commit is contained in:
@@ -9,6 +9,7 @@ UpdateController::UpdateController(QObject *parent) :
|
||||
versionContainer(nullptr)
|
||||
{
|
||||
applicationFolderPath = QDir::currentPath() + applicationFolderName;
|
||||
hashCalculator = new FastHashCalculator;
|
||||
}
|
||||
|
||||
void UpdateController::initialize(VersionContainer *versionContainer,DataParserOutput *dataParserOut, SendSystem *sendSystem)
|
||||
@@ -16,7 +17,6 @@ void UpdateController::initialize(VersionContainer *versionContainer,DataParserO
|
||||
this->versionContainer = versionContainer;
|
||||
this->sendSystem = sendSystem;
|
||||
this->dataParserOut = dataParserOut;
|
||||
hashCalculator = new FastHashCalculator;
|
||||
}
|
||||
|
||||
void UpdateController::calculateCommonHash()
|
||||
@@ -56,7 +56,6 @@ QList<FileData> UpdateController::calculateHash(const QString& path,const QStrin
|
||||
}
|
||||
|
||||
QList<FileData> *hashes = new QList<FileData>;
|
||||
QString fullSize = Tools::convertFileSize(getDirectorySize(path),false);
|
||||
quint64 currentSize = 0;
|
||||
|
||||
QStringList filter;
|
||||
@@ -93,7 +92,7 @@ QList<FileData> UpdateController::calculateHash(const QString& path,const QStrin
|
||||
|
||||
currentSize += fileInfo.size();
|
||||
|
||||
emit sigSendHashInfo(fullSize,Tools::convertFileSize(currentSize,false));
|
||||
|
||||
quint64 fileSize = file.size(); //буффер для хэширования крупных файлов
|
||||
const quint64 bufferSize = 1024;
|
||||
|
||||
@@ -126,24 +125,6 @@ QList<FileData> UpdateController::calculateHash(const QString& path,const QStrin
|
||||
return *hashes;
|
||||
}
|
||||
|
||||
quint64 UpdateController::getDirectorySize(const QString& path)
|
||||
{
|
||||
quint64 totalSize = 0;
|
||||
QDirIterator iterator(path, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
iterator.next();
|
||||
QFileInfo fileInfo = iterator.fileInfo();
|
||||
if (fileInfo.isFile())
|
||||
{
|
||||
totalSize += fileInfo.size();
|
||||
}
|
||||
}
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
void UpdateController::updateFilesOnServer(QList<FileData> *fileSendList){
|
||||
|
||||
QListIterator<FileData> serverIterator(*fileSendList);
|
||||
@@ -177,6 +158,11 @@ void UpdateController::updateFilesOnServer(QList<FileData> *fileSendList){
|
||||
|
||||
}
|
||||
|
||||
FastHashCalculator *UpdateController::getHashCalculator() const
|
||||
{
|
||||
return hashCalculator;
|
||||
}
|
||||
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
{
|
||||
|
||||
@@ -35,9 +35,11 @@ public:
|
||||
void updateFilesOnServer(QList<FileData> *fileSendList);
|
||||
void checkCanUpdate();
|
||||
|
||||
FastHashCalculator *getHashCalculator() const;
|
||||
|
||||
signals:
|
||||
void sigUpdateComplete(bool flag);
|
||||
void sigSendHashInfo(QString fullSize,QString current);
|
||||
|
||||
private:
|
||||
SendSystem *sendSystem;
|
||||
DataParserOutput * dataParserOut;
|
||||
@@ -48,7 +50,6 @@ private:
|
||||
QList<FileData> streamingDataList;
|
||||
|
||||
QList<FileData> calculateHash(const QString& path,const QString& ignoreName);
|
||||
quint64 getDirectorySize(const QString &path);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ FastHashCalculator::FastHashCalculator(QObject *parent) : QObject(parent)
|
||||
void FastHashCalculator::calculateHashes(const QString& path, const QString& ignoreName)
|
||||
{
|
||||
hashList->clear();
|
||||
|
||||
currentSize = 0;
|
||||
if(!QDir(path).exists()){
|
||||
QDir().mkdir(path);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ void FastHashCalculator::calculateHashes(const QString& path, const QString& ign
|
||||
QStringList filter;
|
||||
filter << "*";
|
||||
QList<FileData> *folders = new QList<FileData>;
|
||||
//QString fullSize = Tools::convertFileSize(getDirectorySize(path),false);
|
||||
fullSize = Tools::convertFileSize(getDirectorySize(path),false);
|
||||
|
||||
QDirIterator dirIterator(path,filter, QDir::AllEntries, QDirIterator::Subdirectories);
|
||||
|
||||
@@ -80,18 +80,45 @@ QByteArray FastHashCalculator::calculateFileHashOptimized(const QString &filePat
|
||||
if (!file.open(QIODevice::ReadOnly)) return QByteArray();
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||
const qint64 bufferSize = 2 * 1024; // 2MB
|
||||
const qint64 bufferSize = 2048; // 2MB
|
||||
quint64 completeBytes = 0;
|
||||
QByteArray buffer;
|
||||
buffer.resize(bufferSize);
|
||||
|
||||
while (!file.atEnd()) {
|
||||
qint64 bytesRead = file.read(buffer.data(), bufferSize);
|
||||
hash.addData(buffer.constData(), bytesRead);
|
||||
completeBytes += bytesRead;
|
||||
}
|
||||
|
||||
hashCounterDisplay(completeBytes);
|
||||
return hash.result();
|
||||
}
|
||||
|
||||
void FastHashCalculator::hashCounterDisplay(quint64 size)
|
||||
{
|
||||
currentSize += size;
|
||||
emit sigSendHashInfo(fullSize,Tools::convertFileSize(currentSize,false));
|
||||
}
|
||||
|
||||
quint64 FastHashCalculator::getDirectorySize(const QString& path)
|
||||
{
|
||||
quint64 totalSize = 0;
|
||||
QDirIterator iterator(path, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
iterator.next();
|
||||
QFileInfo fileInfo = iterator.fileInfo();
|
||||
if (fileInfo.isFile())
|
||||
{
|
||||
totalSize += fileInfo.size();
|
||||
}
|
||||
}
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
QList<FileData> *FastHashCalculator::getHashList() const
|
||||
{
|
||||
return hashList;
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
QList<FileData> *getHashList() const;
|
||||
|
||||
signals:
|
||||
void sigSendHashInfo(QString fullSize,QString current);
|
||||
void finished();
|
||||
|
||||
private:
|
||||
@@ -27,8 +28,11 @@ private:
|
||||
|
||||
QList<FileData>* hashList;
|
||||
QMutex _mutex;
|
||||
QString fullSize;
|
||||
quint64 currentSize;
|
||||
|
||||
quint64 getDirectorySize(const QString &path);
|
||||
void hashCounterDisplay(quint64 size);
|
||||
};
|
||||
|
||||
#endif // FASTHASHCALCULATOR_H
|
||||
|
||||
Reference in New Issue
Block a user