diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 03bd9070e..ba0a53c20 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -886,9 +886,15 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { torrent_tmp_path += torrent_name; } p.save_path = torrent_tmp_path.toLocal8Bit().constData(); - qDebug("addMagnetURI: using save_path: %s", qPrintable(defaultTempPath)); + // Check if save path exists, creating it otherwise + if(!QDir(torrent_tmp_path).exists()) + QDir().mkpath(torrent_tmp_path); + qDebug("addMagnetURI: using save_path: %s", qPrintable(torrent_tmp_path)); } else { p.save_path = savePath.toLocal8Bit().constData(); + // Check if save path exists, creating it otherwise + if(!QDir(savePath).exists()) + QDir().mkpath(savePath); qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath)); } @@ -1130,9 +1136,15 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr torrent_tmp_path += root_folder; } p.save_path = torrent_tmp_path.toLocal8Bit().constData(); - qDebug("addTorrent: using save_path: %s", qPrintable(defaultTempPath)); + // Check if save path exists, creating it otherwise + if(!QDir(torrent_tmp_path).exists()) + QDir().mkpath(torrent_tmp_path); + qDebug("addTorrent: using save_path: %s", qPrintable(torrent_tmp_path)); } else { p.save_path = savePath.toLocal8Bit().constData(); + // Check if save path exists, creating it otherwise + if(!QDir(savePath).exists()) + QDir().mkpath(savePath); qDebug("addTorrent: using save_path: %s", qPrintable(savePath)); } @@ -1168,12 +1180,19 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr if(!from_url.isNull()) QFile::remove(file); return h; } + // Remember root folder + TorrentPersistentData::setRootFolder(hash, root_folder); // If temp path is enabled, move torrent - if(!defaultTempPath.isEmpty() && !resumed) { + /*if(!defaultTempPath.isEmpty() && !resumed) { qDebug("Temp folder is enabled, moving new torrent to temp folder"); - h.move_storage(defaultTempPath); - } + QString torrent_tmp_path = defaultTempPath.replace("\\", "/"); + if(!root_folder.isEmpty()) { + if(!torrent_tmp_path.endsWith("/")) torrent_tmp_path += "/"; + torrent_tmp_path += root_folder; + } + h.move_storage(torrent_tmp_path); + }*/ // Connections limit per torrent h.set_max_connections(Preferences::getMaxConnecsPerTorrent()); @@ -2255,7 +2274,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { const QDir current_dir(h.save_path()); const QDir save_dir(getSavePath(h.hash())); if(current_dir == save_dir) { - h.move_storage(defaultTempPath); + QString root_folder = TorrentPersistentData::getRootFolder(hash); + QString torrent_tmp_path = defaultTempPath.replace("\\", "/"); + if(!root_folder.isEmpty()) { + if(!torrent_tmp_path.endsWith("/")) torrent_tmp_path += "/"; + torrent_tmp_path += root_folder; + } + h.move_storage(torrent_tmp_path); } } emit torrentFinishedChecking(h); @@ -2347,17 +2372,6 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } // Clean path savePath = misc::expandPath(savePath); - // Checking if savePath Dir exists - // create it if it is not - QDir saveDir(savePath); - if(!saveDir.exists()) { - if(!saveDir.mkpath(saveDir.absolutePath())) { - std::cerr << "Couldn't create the save directory: " << qPrintable(saveDir.path()) << "\n"; - // XXX: Do something else? - } else { - qDebug("Created save folder at %s", qPrintable(saveDir.path())); - } - } return savePath; } diff --git a/src/src.pro b/src/src.pro index 10f42b8e1..74e9222e1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -3,7 +3,7 @@ LANG_PATH = lang ICONS_PATH = Icons # Set the following variable to 1 to enable debug -DEBUG_MODE = 1 +DEBUG_MODE = 0 # Global TEMPLATE = app @@ -12,14 +12,17 @@ CONFIG += qt \ # Update this VERSION for each release os2 { - DEFINES += VERSION=\'\"v2.3.0rc2\"\' + DEFINES += VERSION=\'\"v2.3.0rc3\"\' } else { - DEFINES += VERSION=\\\"v2.3.0rc2\\\" + DEFINES += VERSION=\\\"v2.3.0rc3\\\" } DEFINES += VERSION_MAJOR=2 DEFINES += VERSION_MINOR=3 DEFINES += VERSION_BUGFIX=0 +# NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL +DEFINES += VERSION_TYPE=RELEASE_CANDIDATE + win32 { # Adapt these paths on Windows INCLUDEPATH += $$quote(C:/qbittorrent/boost_1_42_0) @@ -51,9 +54,6 @@ win32 { } } -# NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL -DEFINES += VERSION_TYPE=ALPHA - # !mac:QMAKE_LFLAGS += -Wl,--as-needed contains(DEBUG_MODE, 1) { CONFIG += debug diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index b24843cf8..8f00b2288 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -226,6 +226,22 @@ public: } return dt; } + + static void setRootFolder(QString hash, QString root_folder) { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); + QHash all_data = settings.value("torrents", QHash()).toHash(); + QHash data = all_data[hash].toHash(); + data.insert("root_folder", root_folder); + all_data[hash] = data; + settings.setValue("torrents", all_data); + } + + static QString getRootFolder(QString hash) { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); + QHash all_data = settings.value("torrents", QHash()).toHash(); + QHash data = all_data[hash].toHash(); + return data.value("root_folder", QString()).toString(); + } static void saveSeedDate(const QTorrentHandle &h) { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));