mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
- Handle paths with (~, ., ..) properly
This commit is contained in:
parent
c334439df6
commit
50e620daf2
5 changed files with 67 additions and 33 deletions
17
src/misc.h
17
src/misc.h
|
@ -317,6 +317,23 @@ public:
|
|||
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
|
||||
}
|
||||
|
||||
// Replace ~ in path
|
||||
static QString expandPath(QString path) {
|
||||
path = path.trimmed();
|
||||
if(path.isEmpty()) return path;
|
||||
if(path.length() == 1) {
|
||||
if(path[0] == '~' ) return QDir::homePath();
|
||||
}
|
||||
if(path[0] == '~' && path[1] == QDir::separator()) {
|
||||
path = path.replace(0, 1, QDir::homePath());
|
||||
} else {
|
||||
if(QDir::isAbsolutePath(path)) {
|
||||
path = QDir(path).absolutePath();
|
||||
}
|
||||
}
|
||||
return QDir::cleanPath(path);
|
||||
}
|
||||
|
||||
// Take a number of seconds and return an user-friendly
|
||||
// time duration like "1d 2h 10m".
|
||||
static QString userFriendlyDuration(qlonglong seconds) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue