mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
- BUGFIX: Handle paths with [~, ., ..] properly
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.0.3
|
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.0.3
|
||||||
- BUGFIX: Minor cosmetic fix to program preferences
|
- BUGFIX: Minor cosmetic fix to program preferences
|
||||||
- BUGFIX: Fix "Temp path" button in program preferences
|
- BUGFIX: Fix "Temp path" button in program preferences
|
||||||
|
- BUGFIX: Handle paths with [~, ., ..] properly
|
||||||
|
|
||||||
* Fri Dec 18 2009 - Christophe Dumez <chris@qbittorrent.org> - v2.0.2
|
* Fri Dec 18 2009 - Christophe Dumez <chris@qbittorrent.org> - v2.0.2
|
||||||
- BUGFIX: Fix .qbittorrent folder not being created (critical bug introduced in v2.0.1 that makes qBittorrent unusuable for new users)
|
- BUGFIX: Fix .qbittorrent folder not being created (critical bug introduced in v2.0.1 that makes qBittorrent unusuable for new users)
|
||||||
|
|||||||
@@ -1664,11 +1664,13 @@ QString Bittorrent::getSavePath(QString hash) {
|
|||||||
qDebug("Using default save path because none was set: %s", defaultSavePath.toLocal8Bit().data());
|
qDebug("Using default save path because none was set: %s", defaultSavePath.toLocal8Bit().data());
|
||||||
savePath = defaultSavePath;
|
savePath = defaultSavePath;
|
||||||
}
|
}
|
||||||
|
// Clean path
|
||||||
|
savePath = misc::expandPath(savePath);
|
||||||
// Checking if savePath Dir exists
|
// Checking if savePath Dir exists
|
||||||
// create it if it is not
|
// create it if it is not
|
||||||
QDir saveDir(savePath);
|
QDir saveDir(savePath);
|
||||||
if(!saveDir.exists()) {
|
if(!saveDir.exists()) {
|
||||||
if(!saveDir.mkpath(saveDir.path())) {
|
if(!saveDir.mkpath(saveDir.absolutePath())) {
|
||||||
std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n";
|
std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n";
|
||||||
// XXX: handle this better
|
// XXX: handle this better
|
||||||
//return QDir::homePath();
|
//return QDir::homePath();
|
||||||
|
|||||||
17
src/misc.h
17
src/misc.h
@@ -304,6 +304,23 @@ public:
|
|||||||
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
|
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
|
// Take a number of seconds and return an user-friendly
|
||||||
// time duration like "1d 2h 10m".
|
// time duration like "1d 2h 10m".
|
||||||
static QString userFriendlyDuration(qlonglong seconds) {
|
static QString userFriendlyDuration(qlonglong seconds) {
|
||||||
|
|||||||
@@ -902,11 +902,11 @@ QString options_imp::getSavePath() const{
|
|||||||
if(textSavePath->text().trimmed().isEmpty()){
|
if(textSavePath->text().trimmed().isEmpty()){
|
||||||
textSavePath->setText(home+QString::fromUtf8("qBT_dir"));
|
textSavePath->setText(home+QString::fromUtf8("qBT_dir"));
|
||||||
}
|
}
|
||||||
return textSavePath->text();
|
return misc::expandPath(textSavePath->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString options_imp::getTempPath() const {
|
QString options_imp::getTempPath() const {
|
||||||
return textTempPath->text();
|
return misc::expandPath(textTempPath->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool options_imp::isTempPathEnabled() const {
|
bool options_imp::isTempPathEnabled() const {
|
||||||
@@ -1291,9 +1291,9 @@ void options_imp::setLocale(QString locale){
|
|||||||
// Return scan dir set in options
|
// Return scan dir set in options
|
||||||
QString options_imp::getScanDir() const {
|
QString options_imp::getScanDir() const {
|
||||||
if(checkScanDir->isChecked()){
|
if(checkScanDir->isChecked()){
|
||||||
return textScanDir->text().trimmed();
|
return misc::expandPath(textScanDir->text());
|
||||||
}else{
|
}else{
|
||||||
return QString();
|
return QString::null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1313,22 +1313,28 @@ int options_imp::getActionOnDblClOnTorrentFn() const {
|
|||||||
|
|
||||||
// Display dialog to choose scan dir
|
// Display dialog to choose scan dir
|
||||||
void options_imp::on_browseScanDirButton_clicked() {
|
void options_imp::on_browseScanDirButton_clicked() {
|
||||||
#ifdef Q_WS_WIN
|
QString scan_path = misc::expandPath(textScanDir->text());
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose scan directory"), QDir::rootPath());
|
QDir scanDir(scan_path);
|
||||||
#else
|
QString dir;
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose scan directory"), QDir::homePath());
|
if(!scan_path.isEmpty() && scanDir.exists()) {
|
||||||
#endif
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose scan directory"), scanDir.absolutePath());
|
||||||
|
} else {
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose scan directory"), QDir::homePath());
|
||||||
|
}
|
||||||
if(!dir.isNull()){
|
if(!dir.isNull()){
|
||||||
textScanDir->setText(dir);
|
textScanDir->setText(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void options_imp::on_browseFilterButton_clicked() {
|
void options_imp::on_browseFilterButton_clicked() {
|
||||||
#ifdef Q_WS_WIN
|
QString filter_path = misc::expandPath(textFilterPath->text());
|
||||||
QString ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::rootPath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
|
QDir filterDir(filter_path);
|
||||||
#else
|
QString ipfilter;
|
||||||
QString ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::homePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
|
if(!filter_path.isEmpty() && filterDir.exists()) {
|
||||||
#endif
|
ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), filterDir.absolutePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
|
||||||
|
} else {
|
||||||
|
ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::homePath(), tr("Filters")+QString(" (*.dat *.p2p *.p2b)"));
|
||||||
|
}
|
||||||
if(!ipfilter.isNull()){
|
if(!ipfilter.isNull()){
|
||||||
textFilterPath->setText(ipfilter);
|
textFilterPath->setText(ipfilter);
|
||||||
}
|
}
|
||||||
@@ -1336,20 +1342,28 @@ void options_imp::on_browseFilterButton_clicked() {
|
|||||||
|
|
||||||
// Display dialog to choose save dir
|
// Display dialog to choose save dir
|
||||||
void options_imp::on_browseSaveDirButton_clicked(){
|
void options_imp::on_browseSaveDirButton_clicked(){
|
||||||
QString def_path = QDir::homePath();
|
QString save_path = misc::expandPath(textSavePath->text());
|
||||||
if(!textSavePath->text().isEmpty())
|
QDir saveDir(save_path);
|
||||||
def_path = textSavePath->text();
|
QString dir;
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), def_path);
|
if(!save_path.isEmpty() && saveDir.exists()) {
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), saveDir.absolutePath());
|
||||||
|
} else {
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
|
||||||
|
}
|
||||||
if(!dir.isNull()){
|
if(!dir.isNull()){
|
||||||
textSavePath->setText(dir);
|
textSavePath->setText(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void options_imp::on_browseTempDirButton_clicked(){
|
void options_imp::on_browseTempDirButton_clicked(){
|
||||||
QString def_path = QDir::homePath();
|
QString temp_path = misc::expandPath(textTempPath->text());
|
||||||
if(!textTempPath->text().isEmpty())
|
QDir tempDir(temp_path);
|
||||||
def_path = textTempPath->text();
|
QString dir;
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), def_path);
|
if(!temp_path.isEmpty() && tempDir.exists()) {
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), tempDir.absolutePath());
|
||||||
|
} else {
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
|
||||||
|
}
|
||||||
if(!dir.isNull()){
|
if(!dir.isNull()){
|
||||||
textTempPath->setText(dir);
|
textTempPath->setText(dir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -579,35 +579,34 @@ bool PropertiesWidget::applyPriorities() {
|
|||||||
h.prioritize_first_last_piece(true);
|
h.prioritize_first_last_piece(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
||||||
if(!h.is_valid()) return;
|
if(!h.is_valid()) return;
|
||||||
QString dir;
|
QString dir;
|
||||||
QDir saveDir(h.save_path());
|
QDir saveDir(h.save_path());
|
||||||
if(saveDir.exists()){
|
if(saveDir.exists()){
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
||||||
}else{
|
}else{
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
}
|
}
|
||||||
if(!dir.isNull()){
|
if(!dir.isNull()){
|
||||||
// Check if savePath exists
|
// Check if savePath exists
|
||||||
QDir savePath(dir);
|
QDir savePath(misc::expandPath(dir));
|
||||||
if(!savePath.exists()){
|
if(!savePath.exists()){
|
||||||
if(!savePath.mkpath(savePath.path())){
|
if(!savePath.mkpath(savePath.absolutePath())){
|
||||||
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Save savepath
|
||||||
|
TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());
|
||||||
|
// Actually move storage
|
||||||
|
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
||||||
|
h.move_storage(savePath.absolutePath());
|
||||||
|
// Update save_path in dialog
|
||||||
|
save_path->setText(savePath.absolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Save savepath
|
|
||||||
TorrentPersistentData::saveSavePath(h.hash(), savePath.path());
|
|
||||||
// Actually move storage
|
|
||||||
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
|
||||||
h.move_storage(savePath.path());
|
|
||||||
// Update save_path in dialog
|
|
||||||
save_path->setText(savePath.path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::filteredFilesChanged() {
|
void PropertiesWidget::filteredFilesChanged() {
|
||||||
if(h.is_valid()) {
|
if(h.is_valid()) {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ QPoint screenCenter() const{
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void updateDiskSpaceLabels() {
|
void updateDiskSpaceLabels() {
|
||||||
long long available = misc::freeDiskSpaceOnPath(savePathTxt->text());
|
long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->text()));
|
||||||
lbl_disk_space->setText(misc::friendlyUnit(available));
|
lbl_disk_space->setText(misc::friendlyUnit(available));
|
||||||
|
|
||||||
// Determine torrent size
|
// Determine torrent size
|
||||||
@@ -231,9 +231,10 @@ public slots:
|
|||||||
|
|
||||||
void on_browseButton_clicked(){
|
void on_browseButton_clicked(){
|
||||||
QString dir;
|
QString dir;
|
||||||
QDir saveDir(savePathTxt->text());
|
QString save_path = misc::expandPath(savePathTxt->text());
|
||||||
if(saveDir.exists()){
|
QDir saveDir(save_path);
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), savePathTxt->text());
|
if(!save_path.isEmpty() && saveDir.exists()){
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath());
|
||||||
}else{
|
}else{
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
}
|
}
|
||||||
@@ -305,11 +306,11 @@ public slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_OkButton_clicked(){
|
void on_OkButton_clicked(){
|
||||||
QDir savePath(savePathTxt->text());
|
|
||||||
if(savePathTxt->text().trimmed().isEmpty()){
|
if(savePathTxt->text().trimmed().isEmpty()){
|
||||||
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QDir savePath(misc::expandPath(savePathTxt->text()));
|
||||||
// Check if savePath exists
|
// Check if savePath exists
|
||||||
if(!savePath.exists()){
|
if(!savePath.exists()){
|
||||||
if(!savePath.mkpath(savePath.path())){
|
if(!savePath.mkpath(savePath.path())){
|
||||||
|
|||||||
Reference in New Issue
Block a user