@@ -339,8 +339,8 @@ MainWindow::MainWindow(QWidget *parent)
339339 " Transferring: (" + formatByteSpeed (current_file_size) +
340340 " / " + formatByteSpeed (current_total_file_size) +
341341 " ) @ " + formatByteSpeed (bytesReceivedThisSecond * 10 ) + " /s" +
342- (filesToRecieve > 0 ? " Files Left: " + QString::number (filesToRecieve) : " " )
343- );
342+ (filesToRecieve > 0 ? " Files Left: " + QString::number (filesToRecieve) : " " ) +
343+ (fileQueue. length () > 0 ? " Files Left: " + QString::number (fileQueue. length ()) : " " ) );
344344 bytesReceivedThisSecond = 0 ;
345345 });
346346
@@ -681,6 +681,15 @@ MainWindow::MainWindow(QWidget *parent)
681681 QString relPath = fileObj[" path" ].toString ();
682682 QString remoteHash = fileObj[" hash" ].toString ();
683683
684+ if (ui->ActivateEncryption ->isChecked ())
685+ {
686+ if (recCipher == nullptr ) return ;
687+
688+ QByteArray relpathArray = QByteArray::fromBase64 (relPath.toUtf8 ());
689+ recCipher->process (relpathArray);
690+ relPath = QString::fromUtf8 (relpathArray);
691+ }
692+
684693 QString fullLocalPath = rootPath + relPath;
685694 QFileInfo checkFile (fullLocalPath);
686695
@@ -690,6 +699,15 @@ MainWindow::MainWindow(QWidget *parent)
690699 QString localHash = QString::number (info.size ());
691700 if (localHash == remoteHash)
692701 {
702+ if (ui->ActivateEncryption ->isChecked ())
703+ {
704+ if (sendCipher == nullptr ) return ;
705+
706+ QByteArray relPathArray = relPath.toUtf8 ();
707+ sendCipher->process (relPathArray);
708+ relPath = relPathArray.toBase64 ();
709+ }
710+
693711 skipList.append (relPath); // It matches! Tell sender to skip it.
694712 filesToRecieve--; // Lower the expected file count
695713 }
@@ -859,6 +877,19 @@ MainWindow::MainWindow(QWidget *parent)
859877 QString filePath = obj[" file_path" ].toString ();
860878 QString remoteHash = obj[" hash" ].toString ();
861879
880+ if (ui->ActivateEncryption ->isChecked ())
881+ {
882+ if (recCipher == nullptr ) return ;
883+ QByteArray filePathArray = QByteArray::fromBase64 (filePath.toUtf8 ());
884+ QByteArray remoteHashArray = QByteArray::fromBase64 (remoteHash.toUtf8 ());
885+
886+ recCipher->process (filePathArray);
887+ recCipher->process (remoteHashArray);
888+
889+ filePath = QString::fromUtf8 (filePathArray);
890+ remoteHash = QString::fromUtf8 (remoteHashArray);
891+ }
892+
862893 // Determine where the file WOULD be saved based on current state
863894 QString fullLocalPath;
864895 if (sendingFolder) {
@@ -944,10 +975,20 @@ MainWindow::MainWindow(QWidget *parent)
944975 {
945976 QJsonArray skipList = obj[" skip_list" ].toArray ();
946977
947- // Convert the JSON array to a quick lookup list
948978 QStringList filesToSkip;
949979 for (int i = 0 ; i < skipList.size (); ++i) {
950- filesToSkip.append (skipList[i].toString ());
980+ QString fileToSkip = skipList[i].toString ();
981+
982+ if (ui->ActivateEncryption ->isChecked ())
983+ {
984+ if (recCipher == nullptr ) return ;
985+ QByteArray fileToSkipArray = QByteArray::fromBase64 (fileToSkip.toUtf8 ());
986+ recCipher->process (fileToSkipArray);
987+
988+ fileToSkip = QString::fromUtf8 (fileToSkipArray);
989+ }
990+
991+ filesToSkip.append (fileToSkip);
951992 }
952993
953994 // Filter our fileQueue
@@ -1323,10 +1364,26 @@ void MainWindow::sendFile(bool runCheck = true)
13231364 {
13241365 QJsonObject jsonMessage;
13251366 jsonMessage[" type" ] = " file_check" ;
1326- jsonMessage[" file_path" ] = fileName;
1327- jsonMessage[" hash" ] = fileChecksum (selectedFilePath, QCryptographicHash::Sha256);
13281367 jsonMessage[" to" ] = pairPartnerId;
13291368
1369+ if (ui->ActivateEncryption ->isChecked ())
1370+ {
1371+ QByteArray fileNameArray = fileName.toUtf8 ();
1372+ QByteArray hashArray = fileChecksum (selectedFilePath, QCryptographicHash::Sha256).toUtf8 ();
1373+
1374+ if (sendCipher == nullptr ) return ;
1375+ sendCipher->process (fileNameArray);
1376+ sendCipher->process (hashArray);
1377+
1378+ jsonMessage[" file_path" ] = QString (fileNameArray.toBase64 ());
1379+ jsonMessage[" hash" ] = QString (hashArray.toBase64 ());
1380+ }
1381+ else
1382+ {
1383+ jsonMessage[" file_path" ] = fileName;
1384+ jsonMessage[" hash" ] = fileChecksum (selectedFilePath, QCryptographicHash::Sha256);
1385+ }
1386+
13301387 QJsonDocument doc (jsonMessage);
13311388 QString jsonString = doc.toJson (QJsonDocument::Compact) + ' \n ' ;
13321389 socket->write (jsonString.toUtf8 ());
@@ -1606,6 +1663,14 @@ void MainWindow::sendDirectories()
16061663 // Calculate the hash (or metadata) right now
16071664 QString relativePath = QString (filePath).replace (selectedFolderPath, " " );
16081665
1666+ if (ui->ActivateEncryption ->isChecked ())
1667+ {
1668+ if (sendCipher == nullptr ) return ;
1669+ QByteArray relativePathArray = relativePath.toUtf8 ();
1670+ sendCipher->process (relativePathArray);
1671+ relativePath = relativePathArray.toBase64 ();
1672+ }
1673+
16091674 QJsonObject fileInfo;
16101675 fileInfo[" path" ] = relativePath;
16111676
0 commit comments