From d209d640612f638d129d66a2f3b20d7a71ec09c9 Mon Sep 17 00:00:00 2001 From: taynpg Date: Sat, 8 Nov 2025 21:51:42 +0800 Subject: [PATCH] =?UTF-8?q?over=EF=BC=9A=E6=96=87=E4=BB=B6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=80=A7=E6=A0=A1=E9=AA=8C=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClientCore/ClientCore.cpp | 10 +++++-- ClientCore/FileTrans.cpp | 17 ++++++++++++ Gui/Form/Transform.cpp | 11 ++++++-- Gui/frelayGUI.cpp | 58 +++++++++++++++++++++++++++------------ Note/version.md | 4 +-- Protocol/Protocol.h | 3 +- Struct/InfoMsg.h | 10 +++---- 7 files changed, 83 insertions(+), 30 deletions(-) diff --git a/ClientCore/ClientCore.cpp b/ClientCore/ClientCore.cpp index 061fe92..ef60ce2 100644 --- a/ClientCore/ClientCore.cpp +++ b/ClientCore/ClientCore.cpp @@ -90,11 +90,17 @@ void ClientCore::handleAsk(QSharedPointer frame) msg.command = STRMSG_AC_ANSWER_FILE_EXIST; for (auto& item : msg.mapData) { if (item.command == STRMSG_AC_UP) { - if (!Util::DirExist(item.path, false)) { + if (!Util::DirExist(item.remotePath, false)) { item.state = static_cast(FCS_DIR_NOT_EXIST); + continue; + } + auto newerPath = Util::Get2FilePath(item.localPath, item.remotePath); + if (Util::FileExist(newerPath)) { + item.state = static_cast(FCS_FILE_EXIST); + continue; } } else { - if (!Util::FileExist(item.path)) { + if (!Util::FileExist(item.localPath)) { item.state = static_cast(FCS_FILE_NOT_EXIST); } } diff --git a/ClientCore/FileTrans.cpp b/ClientCore/FileTrans.cpp index b7634d3..563cfa4 100644 --- a/ClientCore/FileTrans.cpp +++ b/ClientCore/FileTrans.cpp @@ -77,6 +77,22 @@ void FileTrans::ReqDownFile(const TransTask& task) downTask_->task = task; downTask_->totalSize = 0; + + // recv + if (!Util::DirExist(info.toPath, false)) { + QDir dir; + if (!dir.mkpath(info.toPath)) { + info.msg = QString(tr("创建目录失败:%1")).arg(info.toPath); + qCritical() << info.msg; + auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, task.remoteId); + if (!ClientCore::syncInvoke(clientCore_, f)) { + qCritical() << QString(tr("%1 回复 %2 失败。")).arg(info.msg, f->fid); + } + return; + } + qInfo() << QString(tr("目录 %1 不存在,已自动创建。")).arg(info.toPath); + } + downTask_->file.setFileName(Util::Get2FilePath(task.remotePath, task.localPath)); if (!downTask_->file.open(QIODevice::WriteOnly)) { qCritical() << QString(tr("打开文件 [%1] 失败。")).arg(downTask_->file.fileName()); @@ -178,6 +194,7 @@ void FileTrans::fbtReqSend(QSharedPointer frame) } qInfo() << QString(tr("目录 %1 不存在,已自动创建。")).arg(info.toPath); } + auto newerPath = Util::Get2FilePath(info.fromPath, info.toPath); downTask_->file.setFileName(newerPath); if (!downTask_->file.open(QIODevice::WriteOnly)) { diff --git a/Gui/Form/Transform.cpp b/Gui/Form/Transform.cpp index 133c873..9bddf04 100644 --- a/Gui/Form/Transform.cpp +++ b/Gui/Form/Transform.cpp @@ -210,8 +210,12 @@ void CheckCondition::run() if (task.isUpload && !Util::FileExist(task.localPath)) { task.localCheckState = FCS_FILE_NOT_EXIST; } - if (!task.isUpload && !Util::DirExist(task.localPath, true)) { - task.localCheckState = FCS_DIR_NOT_EXIST; + if (!task.isUpload) { + if (!Util::DirExist(task.localPath, false)) { + task.localCheckState = FCS_DIR_NOT_EXIST; + } else if (Util::FileExist(task.localPath)) { + task.localCheckState = FCS_FILE_EXIST; + } } } @@ -222,7 +226,8 @@ void CheckCondition::run() for (auto& task : tasks_) { msg.mapData[task.taskUUID].uuid = task.taskUUID; msg.mapData[task.taskUUID].command = task.isUpload ? STRMSG_AC_UP : STRMSG_AC_DOWN; - msg.mapData[task.taskUUID].path = task.remotePath; + msg.mapData[task.taskUUID].localPath = task.localPath; + msg.mapData[task.taskUUID].remotePath = task.remotePath; } auto f = clientCore_->GetBuffer(msg, FBT_MSGINFO_ASK, clientCore_->GetRemoteID()); diff --git a/Gui/frelayGUI.cpp b/Gui/frelayGUI.cpp index ab6c49f..a4b4fdb 100644 --- a/Gui/frelayGUI.cpp +++ b/Gui/frelayGUI.cpp @@ -7,9 +7,9 @@ #include #include #include -#include "Control/Common.h" #include "./ui_frelayGUI.h" +#include "Control/Common.h" #include "Control/LogControl.h" static LogPrint* logPrint = nullptr; @@ -171,46 +171,70 @@ void frelayGUI::HandleTask(const QVector& tasks) bool frelayGUI::CheckTaskResult(QVector& tasks) { - bool isAccept = false; + bool isAutoCreateDirR = false; + bool isAutoRecoverR = false; + bool isAutoCreateDirL = false; + bool isAutoRecoverL = false; + for (auto& task : tasks) { if (task.localCheckState == FCS_NORMAL && task.remoteCheckState == FCS_NORMAL) { continue; } if (task.isUpload) { - if (task.localCheckState != FCS_NORMAL) { + if (task.localCheckState == FCS_FILE_NOT_EXIST) { QMessageBox::information(this, tr("文件校验"), tr("本地文件校验失败,请检查文件是否存在:") + task.localPath); return false; } - if (task.remoteCheckState != FCS_NORMAL && !isAccept) { + if (task.remoteCheckState == FCS_DIR_NOT_EXIST && !isAutoCreateDirR) { auto msg = tr("远端不存在文件夹") + task.remotePath + ",需要自动创建吗?"; - auto ret =Common::GetAcceptThree(this, "操作确认", msg); + auto ret = Common::GetAcceptThree(this, "操作确认", msg); if (ret == 0) { continue; - } - else if (ret == 1) { - isAccept = true; + } else if (ret == 1) { + isAutoCreateDirR = true; continue; + } else { + return false; } - else { + } + if (task.remoteCheckState == FCS_FILE_EXIST && !isAutoRecoverR) { + auto msg = tr("远端已存在文件") + Util::Get2FilePath(task.localPath, task.remotePath) + ",需要覆盖吗?"; + auto ret = Common::GetAcceptThree(this, "操作警告", msg); + if (ret == 0) { + continue; + } else if (ret == 1) { + isAutoRecoverR = true; + continue; + } else { return false; } } } else { - if (task.localCheckState != FCS_NORMAL) { + if (task.localCheckState == FCS_DIR_NOT_EXIST && !isAutoCreateDirL) { auto msg = tr("本地不存在文件夹") + task.localPath + ",需要自动创建吗?"; - auto ret =Common::GetAcceptThree(this, "操作确认", msg); + auto ret = Common::GetAcceptThree(this, "操作确认", msg); if (ret == 0) { continue; - } - else if (ret == 1) { - isAccept = true; + } else if (ret == 1) { + isAutoCreateDirL = true; continue; - } - else { + } else { return false; } } - if (task.remoteCheckState != FCS_NORMAL) { + if (task.localCheckState == FCS_FILE_EXIST && !isAutoRecoverL) { + auto msg = tr("本地已经存在文件") + Util::Get2FilePath(task.remotePath, task.localPath) + ",需要覆盖吗?"; + auto ret = Common::GetAcceptThree(this, "操作警告", msg); + if (ret == 0) { + continue; + } else if (ret == 1) { + isAutoRecoverL = true; + continue; + } else { + return false; + } + } + if (task.remoteCheckState != FCS_FILE_EXIST) { QMessageBox::information(this, tr("文件校验"), tr("远端文件校验失败,请检查文件是否存在:") + task.remotePath); return false; } diff --git a/Note/version.md b/Note/version.md index 4a57532..d8f8b73 100644 --- a/Note/version.md +++ b/Note/version.md @@ -9,7 +9,7 @@ | 序号 | 类型 | 内容 | 说明 | 基于版本 | 完成版本 | | :--: | :--: | ------------------------------------------------------------ | :--: | :------: | :------: | | 28 | 变更 | 语言简体中文。 | | 0.2.2 | 0.2.3 | -| 27 | 功能 | 传输前检查对方或者自己是否已存在某些文件,提示是否覆盖。 | | 0.2.2 | | +| 27 | 功能 | 传输前检查对方或者自己是否已存在某些文件,提示是否覆盖。 | | 0.2.2 | 0.2.3 | | 26 | 功能 | 最好能保存关闭界面时Splitter和UI的尺寸。 | | 0.2.2 | | | 25 | 功能 | 手动输入的文件夹访问路径保存历史记录,以便后续可能再次使用(10条)。 | | 0.2.2 | | | 24 | 问题 | 发送端如果发送的数据比较大,UI会卡住(功能是正常的)。 | | 0.2.2 | | @@ -24,7 +24,7 @@ | 15 | 问题 | 拖动文件夹到对方,应当不处理,并日志提示。 | | 0.1 | 0.2 | | 14 | 功能 | 文件浏览部分添加右键复制全路径功能。 | | 0.1 | 0.2 | | 13 | 功能 | IP端口部分要添加可选择历史。 | | 0.1 | 0.2 | -| 12 | 功能 | 对照传输前要先校验文件存在性。 | | 0.1 | | +| 12 | 功能 | 对照传输前要先校验文件存在性。 | | 0.1 | 0.2.3 | | 11 | 问题 | 断连后当前远端ID要清除。 | | 0.1 | 0.2 | | 10 | 功能 | 对照传输可以支持反向下载。 | | 0.1 | 0.2 | | 9 | 优化 | 输入路径后可以直接回车访问。 | | 0.1 | 0.2 | diff --git a/Protocol/Protocol.h b/Protocol/Protocol.h index 456a4aa..7ae650e 100644 --- a/Protocol/Protocol.h +++ b/Protocol/Protocol.h @@ -62,7 +62,8 @@ public: enum FileCheckState { FCS_NORMAL = 0, FCS_DIR_NOT_EXIST, - FCS_FILE_NOT_EXIST + FCS_FILE_NOT_EXIST, + FCS_FILE_EXIST }; // 字符串标识 diff --git a/Struct/InfoMsg.h b/Struct/InfoMsg.h index 45ddc0c..93f156d 100644 --- a/Struct/InfoMsg.h +++ b/Struct/InfoMsg.h @@ -12,8 +12,8 @@ struct PropertyData { QString uuid; QString command; QString userAction; - QString path; - QString properC; + QString localPath; + QString remotePath; qint32 state; qint32 properE; }; @@ -40,7 +40,7 @@ struct InfoMsg { for (auto it = mapData.constBegin(); it != mapData.constEnd(); ++it) { data << it.key(); data << it.value().uuid << it.value().command << it.value().userAction - << it.value().path << it.value().properC << it.value().state << it.value().properE; + << it.value().localPath << it.value().remotePath << it.value().state << it.value().properE; } } @@ -62,8 +62,8 @@ struct InfoMsg { QString key; PropertyData prop; data >> key; - data >> prop.uuid >> prop.command >> prop.userAction >> prop.path - >> prop.properC >> prop.state >> prop.properE; + data >> prop.uuid >> prop.command >> prop.userAction >> prop.localPath + >> prop.remotePath >> prop.state >> prop.properE; mapData.insert(key, prop); } }