diff --git a/.qtcreator/CMakeLists.txt.user b/.qtcreator/CMakeLists.txt.user new file mode 100644 index 0000000..26b5bc0 --- /dev/null +++ b/.qtcreator/CMakeLists.txt.user @@ -0,0 +1,603 @@ + + + + + + EnvironmentId + {8ef8e4d9-104a-416c-806b-9f180c9cbc0a} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + true + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 0 + 80 + true + true + 1 + 0 + false + true + false + 2 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 6 + true + + + + true + + 0 + + + + ProjectExplorer.Project.Target.0 + + Desktop + true + x86-windows-msys-pe-64bit + x86-windows-msys-pe-64bit + {91740fcb-06a8-437e-9899-e11928f5b8f6} + 0 + 0 + 4 + + Debug + 2 + false + + -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCOMPILE_GUI:STRING=ON +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_COLOR_DIAGNOSTICS:BOOL=ON +-DQT_DEFAULT_MAJOR_VERSION:STRING=6 +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_GENERATOR:STRING=MinGW Makefiles + 0 + D:\Git\frelay\build\x86_windows_msys_pe_64bit-Debug + + + + + all + + false + + true + 构建 + CMakeProjectManager.MakeStep + + 1 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + 构建 + CMakeProjectManager.MakeStep + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + 0 + 4 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + + + + + + + + false + + true + 构建 + ApplicationManagerPlugin.Deploy.CMakePackageStep + + + install-package --acknowledge + true + Install Application Manager package + ApplicationManagerPlugin.Deploy.InstallPackageStep + + + + + + + + 2 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ApplicationManagerPlugin.Deploy.Configuration + + 2 + + false + + false + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayBaseTest + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayConsole + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayServer + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayTest + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayGUI + false + + true + true + true + %{RunConfig:Executable:Path} + + 5 + + + Release + 2 + false + + -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_COLOR_DIAGNOSTICS:BOOL=ON +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_GENERATOR:STRING=MinGW Makefiles + D:\Git\frelay\build\x86_windows_msys_pe_64bit-Release + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + 1 + 0 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + + + + + + + + false + + true + ApplicationManagerPlugin.Deploy.CMakePackageStep + + + install-package --acknowledge + true + Install Application Manager package + ApplicationManagerPlugin.Deploy.InstallPackageStep + + + + + + + + 2 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ApplicationManagerPlugin.Deploy.Configuration + + 2 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + + true + true + %{RunConfig:Executable:Path} + + 1 + + 2 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + + + + + + + + false + + true + 构建 + ApplicationManagerPlugin.Deploy.CMakePackageStep + + + install-package --acknowledge + true + Install Application Manager package + ApplicationManagerPlugin.Deploy.InstallPackageStep + + + + + + + + 2 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ApplicationManagerPlugin.Deploy.Configuration + + 2 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayBaseTest + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayConsole + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayServer + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayTest + false + + true + true + true + %{RunConfig:Executable:Path} + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + CMakeProjectManager.CMakeRunConfiguration. + frelayGUI + false + + true + true + true + %{RunConfig:Executable:Path} + + 5 + + + + ProjectExplorer.Project.TargetCount + 1 + + + Version + 22 + + diff --git a/ClientCore/ClientCore.cpp b/ClientCore/ClientCore.cpp index ea56bbc..061fe92 100644 --- a/ClientCore/ClientCore.cpp +++ b/ClientCore/ClientCore.cpp @@ -89,12 +89,12 @@ void ClientCore::handleAsk(QSharedPointer frame) if (msg.command == STRMSG_AC_CHECK_FILE_EXIST) { msg.command = STRMSG_AC_ANSWER_FILE_EXIST; for (auto& item : msg.mapData) { - if (item.mark == STRMSG_AC_UP) { - if (!Util::DirExist(item.key, true)) { + if (item.command == STRMSG_AC_UP) { + if (!Util::DirExist(item.path, false)) { item.state = static_cast(FCS_DIR_NOT_EXIST); } } else { - if (!Util::FileExist(item.key)) { + if (!Util::FileExist(item.path)) { item.state = static_cast(FCS_FILE_NOT_EXIST); } } diff --git a/ClientCore/FileTrans.cpp b/ClientCore/FileTrans.cpp index 22219ca..b7634d3 100644 --- a/ClientCore/FileTrans.cpp +++ b/ClientCore/FileTrans.cpp @@ -1,5 +1,6 @@ #include "FileTrans.h" +#include #include FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore) @@ -164,6 +165,19 @@ void FileTrans::fbtReqSend(QSharedPointer frame) } // 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, frame->fid); + if (!ClientCore::syncInvoke(clientCore_, f)) { + qCritical() << QString(tr("%1 回复 %2 失败。")).arg(info.msg, f->fid); + } + return; + } + 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)) { @@ -171,9 +185,8 @@ void FileTrans::fbtReqSend(QSharedPointer frame) qCritical() << info.msg; auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, frame->fid); if (!ClientCore::syncInvoke(clientCore_, f)) { - qCritical() << QString(tr("打开接收文件 %2 失败,回复 %2 失败。")).arg(info.msg, f->fid); + qCritical() << QString(tr("打开接收文件 %1 失败,回复 %2 失败。")).arg(info.msg, f->fid); downTask_->file.close(); - return; } return; } diff --git a/Gui/CMakeLists.txt b/Gui/CMakeLists.txt index 2e6bec9..ce39bbf 100644 --- a/Gui/CMakeLists.txt +++ b/Gui/CMakeLists.txt @@ -27,6 +27,7 @@ Control/cusTableWidget.cpp Control/cusTableWidget.h Control/cpTableWidget.h Control/cpTableWidget.cpp GuiUtil/Config.h GuiUtil/Config.cpp ../Res/qss.qrc Form/Loading.h Form/Loading.cpp +Control/Common.h Control/Common.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) diff --git a/Gui/Control/Common.cpp b/Gui/Control/Common.cpp new file mode 100644 index 0000000..c8ce514 --- /dev/null +++ b/Gui/Control/Common.cpp @@ -0,0 +1,24 @@ +#include "Common.h" + +#include + +Common::Common() : QWidget(nullptr) +{ +} + +int Common::GetAcceptThree(QWidget* parent, const QString& notice, const QString& title) +{ + QMessageBox msgBox(parent); + msgBox.setWindowTitle(notice); + msgBox.setText(title); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::Cancel); + int result = msgBox.exec(); + switch (result) { + case QMessageBox::Yes: + return 0; + case QMessageBox::YesToAll: + return 1; + default: + return -1; + } +} diff --git a/Gui/Control/Common.h b/Gui/Control/Common.h new file mode 100644 index 0000000..3ce5f4b --- /dev/null +++ b/Gui/Control/Common.h @@ -0,0 +1,16 @@ +#ifndef COMMON_H +#define COMMON_H + +#include + +class Common : public QWidget +{ + Q_OBJECT +public: + Common(); + +public: + static int GetAcceptThree(QWidget* parent, const QString& notice, const QString& title); +}; + +#endif // COMMON_H \ No newline at end of file diff --git a/Gui/Form/Transform.cpp b/Gui/Form/Transform.cpp index 2634dba..133c873 100644 --- a/Gui/Form/Transform.cpp +++ b/Gui/Form/Transform.cpp @@ -162,16 +162,25 @@ void CheckCondition::SetTasks(const QVector& tasks) tasks_ = tasks; } -InfoMsg CheckCondition::GetInfoMsg() const +QVector CheckCondition::GetTasks() const { - return infoMsg_; + return tasks_; } void CheckCondition::recvFrame(QSharedPointer frame) { InfoMsg info = infoUnpack(frame->data); if (info.command == STRMSG_AC_ANSWER_FILE_EXIST) { - infoMsg_ = info; + + for (auto& item : info.mapData) { + auto it = + std::find_if(tasks_.begin(), tasks_.end(), [&item](const TransTask& task) { return task.taskUUID == item.uuid; }); + if (it == tasks_.end()) { + continue; + } + it->remoteCheckState = static_cast(item.state); + } + qInfo() << tr("检查结束......"); msg_ = info.command; return; @@ -209,9 +218,11 @@ void CheckCondition::run() // 再检查远程文件是否存在 InfoMsg msg; msg.command = STRMSG_AC_CHECK_FILE_EXIST; - for (const auto& task : tasks_) { - msg.mapData[task.taskUUID].mark = task.isUpload ? STRMSG_AC_UP : STRMSG_AC_DOWN; - msg.mapData[task.taskUUID].key = task.remotePath; + + 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; } auto f = clientCore_->GetBuffer(msg, FBT_MSGINFO_ASK, clientCore_->GetRemoteID()); diff --git a/Gui/Form/Transform.h b/Gui/Form/Transform.h index 8f1a39b..2e47b46 100644 --- a/Gui/Form/Transform.h +++ b/Gui/Form/Transform.h @@ -85,7 +85,7 @@ public: public: void SetClientCore(ClientCore* clientCore); void SetTasks(const QVector& tasks); - InfoMsg GetInfoMsg() const; + QVector GetTasks() const; Q_SIGNALS: void sigCheckOver(); @@ -103,7 +103,6 @@ private: bool isAlreadyInter_; QVector tasks_; ClientCore* clientCore_{}; - InfoMsg infoMsg_; }; #endif // TRANSFORM_H \ No newline at end of file diff --git a/Gui/frelayGUI.cpp b/Gui/frelayGUI.cpp index 69bf7f8..e0a16b3 100644 --- a/Gui/frelayGUI.cpp +++ b/Gui/frelayGUI.cpp @@ -2,10 +2,12 @@ #include
#include +#include #include #include #include #include +#include "Control/Common.h" #include "./ui_frelayGUI.h" #include "Control/LogControl.h" @@ -142,7 +144,6 @@ void frelayGUI::HandleTask(const QVector& tasks) qCritical() << QString(tr("未连接到服务器。。。")); return; } - transform_->SetTasks(tasks); // 检查文件 CheckCondition cond(this); @@ -159,14 +160,63 @@ void frelayGUI::HandleTask(const QVector& tasks) cond.start(); checking.exec(); - auto msg = cond.GetInfoMsg(); - for (auto& data : msg.mapData) { - if (data.state == static_cast(FCS_NORMAL)) { + // 检查结果 + auto reTasks = cond.GetTasks(); + if (!CheckTaskResult(reTasks)) { + return; + } + transform_->SetTasks(reTasks); + transform_->exec(); +} + +bool frelayGUI::CheckTaskResult(QVector& tasks) +{ + bool isAccept = false; + for (auto& task : tasks) { + if (task.localCheckState == FCS_NORMAL && task.remoteCheckState == FCS_NORMAL) { continue; } + if (task.isUpload) { + if (task.localCheckState != FCS_NORMAL) { + QMessageBox::information(this, tr("文件校验"), tr("本地文件校验失败,请检查文件是否存在:") + task.localPath); + return false; + } + if (task.remoteCheckState != FCS_NORMAL && !isAccept) { + auto msg = tr("远端不存在文件夹") + task.remotePath + ",需要自动创建吗?"; + auto ret =Common::GetAcceptThree(this, "操作确认", msg); + if (ret == 0) { + continue; + } + else if (ret == 1) { + isAccept = true; + continue; + } + else { + return false; + } + } + } else { + if (task.localCheckState != FCS_NORMAL) { + auto msg = tr("本地不存在文件夹") + task.localPath + ",需要自动创建吗?"; + auto ret =Common::GetAcceptThree(this, "操作确认", msg); + if (ret == 0) { + continue; + } + else if (ret == 1) { + isAccept = true; + continue; + } + else { + return false; + } + } + if (task.remoteCheckState != FCS_NORMAL) { + QMessageBox::information(this, tr("文件校验"), tr("远端文件校验失败,请检查文件是否存在:") + task.remotePath); + return false; + } + } } - - transform_->exec(); + return true; } void frelayGUI::closeEvent(QCloseEvent* event) diff --git a/Gui/frelayGUI.h b/Gui/frelayGUI.h index dec317e..e45885b 100644 --- a/Gui/frelayGUI.h +++ b/Gui/frelayGUI.h @@ -36,6 +36,7 @@ public: public slots: void HandleTask(const QVector& tasks); + bool CheckTaskResult(QVector& tasks); protected: void closeEvent(QCloseEvent* event) override; diff --git a/Struct/InfoMsg.h b/Struct/InfoMsg.h index 147f3ee..45ddc0c 100644 --- a/Struct/InfoMsg.h +++ b/Struct/InfoMsg.h @@ -4,15 +4,15 @@ #include #include #include +#include #include #include -#include struct PropertyData { - QString key; - QString mark; + QString uuid; + QString command; QString userAction; - QString properB; + QString path; QString properC; qint32 state; qint32 properE; @@ -32,36 +32,43 @@ struct InfoMsg { void serialize(QDataStream& data) const { data << mark << command << msg << fromPath << toPath << size << permissions; - data << list.size(); + data << static_cast(list.size()); for (const auto& item : list) { data << item; } - data << mapData.size(); - for (const auto& item : mapData) { - data << item.key << item.mark << item.userAction << item.properB << item.properC << item.state << item.properE; + data << static_cast(mapData.size()); + 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; } } void deserialize(QDataStream& data) { data >> mark >> command >> msg >> fromPath >> toPath >> size >> permissions; + qint32 listSize; data >> listSize; list.resize(listSize); for (auto& item : list) { data >> item; } + qint32 mapSize; data >> mapSize; - data >> mapSize; + mapData.clear(); for (int i = 0; i < mapSize; ++i) { + QString key; PropertyData prop; - data >> prop.key >> prop.mark >> prop.userAction >> prop.properB >> prop.properC >> prop.state >> prop.properE; - mapData.insert(prop.key, prop); + data >> key; + data >> prop.uuid >> prop.command >> prop.userAction >> prop.path + >> prop.properC >> prop.state >> prop.properE; + mapData.insert(key, prop); } } }; QDataStream& operator<<(QDataStream& data, const InfoMsg& info); QDataStream& operator>>(QDataStream& data, InfoMsg& info); -#endif // INFO_MSG_H \ No newline at end of file +#endif // INFO_MSG_H diff --git a/Struct/InfoPack.hpp b/Struct/InfoPack.hpp index 92b53dc..7230a52 100644 --- a/Struct/InfoPack.hpp +++ b/Struct/InfoPack.hpp @@ -4,6 +4,7 @@ #include #include #include +#include template QByteArray infoPack(const T& obj) { @@ -22,4 +23,4 @@ template T infoUnpack(const QByteArray& byteArray) return obj; } -#endif // INFO_PACK_HPP \ No newline at end of file +#endif // INFO_PACK_HPP diff --git a/Test/infoTest.cpp b/Test/infoTest.cpp index b646938..7a0e386 100644 --- a/Test/infoTest.cpp +++ b/Test/infoTest.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include int infoTest1() { @@ -80,4 +82,15 @@ void performanceTest() in >> val; } qDebug() << "New streams:" << timer.elapsed() << "ms"; -} \ No newline at end of file +} +int infoTest3() +{ + InfoMsg msg1; + msg1.mapData["C++"].command = "exec"; + msg1.command = "FFASS0"; + + auto bytes = infoPack(msg1); + auto msg2 = infoUnpack(bytes); + + return 0; +} diff --git a/Test/infoTest.h b/Test/infoTest.h index dac3ad4..b6a2ab2 100644 --- a/Test/infoTest.h +++ b/Test/infoTest.h @@ -5,6 +5,7 @@ int infoTest1(); int infoTest2(); +int infoTest3(); void performanceTest(); -#endif \ No newline at end of file +#endif diff --git a/Test/protocolTest.cpp b/Test/protocolTest.cpp index 977ac60..cb58dc9 100644 --- a/Test/protocolTest.cpp +++ b/Test/protocolTest.cpp @@ -22,7 +22,7 @@ int test1() int main() { - setConsoleMsgHandler(); - test1(); + //setConsoleMsgHandler(); + infoTest3(); return 0; -} \ No newline at end of file +}