diff --git a/ClientCore/FileTrans.cpp b/ClientCore/FileTrans.cpp index 0656cee..67b21d9 100644 --- a/ClientCore/FileTrans.cpp +++ b/ClientCore/FileTrans.cpp @@ -1,13 +1,81 @@ #include "FileTrans.h" +#include FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore) { RegisterFrameCall(); } -void FileTrans::SetTasks(const QVector& tasks) +/* + * When the local client actively sends a file, it cannot simultaneously perform download operations. + * Passive sending is an exception, primarily to monitor the sending progress. In contrast, + * the progress of passive sending is monitored by the requesting download side, + * so there is no need to track the progress locally. + */ +void FileTrans::ReqSendFile(const TransTask& task) { - localTasks_ = tasks; + // TODO: check if running... + + // start + InfoMsg info; + info.toPath = task.remotePath; + info.fromPath = task.localPath; + + QFileInfo fileInfo(info.fromPath); + if (fileInfo.exists()) { + qint64 size = fileInfo.size(); + info.permissions = static_cast(fileInfo.permissions()); + info.size = size; + } else { + sigError(QString(tr("File [%1] not exit.")).arg(info.fromPath)); + return; + } + + if (!clientCore_->Send(info, FBT_CLI_REQ_SEND, task.remoteId)) { + sigError(QString(tr("send req send failed: %1")).arg(info.msg)); + sendTask_.state = TaskState::STATE_NONE; + return; + } + sendTask_.state = TaskState::STATE_RUNNING; + sendTask_.totalSize = info.size; + sendTask_.tranSize = 0; +} + +void FileTrans::ReqDownFile(const TransTask& task) +{ + // TODO: check if running... + + // start + InfoMsg info; + info.toPath = task.localPath; + info.fromPath = task.remotePath; + + if (!clientCore_->Send(info, FBT_CLI_REQ_DOWN, task.remoteId)) { + sigError(QString(tr("send req send failed: %1")).arg(info.msg)); + sendTask_.state = TaskState::STATE_NONE; + return; + } + sendTask_.state = TaskState::STATE_RUNNING; +} + +qint32 FileTrans::GetSendProgress() +{ + if (sendTask_.state != TaskState::STATE_RUNNING) { + return -1; + } + + double per = (sendTask_.tranSize * 100.0) / sendTask_.totalSize; + return per; +} + +qint32 FileTrans::GetDownProgress() +{ + if (downTask_.state != TaskState::STATE_RUNNING) { + return -1; + } + + double per = (downTask_.tranSize * 100.0) / downTask_.totalSize; + return per; } void FileTrans::RegisterFrameCall() @@ -152,7 +220,8 @@ void FileTrans::SendFile(const QSharedPointer& task) auto* sendThread = new SendThread(clientCore_); sendThread->setTask(task); QMutexLocker locker(&sthMut_); - sendThreads_.push_back(sendThread); + // TODO: check if already exist + upTasks_[task->task.localId] = sendThread; sendThread->run(); } diff --git a/ClientCore/FileTrans.h b/ClientCore/FileTrans.h index 3ef2fd5..f800d73 100644 --- a/ClientCore/FileTrans.h +++ b/ClientCore/FileTrans.h @@ -52,12 +52,18 @@ private: class FileTrans : public QObject { Q_OBJECT + public: FileTrans(ClientCore* clientCore); public: - void SetTasks(const QVector& tasks); - void RegisterFrameCall(); + void ReqSendFile(const TransTask& task); + void ReqDownFile(const TransTask& task); + qint32 GetSendProgress(); + qint32 GetDownProgress(); + +signals: + void sigError(const QString& err); private: void fbtReqSend(QSharedPointer frame); @@ -71,19 +77,18 @@ private: void fbtTransFailed(QSharedPointer frame); private: + void RegisterFrameCall(); void SendFile(const QSharedPointer& task); private: DoTransTask downTask_; + DoTransTask sendTask_; QMutex lMut_; QMutex rMut_; - QVector localTasks_; - QVector remoteTasks_; ClientCore* clientCore_; QMutex sthMut_; - QVector sendThreads_; QMap upTasks_; }; diff --git a/Gui/Control/FileControl.cpp b/Gui/Control/FileControl.cpp index e17d736..9496ad9 100644 --- a/Gui/Control/FileControl.cpp +++ b/Gui/Control/FileControl.cpp @@ -33,7 +33,6 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); }); remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); }); remotePtr->setClientCore(clientCore); - fileTrans_ = new FileTrans(clientCore); fileHelper_ = remotePtr; } } diff --git a/Gui/Control/FileControl.h b/Gui/Control/FileControl.h index f291483..2ac889a 100644 --- a/Gui/Control/FileControl.h +++ b/Gui/Control/FileControl.h @@ -6,7 +6,6 @@ #include #include #include -#include namespace Ui { class FileManager; @@ -39,7 +38,6 @@ private: Ui::FileManager* ui; QString curRoot_; QMenu* menu_; - FileTrans* fileTrans_; std::shared_ptr fileHelper_; }; diff --git a/Gui/Form/Transform.cpp b/Gui/Form/Transform.cpp index 75863e6..2024e1f 100644 --- a/Gui/Form/Transform.cpp +++ b/Gui/Form/Transform.cpp @@ -1,4 +1,5 @@ #include "Transform.h" + #include #include "ui_Transform.h" @@ -16,4 +17,23 @@ TransForm::~TransForm() void TransForm::SetClientCore(ClientCore* clientCore) { clientCore_ = clientCore; + fileTrans_ = new FileTrans(clientCore_); +} + +void TransForm::SetTasks(const QVector& tasks) +{ + tasks_ = tasks; +} + +void TransForm::startTask() +{ + for (auto& task : tasks_) { + + } +} + +void TransForm::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + startTask(); } diff --git a/Gui/Form/Transform.h b/Gui/Form/Transform.h index 3c44fce..21254f1 100644 --- a/Gui/Form/Transform.h +++ b/Gui/Form/Transform.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Ui { class TransForm; @@ -19,9 +20,18 @@ public: public: void SetClientCore(ClientCore* clientCore); + void SetTasks(const QVector& tasks); private: - ClientCore* clientCore_; + void startTask(); + +protected: + void showEvent(QShowEvent* event) override; + +private: + QVector tasks_; + FileTrans* fileTrans_{}; + ClientCore* clientCore_{}; Ui::TransForm* ui; }; diff --git a/README.md b/README.md index 3462cd0..55451a1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # frelay A tool that uses a relay server to upload and download files from remote clients. + +## Features + +1. Minimal configuration—simply start a server, connect to it, and begin transferring files. +2. If you frequently transfer the same files repeatedly, frelay offers a local-remote file mapping feature for one-click transfers. + +## Disclaimer +This tool is solely designed for simple file transmission between clients via a relay server. It does not include any security validation logic to prevent data attacks or similar threats. It is primarily intended for temporary, non-sensitive file transfers. Please close the software or disconnect from the relay server when not in use.