over:文件存在性校验功能完成。

This commit is contained in:
2025-11-08 21:51:42 +08:00
parent f8bbf02e04
commit d209d64061
7 changed files with 83 additions and 30 deletions

View File

@@ -90,11 +90,17 @@ void ClientCore::handleAsk(QSharedPointer<FrameBuffer> frame)
msg.command = STRMSG_AC_ANSWER_FILE_EXIST; msg.command = STRMSG_AC_ANSWER_FILE_EXIST;
for (auto& item : msg.mapData) { for (auto& item : msg.mapData) {
if (item.command == STRMSG_AC_UP) { if (item.command == STRMSG_AC_UP) {
if (!Util::DirExist(item.path, false)) { if (!Util::DirExist(item.remotePath, false)) {
item.state = static_cast<qint32>(FCS_DIR_NOT_EXIST); item.state = static_cast<qint32>(FCS_DIR_NOT_EXIST);
continue;
}
auto newerPath = Util::Get2FilePath(item.localPath, item.remotePath);
if (Util::FileExist(newerPath)) {
item.state = static_cast<qint32>(FCS_FILE_EXIST);
continue;
} }
} else { } else {
if (!Util::FileExist(item.path)) { if (!Util::FileExist(item.localPath)) {
item.state = static_cast<qint32>(FCS_FILE_NOT_EXIST); item.state = static_cast<qint32>(FCS_FILE_NOT_EXIST);
} }
} }

View File

@@ -77,6 +77,22 @@ void FileTrans::ReqDownFile(const TransTask& task)
downTask_->task = task; downTask_->task = task;
downTask_->totalSize = 0; 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)); downTask_->file.setFileName(Util::Get2FilePath(task.remotePath, task.localPath));
if (!downTask_->file.open(QIODevice::WriteOnly)) { if (!downTask_->file.open(QIODevice::WriteOnly)) {
qCritical() << QString(tr("打开文件 [%1] 失败。")).arg(downTask_->file.fileName()); qCritical() << QString(tr("打开文件 [%1] 失败。")).arg(downTask_->file.fileName());
@@ -178,6 +194,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
} }
qInfo() << QString(tr("目录 %1 不存在,已自动创建。")).arg(info.toPath); qInfo() << QString(tr("目录 %1 不存在,已自动创建。")).arg(info.toPath);
} }
auto newerPath = Util::Get2FilePath(info.fromPath, info.toPath); auto newerPath = Util::Get2FilePath(info.fromPath, info.toPath);
downTask_->file.setFileName(newerPath); downTask_->file.setFileName(newerPath);
if (!downTask_->file.open(QIODevice::WriteOnly)) { if (!downTask_->file.open(QIODevice::WriteOnly)) {

View File

@@ -210,8 +210,12 @@ void CheckCondition::run()
if (task.isUpload && !Util::FileExist(task.localPath)) { if (task.isUpload && !Util::FileExist(task.localPath)) {
task.localCheckState = FCS_FILE_NOT_EXIST; task.localCheckState = FCS_FILE_NOT_EXIST;
} }
if (!task.isUpload && !Util::DirExist(task.localPath, true)) { if (!task.isUpload) {
if (!Util::DirExist(task.localPath, false)) {
task.localCheckState = FCS_DIR_NOT_EXIST; 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_) { for (auto& task : tasks_) {
msg.mapData[task.taskUUID].uuid = task.taskUUID; msg.mapData[task.taskUUID].uuid = task.taskUUID;
msg.mapData[task.taskUUID].command = task.isUpload ? STRMSG_AC_UP : STRMSG_AC_DOWN; 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()); auto f = clientCore_->GetBuffer(msg, FBT_MSGINFO_ASK, clientCore_->GetRemoteID());

View File

@@ -7,9 +7,9 @@
#include <QSplitter> #include <QSplitter>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <fversion.h> #include <fversion.h>
#include "Control/Common.h"
#include "./ui_frelayGUI.h" #include "./ui_frelayGUI.h"
#include "Control/Common.h"
#include "Control/LogControl.h" #include "Control/LogControl.h"
static LogPrint* logPrint = nullptr; static LogPrint* logPrint = nullptr;
@@ -171,46 +171,70 @@ void frelayGUI::HandleTask(const QVector<TransTask>& tasks)
bool frelayGUI::CheckTaskResult(QVector<TransTask>& tasks) bool frelayGUI::CheckTaskResult(QVector<TransTask>& tasks)
{ {
bool isAccept = false; bool isAutoCreateDirR = false;
bool isAutoRecoverR = false;
bool isAutoCreateDirL = false;
bool isAutoRecoverL = false;
for (auto& task : tasks) { for (auto& task : tasks) {
if (task.localCheckState == FCS_NORMAL && task.remoteCheckState == FCS_NORMAL) { if (task.localCheckState == FCS_NORMAL && task.remoteCheckState == FCS_NORMAL) {
continue; continue;
} }
if (task.isUpload) { if (task.isUpload) {
if (task.localCheckState != FCS_NORMAL) { if (task.localCheckState == FCS_FILE_NOT_EXIST) {
QMessageBox::information(this, tr("文件校验"), tr("本地文件校验失败,请检查文件是否存在:") + task.localPath); QMessageBox::information(this, tr("文件校验"), tr("本地文件校验失败,请检查文件是否存在:") + task.localPath);
return false; return false;
} }
if (task.remoteCheckState != FCS_NORMAL && !isAccept) { if (task.remoteCheckState == FCS_DIR_NOT_EXIST && !isAutoCreateDirR) {
auto msg = tr("远端不存在文件夹") + task.remotePath + ",需要自动创建吗?"; auto msg = tr("远端不存在文件夹") + task.remotePath + ",需要自动创建吗?";
auto ret = Common::GetAcceptThree(this, "操作确认", msg); auto ret = Common::GetAcceptThree(this, "操作确认", msg);
if (ret == 0) { if (ret == 0) {
continue; continue;
} } else if (ret == 1) {
else if (ret == 1) { isAutoCreateDirR = true;
isAccept = true;
continue; 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; return false;
} }
} }
} else { } else {
if (task.localCheckState != FCS_NORMAL) { if (task.localCheckState == FCS_DIR_NOT_EXIST && !isAutoCreateDirL) {
auto msg = tr("本地不存在文件夹") + task.localPath + ",需要自动创建吗?"; auto msg = tr("本地不存在文件夹") + task.localPath + ",需要自动创建吗?";
auto ret = Common::GetAcceptThree(this, "操作确认", msg); auto ret = Common::GetAcceptThree(this, "操作确认", msg);
if (ret == 0) { if (ret == 0) {
continue; continue;
} } else if (ret == 1) {
else if (ret == 1) { isAutoCreateDirL = true;
isAccept = true;
continue; continue;
} } else {
else {
return false; 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); QMessageBox::information(this, tr("文件校验"), tr("远端文件校验失败,请检查文件是否存在:") + task.remotePath);
return false; return false;
} }

View File

@@ -9,7 +9,7 @@
| 序号 | 类型 | 内容 | 说明 | 基于版本 | 完成版本 | | 序号 | 类型 | 内容 | 说明 | 基于版本 | 完成版本 |
| :--: | :--: | ------------------------------------------------------------ | :--: | :------: | :------: | | :--: | :--: | ------------------------------------------------------------ | :--: | :------: | :------: |
| 28 | 变更 | 语言简体中文。 | | 0.2.2 | 0.2.3 | | 28 | 变更 | 语言简体中文。 | | 0.2.2 | 0.2.3 |
| 27 | 功能 | 传输前检查对方或者自己是否已存在某些文件,提示是否覆盖。 | | 0.2.2 | | | 27 | 功能 | 传输前检查对方或者自己是否已存在某些文件,提示是否覆盖。 | | 0.2.2 | 0.2.3 |
| 26 | 功能 | 最好能保存关闭界面时Splitter和UI的尺寸。 | | 0.2.2 | | | 26 | 功能 | 最好能保存关闭界面时Splitter和UI的尺寸。 | | 0.2.2 | |
| 25 | 功能 | 手动输入的文件夹访问路径保存历史记录,以便后续可能再次使用(10条)。 | | 0.2.2 | | | 25 | 功能 | 手动输入的文件夹访问路径保存历史记录,以便后续可能再次使用(10条)。 | | 0.2.2 | |
| 24 | 问题 | 发送端如果发送的数据比较大,UI会卡住(功能是正常的)。 | | 0.2.2 | | | 24 | 问题 | 发送端如果发送的数据比较大,UI会卡住(功能是正常的)。 | | 0.2.2 | |
@@ -24,7 +24,7 @@
| 15 | 问题 | 拖动文件夹到对方,应当不处理,并日志提示。 | | 0.1 | 0.2 | | 15 | 问题 | 拖动文件夹到对方,应当不处理,并日志提示。 | | 0.1 | 0.2 |
| 14 | 功能 | 文件浏览部分添加右键复制全路径功能。 | | 0.1 | 0.2 | | 14 | 功能 | 文件浏览部分添加右键复制全路径功能。 | | 0.1 | 0.2 |
| 13 | 功能 | IP端口部分要添加可选择历史。 | | 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 | | 11 | 问题 | 断连后当前远端ID要清除。 | | 0.1 | 0.2 |
| 10 | 功能 | 对照传输可以支持反向下载。 | | 0.1 | 0.2 | | 10 | 功能 | 对照传输可以支持反向下载。 | | 0.1 | 0.2 |
| 9 | 优化 | 输入路径后可以直接回车访问。 | | 0.1 | 0.2 | | 9 | 优化 | 输入路径后可以直接回车访问。 | | 0.1 | 0.2 |

View File

@@ -62,7 +62,8 @@ public:
enum FileCheckState { enum FileCheckState {
FCS_NORMAL = 0, FCS_NORMAL = 0,
FCS_DIR_NOT_EXIST, FCS_DIR_NOT_EXIST,
FCS_FILE_NOT_EXIST FCS_FILE_NOT_EXIST,
FCS_FILE_EXIST
}; };
// 字符串标识 // 字符串标识

View File

@@ -12,8 +12,8 @@ struct PropertyData {
QString uuid; QString uuid;
QString command; QString command;
QString userAction; QString userAction;
QString path; QString localPath;
QString properC; QString remotePath;
qint32 state; qint32 state;
qint32 properE; qint32 properE;
}; };
@@ -40,7 +40,7 @@ struct InfoMsg {
for (auto it = mapData.constBegin(); it != mapData.constEnd(); ++it) { for (auto it = mapData.constBegin(); it != mapData.constEnd(); ++it) {
data << it.key(); data << it.key();
data << it.value().uuid << it.value().command << it.value().userAction 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; QString key;
PropertyData prop; PropertyData prop;
data >> key; data >> key;
data >> prop.uuid >> prop.command >> prop.userAction >> prop.path data >> prop.uuid >> prop.command >> prop.userAction >> prop.localPath
>> prop.properC >> prop.state >> prop.properE; >> prop.remotePath >> prop.state >> prop.properE;
mapData.insert(key, prop); mapData.insert(key, prop);
} }
} }