mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Fix "Append Label to Save path" on Windows
This commit is contained in:
parent
12d1e852f4
commit
d9e15e40f4
@ -422,13 +422,17 @@ void misc::chmod644(const QDir& folder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString misc::updateLabelInSavePath(const QString& defaultSavePath, const QString &save_path, const QString &old_label, const QString &new_label) {
|
QString misc::updateLabelInSavePath(QString defaultSavePath, QString save_path, const QString &old_label, const QString &new_label) {
|
||||||
if(old_label == new_label) return save_path;
|
if(old_label == new_label) return save_path;
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
|
defaultSavePath.replace("\\", "/");
|
||||||
|
save_path.replace("\\", "/");
|
||||||
|
#endif
|
||||||
qDebug("UpdateLabelInSavePath(%s, %s, %s)", qPrintable(save_path), qPrintable(old_label), qPrintable(new_label));
|
qDebug("UpdateLabelInSavePath(%s, %s, %s)", qPrintable(save_path), qPrintable(old_label), qPrintable(new_label));
|
||||||
if(!save_path.startsWith(defaultSavePath)) return save_path;
|
if(!save_path.startsWith(defaultSavePath)) return save_path;
|
||||||
QString new_save_path = save_path;
|
QString new_save_path = save_path;
|
||||||
new_save_path.replace(defaultSavePath, "");
|
new_save_path.replace(defaultSavePath, "");
|
||||||
QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts);
|
QStringList path_parts = new_save_path.split("/", QString::SkipEmptyParts);
|
||||||
if(path_parts.empty()) {
|
if(path_parts.empty()) {
|
||||||
if(!new_label.isEmpty())
|
if(!new_label.isEmpty())
|
||||||
path_parts << new_label;
|
path_parts << new_label;
|
||||||
|
@ -128,7 +128,7 @@ public:
|
|||||||
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> t);
|
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> t);
|
||||||
static QString truncateRootFolder(libtorrent::torrent_handle h);
|
static QString truncateRootFolder(libtorrent::torrent_handle h);
|
||||||
|
|
||||||
static QString updateLabelInSavePath(const QString& defaultSavePath, const QString &save_path, const QString &old_label, const QString &new_label);
|
static QString updateLabelInSavePath(QString defaultSavePath, QString save_path, const QString &old_label, const QString &new_label);
|
||||||
|
|
||||||
static bool sameFiles(const QString &path1, const QString &path2);
|
static bool sameFiles(const QString &path1, const QString &path2);
|
||||||
static bool isUrl(const QString &s);
|
static bool isUrl(const QString &s);
|
||||||
|
@ -504,10 +504,22 @@ void torrentAdditionDialog::updateDiskSpaceLabels() {
|
|||||||
void torrentAdditionDialog::on_browseButton_clicked(){
|
void torrentAdditionDialog::on_browseButton_clicked(){
|
||||||
Q_ASSERT(!is_magnet);
|
Q_ASSERT(!is_magnet);
|
||||||
QString new_path;
|
QString new_path;
|
||||||
|
QString root_folder;
|
||||||
|
const QString label_name = comboLabel->currentText();
|
||||||
if(t->num_files() == 1) {
|
if(t->num_files() == 1) {
|
||||||
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText(), QString(), 0, QFileDialog::DontConfirmOverwrite);
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText(), QString(), 0, QFileDialog::DontConfirmOverwrite);
|
||||||
|
if(!new_path.isEmpty()) {
|
||||||
|
QStringList path_parts = new_path.replace("\\", "/").split("/");
|
||||||
|
const QString filename = path_parts.takeLast();
|
||||||
|
// Append label
|
||||||
|
if(QDir(path_parts.join(QDir::separator())) == QDir(defaultSavePath) && !label_name.isEmpty())
|
||||||
|
path_parts << label_name;
|
||||||
|
// Append file name
|
||||||
|
path_parts << filename;
|
||||||
|
// Construct new_path
|
||||||
|
new_path = path_parts.join(QDir::separator());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
QString root_folder;
|
|
||||||
QString truncated_path = getCurrentTruncatedSavePath(&root_folder);
|
QString truncated_path = getCurrentTruncatedSavePath(&root_folder);
|
||||||
if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){
|
if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path);
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path);
|
||||||
@ -519,7 +531,6 @@ void torrentAdditionDialog::on_browseButton_clicked(){
|
|||||||
if(path_parts.last().isEmpty())
|
if(path_parts.last().isEmpty())
|
||||||
path_parts.removeLast();
|
path_parts.removeLast();
|
||||||
// Append label
|
// Append label
|
||||||
const QString label_name = comboLabel->currentText();
|
|
||||||
if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty())
|
if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty())
|
||||||
path_parts << label_name;
|
path_parts << label_name;
|
||||||
// Append root folder
|
// Append root folder
|
||||||
|
Loading…
Reference in New Issue
Block a user