fix: remote judge not exist file bug.
This commit is contained in:
@@ -18,7 +18,13 @@ FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
|
||||
void FileTrans::ReqSendFile(const TransTask& task)
|
||||
{
|
||||
// TODO: check if running...
|
||||
|
||||
if (sendTask_->file.isOpen()) {
|
||||
qWarning() << QString(tr("file [%1] is running.")).arg(sendTask_->file.fileName());
|
||||
while (sendTask_->file.isOpen()) {
|
||||
QThread::msleep(1);
|
||||
}
|
||||
qWarning() << QString(tr("file [%1] is exit running.")).arg(sendTask_->file.fileName());
|
||||
}
|
||||
// start
|
||||
InfoMsg info;
|
||||
info.toPath = task.remotePath;
|
||||
@@ -85,20 +91,26 @@ void FileTrans::ReqDownFile(const TransTask& task)
|
||||
qint32 FileTrans::GetSendProgress()
|
||||
{
|
||||
if (sendTask_->state == TaskState::STATE_FINISH) {
|
||||
downTask_->state == TaskState::STATE_NONE;
|
||||
sendTask_->state = TaskState::STATE_NONE;
|
||||
return 100;
|
||||
}
|
||||
if (sendTask_->state != TaskState::STATE_RUNNING) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// wait file state ok.
|
||||
double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize;
|
||||
return per;
|
||||
qint32 rt = static_cast<qint32>(per);
|
||||
if (rt >= 100) {
|
||||
return 99;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
qint32 FileTrans::GetDownProgress()
|
||||
{
|
||||
if (downTask_->state == TaskState::STATE_FINISH) {
|
||||
downTask_->state == TaskState::STATE_NONE;
|
||||
downTask_->state = TaskState::STATE_NONE;
|
||||
return 100;
|
||||
}
|
||||
if (downTask_->state != TaskState::STATE_RUNNING) {
|
||||
@@ -107,8 +119,13 @@ qint32 FileTrans::GetDownProgress()
|
||||
if (downTask_->totalSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
// wait file state ok.
|
||||
double per = (downTask_->tranSize * 100.0) / downTask_->totalSize;
|
||||
return per;
|
||||
qint32 rt = static_cast<qint32>(per);
|
||||
if (rt >= 100) {
|
||||
return 99;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
void FileTrans::RegisterSignal()
|
||||
@@ -357,6 +374,7 @@ void SendThread::run()
|
||||
auto f = cliCore_->GetBuffer(info, FBT_CLI_TRANS_DONE, task_->task.remoteId);
|
||||
ClientCore::asyncInvoke(cliCore_, [this, f]() { return cliCore_->Send(f); });
|
||||
task_->file.close();
|
||||
task_->state = TaskState::STATE_FINISH;
|
||||
}
|
||||
|
||||
void SendThread::setTask(const QSharedPointer<DoTransTask>& task)
|
||||
|
||||
@@ -80,29 +80,18 @@ void Util::InitLogger(const QString& logPath, const QString& mark)
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
// do not check exit
|
||||
QString Util::Get2FilePath(const QString& file, const QString& directory)
|
||||
{
|
||||
if (file.isEmpty() || directory.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QFileInfo fileInfo(file);
|
||||
QDir dir(directory);
|
||||
QString fileName = QFileInfo(file).fileName();
|
||||
QString cleanDir = QDir::cleanPath(directory);
|
||||
QString fullPath = QDir(cleanDir).filePath(fileName);
|
||||
|
||||
if (!fileInfo.isFile()) {
|
||||
qWarning() << "Path A is not a file:" << file;
|
||||
return QString();
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
qWarning() << "Path B is not a valid directory:" << directory;
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString fileName = fileInfo.fileName();
|
||||
QString cleanPathB = QDir::cleanPath(directory);
|
||||
QString newPath = cleanPathB + QDir::separator() + fileName;
|
||||
newPath = QDir::cleanPath(newPath);
|
||||
return newPath;
|
||||
return QDir::cleanPath(fullPath);
|
||||
}
|
||||
|
||||
void Util::ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||
|
||||
Reference in New Issue
Block a user