Handle .!qB extension behind the scenes

PR #15920.
This commit is contained in:
Vladimir Golovnev
2022-01-08 08:45:50 +03:00
committed by GitHub
parent 9f6130cbaa
commit f44341a8e2
11 changed files with 63 additions and 105 deletions

View File

@@ -40,7 +40,6 @@
#include <QUrl>
#include "base/bittorrent/categoryoptions.h"
#include "base/bittorrent/common.h"
#include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/peeraddress.h"
@@ -565,14 +564,10 @@ void TorrentsController::filesAction()
{KEY_FILE_PROGRESS, fp[index]},
{KEY_FILE_PRIORITY, static_cast<int>(priorities[index])},
{KEY_FILE_SIZE, torrent->fileSize(index)},
{KEY_FILE_AVAILABILITY, fileAvailability[index]}
{KEY_FILE_AVAILABILITY, fileAvailability[index]},
{KEY_FILE_NAME, Utils::Fs::toUniformPath(torrent->filePath(index))}
};
QString fileName = torrent->filePath(index);
if (fileName.endsWith(QB_EXT, Qt::CaseInsensitive))
fileName.chop(QB_EXT.size());
fileDict[KEY_FILE_NAME] = Utils::Fs::toUniformPath(fileName);
const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(index);
fileDict[KEY_FILE_PIECE_RANGE] = QJsonArray {idx.first(), idx.last()};

View File

@@ -44,20 +44,16 @@ window.qBittorrent.Filesystem = (function() {
};
};
const QB_EXT = '.!qB';
const PathSeparator = '/';
/**
* Returns the file extension part of a file name.
*/
const fileExtension = function(filename) {
const name = filename.endsWith(QB_EXT)
? filename.substring(0, filename.length - QB_EXT.length)
: filename;
const pointIndex = name.lastIndexOf('.');
const pointIndex = filename.lastIndexOf('.');
if (pointIndex === -1)
return '';
return name.substring(pointIndex + 1);
return filename.substring(pointIndex + 1);
};
const fileName = function(filepath) {