From 648fca13c511ca154deceb8da93bbdc9d2180866 Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 6 Nov 2025 23:12:13 +0800 Subject: [PATCH] =?UTF-8?q?up=EF=BC=9A=E5=9F=BA=E6=9C=AC=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=AE=8C=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 2 ++ .vscode/settings.json | 3 ++- ClientCore/ClientCore.cpp | 17 +++++++++++------ ClientCore/FileTrans.h | 4 +++- Gui/Control/CompareControl.cpp | 2 ++ Gui/Control/cusTableWidget.cpp | 1 + Gui/Form/Transform.cpp | 13 ++++++++----- Gui/Form/Transform.h | 2 +- Protocol/Protocol.h | 7 +++++++ Struct/InfoMsg.h | 4 ++-- Util/Util.cpp | 23 +++++++++++++++++++++-- Util/Util.h | 3 ++- 12 files changed, 62 insertions(+), 19 deletions(-) diff --git a/.clang-format b/.clang-format index df08a30..8431c74 100644 --- a/.clang-format +++ b/.clang-format @@ -5,6 +5,8 @@ AccessModifierOffset: -4 ReflowComments: true SpacesBeforeTrailingComments: 3 AllowShortFunctionsOnASingleLine: None +AllowShortEnumsOnASingleLine: false +AllowEnum BreakBeforeBraces: Custom BraceWrapping: AfterFunction: true diff --git a/.vscode/settings.json b/.vscode/settings.json index f2244eb..809c9a0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -145,7 +145,8 @@ "qgraphicsdropshadoweffect": "cpp", "qpushbutton": "cpp", "qpainter": "cpp", - "qdialog": "cpp" + "qdialog": "cpp", + "quuid": "cpp" }, "editor.tokenColorCustomizations": { "textMateRules": [ diff --git a/ClientCore/ClientCore.cpp b/ClientCore/ClientCore.cpp index 32c6656..c3bdfc3 100644 --- a/ClientCore/ClientCore.cpp +++ b/ClientCore/ClientCore.cpp @@ -87,14 +87,19 @@ void ClientCore::handleAsk(QSharedPointer frame) InfoMsg msg = infoUnpack(frame->data); // TODO: 处理询问请求 if (msg.command == STRMSG_AC_CHECK_FILE_EXIST) { - InfoMsg ans; - ans.command = STRMSG_AC_ANSWER_FILE_EXIST; - for (const auto& filePath : msg.list) { - if (!Util::FileExist(filePath)) { - ans.list.append(filePath); + msg.command = STRMSG_AC_ANSWER_FILE_EXIST; + for (auto& item : msg.mapData) { + if (item.mark == STRMSG_AC_UP) { + if (!Util::DirExist(item.key, true)) { + item.properD = static_cast(FCS_DIR_NOT_EXIST); + } + } else { + if (!Util::FileExist(item.key)) { + item.properD = static_cast(FCS_FILE_NOT_EXIST); + } } } - if (!Send(ans, FBT_MSGINFO_ANSWER, frame->fid)) { + if (!Send(msg, FBT_MSGINFO_ANSWER, frame->fid)) { auto logMsg = tr("给") + frame->fid + tr("返回检查文件存在性消息失败。"); qCritical() << logMsg; return; diff --git a/ClientCore/FileTrans.h b/ClientCore/FileTrans.h index 5d0c3bc..2ac2cfc 100644 --- a/ClientCore/FileTrans.h +++ b/ClientCore/FileTrans.h @@ -10,7 +10,6 @@ #include "ClientCore.h" constexpr int MAX_SEND_TASK = 10; - struct TransTask { bool isUpload{false}; QString localId; @@ -19,6 +18,9 @@ struct TransTask { QString remoteId; QString remotePath; QString remoteUUID; + QString taskUUID; + FileCheckState localCheckState{FCS_NORMAL}; + FileCheckState remoteCheckState{FCS_NORMAL}; }; enum class TaskState { diff --git a/Gui/Control/CompareControl.cpp b/Gui/Control/CompareControl.cpp index da57725..ddef514 100644 --- a/Gui/Control/CompareControl.cpp +++ b/Gui/Control/CompareControl.cpp @@ -310,6 +310,7 @@ void Compare::TransToLeft() const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 2); const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 1); TransTask task; + task.taskUUID = Util::UUID(); task.isUpload = false; task.localId = GlobalData::Ins()->GetLocalID(); task.localPath = itemT->text(); @@ -330,6 +331,7 @@ void Compare::TransToRight() const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 1); const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 2); TransTask task; + task.taskUUID = Util::UUID(); task.isUpload = true; task.localId = GlobalData::Ins()->GetLocalID(); task.localPath = Util::Join(itemF->text(), ui->tableWidget->item(indexList[i].row(), 0)->text()); diff --git a/Gui/Control/cusTableWidget.cpp b/Gui/Control/cusTableWidget.cpp index aef97a1..7da0a0a 100644 --- a/Gui/Control/cusTableWidget.cpp +++ b/Gui/Control/cusTableWidget.cpp @@ -56,6 +56,7 @@ void CustomTableWidget::dropEvent(QDropEvent* event) continue; } TransTask task; + task.taskUUID = Util::UUID(); task.isUpload = isRemote_; task.localId = oidCall_(); task.remoteId = ridCall_(); diff --git a/Gui/Form/Transform.cpp b/Gui/Form/Transform.cpp index 5bc53fb..bf83530 100644 --- a/Gui/Form/Transform.cpp +++ b/Gui/Form/Transform.cpp @@ -166,8 +166,8 @@ void CheckCondition::recvFrame(QSharedPointer frame) { InfoMsg info = infoUnpack(frame->data); if (info.command == STRMSG_AC_ANSWER_FILE_EXIST) { - remoteNotExits_ = info.list; - qInfo() << tr("检查结束,远端不存在的文件数:") << remoteNotExits_.size(); + infoMsg_ = info; + qInfo() << tr("检查结束......"); msg_ = info.command; return; } @@ -192,10 +192,12 @@ void CheckCondition::run() isAlreadyInter_ = false; // 先检查本地文件是否存在 - for (const auto& task : tasks_) { + for (auto& task : tasks_) { if (task.isUpload && !Util::FileExist(task.localPath)) { + task.localCheckState = FCS_FILE_NOT_EXIST; } - if (!task.isUpload && Util::FileExist(task.localPath)) { + if (!task.isUpload && !Util::DirExist(task.localPath, true)) { + task.localCheckState = FCS_DIR_NOT_EXIST; } } @@ -203,7 +205,8 @@ void CheckCondition::run() InfoMsg msg; msg.command = STRMSG_AC_CHECK_FILE_EXIST; for (const auto& task : tasks_) { - msg.list.push_back(task.remotePath); + msg.mapData[task.taskUUID].mark = task.isUpload ? STRMSG_AC_UP : STRMSG_AC_DOWN; + msg.mapData[task.taskUUID].key = task.remotePath; } auto f = clientCore_->GetBuffer(msg, FBT_MSGINFO_ASK, clientCore_->GetRemoteID()); diff --git a/Gui/Form/Transform.h b/Gui/Form/Transform.h index 057500b..1c6bf74 100644 --- a/Gui/Form/Transform.h +++ b/Gui/Form/Transform.h @@ -102,7 +102,7 @@ private: bool isAlreadyInter_; QVector tasks_; ClientCore* clientCore_{}; - QVector remoteNotExits_; + InfoMsg infoMsg_; }; #endif // TRANSFORM_H \ No newline at end of file diff --git a/Protocol/Protocol.h b/Protocol/Protocol.h index a4df797..a9f94ea 100644 --- a/Protocol/Protocol.h +++ b/Protocol/Protocol.h @@ -59,6 +59,11 @@ public: static QByteArray PackBuffer(const QSharedPointer& frame); }; +enum FileCheckState { + FCS_NORMAL = 0, + FCS_DIR_NOT_EXIST, + FCS_FILE_NOT_EXIST +}; // 字符串标识 #define STRMSG_AC_CHECK_FILE_EXIST "requestCheckFileExist" @@ -73,6 +78,8 @@ public: #define STRMSG_AC_ANSWER_NEW_DIR "answerNewDir" #define STRMSG_AC_ASK_FILEINFO "requestFileInfo" #define STRMSG_AC_ANSWER_FILEINFO "answerFileInfo" +#define STRMSG_AC_UP "upAction" +#define STRMSG_AC_DOWN "downAction" #define STRMSG_ST_FILEEXIT "fileExist" #define STRMSG_ST_FILENOEXIT "fileNotExist" diff --git a/Struct/InfoMsg.h b/Struct/InfoMsg.h index 1ce7968..4a6b922 100644 --- a/Struct/InfoMsg.h +++ b/Struct/InfoMsg.h @@ -14,8 +14,8 @@ struct PropertyData { QString properA; QString properB; QString properC; - QString properD; - QString properE; + qint32 properD; + qint32 properE; }; struct InfoMsg { diff --git a/Util/Util.cpp b/Util/Util.cpp index bbfd52c..34ae38b 100644 --- a/Util/Util.cpp +++ b/Util/Util.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -130,9 +131,27 @@ bool Util::FileExist(const QString& path) return QFile::exists(path); } -bool Util::DirExist(const QString& path) +bool Util::DirExist(const QString& path, bool isFilePath) { - return QDir(path).exists(); + if (path.isEmpty()) { + return false; + } + + QString dirPath = path; + if (isFilePath) { + QFileInfo fileInfo(path); + dirPath = fileInfo.absolutePath(); + } else { + QFileInfo dirInfo(path); + dirPath = dirInfo.absoluteFilePath(); + } + QDir dir(dirPath); + return dir.exists(); +} + +QString Util::UUID() +{ + return QUuid::createUuid().toString().remove("{").remove("}"); } QString DirFileHelper::GetErr() const diff --git a/Util/Util.h b/Util/Util.h index 2d116b0..81c7cbf 100644 --- a/Util/Util.h +++ b/Util/Util.h @@ -50,7 +50,8 @@ public: static void ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg); static QString GetVersion(); static bool FileExist(const QString& path); - static bool DirExist(const QString& path); + static bool DirExist(const QString& path, bool isFilePath); + static QString UUID(); }; class DirFileHelper : public QObject