add: basic req trans.
This commit is contained in:
@@ -1,13 +1,81 @@
|
|||||||
#include "FileTrans.h"
|
#include "FileTrans.h"
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
|
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
|
||||||
{
|
{
|
||||||
RegisterFrameCall();
|
RegisterFrameCall();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTrans::SetTasks(const QVector<TransTask>& 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<quint32>(fileInfo.permissions());
|
||||||
|
info.size = size;
|
||||||
|
} else {
|
||||||
|
sigError(QString(tr("File [%1] not exit.")).arg(info.fromPath));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clientCore_->Send<InfoMsg>(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<InfoMsg>(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()
|
void FileTrans::RegisterFrameCall()
|
||||||
@@ -152,7 +220,8 @@ void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task)
|
|||||||
auto* sendThread = new SendThread(clientCore_);
|
auto* sendThread = new SendThread(clientCore_);
|
||||||
sendThread->setTask(task);
|
sendThread->setTask(task);
|
||||||
QMutexLocker locker(&sthMut_);
|
QMutexLocker locker(&sthMut_);
|
||||||
sendThreads_.push_back(sendThread);
|
// TODO: check if already exist
|
||||||
|
upTasks_[task->task.localId] = sendThread;
|
||||||
sendThread->run();
|
sendThread->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,18 @@ private:
|
|||||||
class FileTrans : public QObject
|
class FileTrans : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileTrans(ClientCore* clientCore);
|
FileTrans(ClientCore* clientCore);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetTasks(const QVector<TransTask>& tasks);
|
void ReqSendFile(const TransTask& task);
|
||||||
void RegisterFrameCall();
|
void ReqDownFile(const TransTask& task);
|
||||||
|
qint32 GetSendProgress();
|
||||||
|
qint32 GetDownProgress();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sigError(const QString& err);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fbtReqSend(QSharedPointer<FrameBuffer> frame);
|
void fbtReqSend(QSharedPointer<FrameBuffer> frame);
|
||||||
@@ -71,19 +77,18 @@ private:
|
|||||||
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void RegisterFrameCall();
|
||||||
void SendFile(const QSharedPointer<DoTransTask>& task);
|
void SendFile(const QSharedPointer<DoTransTask>& task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DoTransTask downTask_;
|
DoTransTask downTask_;
|
||||||
|
DoTransTask sendTask_;
|
||||||
|
|
||||||
QMutex lMut_;
|
QMutex lMut_;
|
||||||
QMutex rMut_;
|
QMutex rMut_;
|
||||||
QVector<TransTask> localTasks_;
|
|
||||||
QVector<TransTask> remoteTasks_;
|
|
||||||
|
|
||||||
ClientCore* clientCore_;
|
ClientCore* clientCore_;
|
||||||
QMutex sthMut_;
|
QMutex sthMut_;
|
||||||
QVector<QThread*> sendThreads_;
|
|
||||||
QMap<QString, QThread*> upTasks_;
|
QMap<QString, QThread*> upTasks_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
|
|||||||
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
|
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
|
||||||
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
||||||
remotePtr->setClientCore(clientCore);
|
remotePtr->setClientCore(clientCore);
|
||||||
fileTrans_ = new FileTrans(clientCore);
|
|
||||||
fileHelper_ = remotePtr;
|
fileHelper_ = remotePtr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <FileTrans.h>
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FileManager;
|
class FileManager;
|
||||||
@@ -39,7 +38,6 @@ private:
|
|||||||
Ui::FileManager* ui;
|
Ui::FileManager* ui;
|
||||||
QString curRoot_;
|
QString curRoot_;
|
||||||
QMenu* menu_;
|
QMenu* menu_;
|
||||||
FileTrans* fileTrans_;
|
|
||||||
std::shared_ptr<DirFileHelper> fileHelper_;
|
std::shared_ptr<DirFileHelper> fileHelper_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "ui_Transform.h"
|
#include "ui_Transform.h"
|
||||||
@@ -16,4 +17,23 @@ TransForm::~TransForm()
|
|||||||
void TransForm::SetClientCore(ClientCore* clientCore)
|
void TransForm::SetClientCore(ClientCore* clientCore)
|
||||||
{
|
{
|
||||||
clientCore_ = clientCore;
|
clientCore_ = clientCore;
|
||||||
|
fileTrans_ = new FileTrans(clientCore_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransForm::SetTasks(const QVector<TransTask>& tasks)
|
||||||
|
{
|
||||||
|
tasks_ = tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransForm::startTask()
|
||||||
|
{
|
||||||
|
for (auto& task : tasks_) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransForm::showEvent(QShowEvent* event)
|
||||||
|
{
|
||||||
|
QDialog::showEvent(event);
|
||||||
|
startTask();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <ClientCore.h>
|
#include <ClientCore.h>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <FileTrans.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class TransForm;
|
class TransForm;
|
||||||
@@ -19,9 +20,18 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void SetClientCore(ClientCore* clientCore);
|
void SetClientCore(ClientCore* clientCore);
|
||||||
|
void SetTasks(const QVector<TransTask>& tasks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ClientCore* clientCore_;
|
void startTask();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector<TransTask> tasks_;
|
||||||
|
FileTrans* fileTrans_{};
|
||||||
|
ClientCore* clientCore_{};
|
||||||
Ui::TransForm* ui;
|
Ui::TransForm* ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
# frelay
|
# frelay
|
||||||
|
|
||||||
A tool that uses a relay server to upload and download files from remote clients.
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user