|
1 | | -#include "settinghepler.h" |
| 1 | +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +#include "settinghepler.h" |
2 | 6 |
|
3 | 7 | #include "common/log.h" |
4 | 8 |
|
@@ -71,7 +75,7 @@ bool SettingHelper::handleDataConfiguration(const QString &path) |
71 | 75 |
|
72 | 76 | QDir pdir(path); |
73 | 77 | QString filepath = pdir.absolutePath() + "/"; |
74 | | - QJsonObject jsonObj = ParseJson(filepath + "transfer.json"); |
| 78 | + QJsonObject jsonObj = ParseJson(pdir.filePath("transfer.json")); |
75 | 79 | if (jsonObj.isEmpty()) { |
76 | 80 | addTaskcounter(-1); |
77 | 81 | WLOG << "transfer.json is invaild"; |
@@ -100,8 +104,10 @@ bool SettingHelper::handleDataConfiguration(const QString &path) |
100 | 104 | } |
101 | 105 | } |
102 | 106 | addTaskcounter(-1); |
103 | | - //remove dir |
104 | | - pdir.removeRecursively(); |
| 107 | + //remove transfer.json |
| 108 | + const QString jsonFile = pdir.filePath("transfer.json"); |
| 109 | + if (!QFile::remove(jsonFile)) |
| 110 | + WLOG << "Failed to remove transfer.json: " << jsonFile.toStdString(); |
105 | 111 | return true; |
106 | 112 | } |
107 | 113 |
|
@@ -309,8 +315,11 @@ bool SettingHelper::setFile(QJsonObject jsonObj, QString filepath) |
309 | 315 | const QJsonArray &userFileArray = userFileValue.toArray(); |
310 | 316 | for (const auto &value : userFileArray) { |
311 | 317 | QString filename = value.toString(); |
| 318 | + |
| 319 | + // 只保留文件名部分,兼容相对路径和绝对路径格式 |
| 320 | + QString file = filepath + QFileInfo(filename).fileName(); |
| 321 | + |
312 | 322 | QString targetFile = QDir::homePath() + "/" + filename; |
313 | | - QString file = filepath + filename.mid(filename.indexOf('/') + 1); |
314 | 323 | QFileInfo info = QFileInfo(targetFile); |
315 | 324 | auto dir = info.dir(); |
316 | 325 | if (!dir.exists()) |
|
0 commit comments