diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index c53b0124b..641110788 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -944,6 +944,15 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr QString hash; boost::intrusive_ptr t; +#ifdef Q_WS_WIN + // Windows hack + if(!path.endsWith(".torrent")) { + if(QFile::rename(path, path+".torrent")) + path += ".torrent"; + } + qDebug("Downloading torrent at path: %s", qPrintable(path)); +#endif + // Checking if BT_backup Dir exists // create it if it is not if(! torrentBackup.exists()) { @@ -2302,6 +2311,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit())); if(index < 0) { // Add file to torrent download list +#ifdef Q_WS_WIN + // Windows hack + if(!file_path.endsWith(".torrent")) { + Q_ASSERT(QFile::exists(file_path)); + qDebug("Torrent name does not end with .torrent, fixing..."); + if(QFile::rename(file_path, file_path+".torrent")) { + file_path += ".torrent"; + } else { + qDebug("Failed to rename torrent file!"); + } + } + qDebug("Downloading torrent at path: %s", qPrintable(file_path)); +#endif emit newDownloadedTorrent(file_path, url); } else { url_skippingDlg.removeAt(index); diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index 27974c621..06a2f4398 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -72,26 +72,27 @@ void downloadThread::processDlFinished(QNetworkReply* reply) { } // Success QString filePath; - QTemporaryFile tmpfile; - tmpfile.setAutoRemove(false); - if (tmpfile.open()) { - filePath = tmpfile.fileName(); + QTemporaryFile *tmpfile = new QTemporaryFile; + tmpfile->setAutoRemove(false); + if (tmpfile->open()) { + filePath = tmpfile->fileName(); qDebug("Temporary filename is: %s", qPrintable(filePath)); if(reply->open(QIODevice::ReadOnly)) { // TODO: Support GZIP compression - QByteArray content = reply->readAll(); - //qDebug("Read content: %s", content.data()); - tmpfile.write(content); + tmpfile->write(reply->readAll()); reply->close(); - tmpfile.close(); + tmpfile->close(); + delete tmpfile; // Send finished signal emit downloadFinished(url, filePath); } else { // Error when reading the request - tmpfile.close(); + tmpfile->close(); + delete tmpfile; emit downloadFailure(url, tr("I/O Error")); } } else { + delete tmpfile; emit downloadFailure(url, tr("I/O Error")); } } diff --git a/src/geoip.h b/src/geoip.h index 97546941a..c8bf32b02 100644 --- a/src/geoip.h +++ b/src/geoip.h @@ -68,13 +68,19 @@ protected: // Create geoip folder is necessary QDir gfolder(geoipFolder(false)); if(!gfolder.exists()) { - if(!gfolder.mkpath(geoipFolder(false))) return; + if(!gfolder.mkpath(geoipFolder(false))) { + std::cerr << "Failed to create geoip folder at " << qPrintable(geoipFolder(false)) << std::endl; + return; + } } // Remove destination files if(QFile::exists(geoipDBpath(false))) QFile::remove(geoipDBpath(false)); // Copy from executable to hard disk - QFile::copy(geoipDBpath(true), geoipDBpath(false)); + qDebug("%s -> %s", qPrintable(geoipDBpath(true)), qPrintable(geoipDBpath(false))); + if(!QFile::copy(geoipDBpath(true), geoipDBpath(false))) { + std::cerr << "ERROR: Failed to copy geoip.dat from executable to hard disk" << std::endl; + } qDebug("Local Geoip database was updated"); } } diff --git a/src/geoip.qrc b/src/geoip.qrc index 50758c4f9..ecd5ebef5 100644 --- a/src/geoip.qrc +++ b/src/geoip.qrc @@ -1,5 +1,5 @@ - - - geoip/GeoIP.dat - - + + + geoip/GeoIP.dat + + diff --git a/src/main.cpp b/src/main.cpp index 6b82fc592..537e077ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,6 +168,13 @@ void useStyle(QApplication *app, QString style){ // Main int main(int argc, char *argv[]){ + // Create Application + #ifdef DISABLE_GUI + app = new QCoreApplication(argc, argv); + #else + app = new QApplication(argc, argv); + #endif + QString locale; QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); #ifndef DISABLE_GUI @@ -208,16 +215,10 @@ int main(int argc, char *argv[]){ std::cout << "disconnected\n"; } localSocket.close(); + delete app; return 0; } - // Create Application -#ifdef DISABLE_GUI - app = new QCoreApplication(argc, argv); -#else - app = new QApplication(argc, argv); -#endif - // Load translation locale = settings.value(QString::fromUtf8("Preferences/General/Locale"), QString()).toString(); QTranslator translator; @@ -341,7 +342,10 @@ int main(int argc, char *argv[]){ delete loader; #endif qDebug("Deleting app..."); +#ifndef Q_WS_WIN + // XXX: Why does it crash on Windows!? delete app; +#endif qDebug("App was deleted! All good."); return ret; } diff --git a/src/misc.cpp b/src/misc.cpp index 3eaa69c3a..3a5194201 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -74,6 +74,9 @@ QString misc::QDesktopServicesDataLocation() { result = QString::fromWCharArray(path); if (!QCoreApplication::applicationName().isEmpty()) result = result + QLatin1String("\\") + qApp->applicationName(); + if(!result.endsWith("\\")) + result += "\\"; + return result; #else #ifdef Q_WS_MAC // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html @@ -360,7 +363,7 @@ QString misc::BTBackupLocation() { } QString misc::cacheLocation() { - const QString &location = QDir::cleanPath(QDesktopServicesCacheLocation()); + QString location = QDir::cleanPath(QDesktopServicesCacheLocation()); QDir locationDir(location); if(!locationDir.exists()) locationDir.mkpath(locationDir.absolutePath()); diff --git a/src/preferences.h b/src/preferences.h index 1af30d7ef..90d4c9ed6 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -983,6 +983,18 @@ public: qBTRSS.setValue("hosts_cookies", hosts_table); } +#ifdef Q_WS_WIN + static void setPythonPath(QString path) { + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue(QString::fromUtf8("Preferences/Win32/PythonPath"), path); + } + + static QString getPythonPath() { + QSettings settings("qBittorrent", "qBittorrent"); + return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString(); + } +#endif + }; #endif // PREFERENCES_H diff --git a/src/searchengine.cpp b/src/searchengine.cpp index 1a133f48f..4abc6ef18 100644 --- a/src/searchengine.cpp +++ b/src/searchengine.cpp @@ -42,11 +42,17 @@ #include #include #include +#include + +#ifdef Q_WS_WIN +#include +#endif #include "searchengine.h" #include "bittorrent.h" #include "downloadthread.h" #include "misc.h" +#include "preferences.h" #include "searchlistdelegate.h" #include "GUI.h" @@ -72,13 +78,11 @@ SearchEngine::SearchEngine(GUI *parent, Bittorrent *BTSession) : QWidget(parent) // Boolean initialization search_stopped = false; // Creating Search Process - searchProcess = new QProcess(this); - QStringList env = QProcess::systemEnvironment(); #ifdef Q_WS_WIN - // add qBittorrent executable folder to PATH environment variable - qDebug("qBittorrent executable path: %s", qPrintable(qApp->applicationDirPath())); - env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+qApp->applicationDirPath()); + checkForPythonExe(); #endif + searchProcess = new QProcess(this); + QStringList env = QProcess::systemEnvironment(); searchProcess->setEnvironment(env); connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted())); connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); @@ -106,6 +110,59 @@ void SearchEngine::fillCatCombobox() { } } +#ifdef Q_WS_WIN +void SearchEngine::checkForPythonExe() { + QString python_path = Preferences::getPythonPath(); + if(python_path.isEmpty() || !QFile::exists(python_path+QDir::separator()+"python.exe")) { + // Attempt to detect python in standard location + QStringList filters; + filters << "Python25" << "Python26"; + QStringList python_folders = QDir::root().entryList(filters, QDir::Dirs, QDir::Name); + if(!python_folders.isEmpty()) { + python_path = QDir::root().absoluteFilePath(python_folders.last()); + qDebug("Detected python folder at %s", qPrintable(python_path)); + } else { + filters.clear(); + filters << "Python*"; + python_folders = QDir::root().entryList(filters, QDir::Dirs, QDir::Name); + if(!python_folders.isEmpty()) { + python_path = QDir::root().absoluteFilePath(python_folders.last()); + qDebug("Detected python folder at %s", qPrintable(python_path)); + } else { + qDebug("Failed to detect Python folder"); + } + } + } + if(python_path.isEmpty() || !QFile::exists(python_path+QDir::separator()+"python.exe")) { + QMessageBox::warning(0, tr("Failed to locate the Python interpreter"), tr("The Python interpreter was not found.\nqBittorrent will now ask you to point to its correct location.")); + QString python_exe_path = QFileDialog::getOpenFileName(0, tr("Please point to its location on your hard disk."), + QDir::root().absolutePath(), tr("Python executable (python.exe)")); + if(python_exe_path.isEmpty() || !QFile::exists(python_exe_path)) { + QMessageBox::warning(0, tr("No Python interpreter"), tr("The Python interpreter is missing. qBittorrent search engine will not work.")); + return; + } + qDebug("Python exe path is: %s", qPrintable(python_exe_path)); + QStringList tmp_list = python_exe_path.split(QDir::separator()); + if(tmp_list.size() == 1) + tmp_list = tmp_list.first().split("/"); + tmp_list.removeLast(); + python_path = tmp_list.join(QDir::separator()); + qDebug("New Python path is: %s", qPrintable(python_path)); + // Save python path + Preferences::setPythonPath(python_path); + } + // Add it to PATH envvar + QString path_envar = QString::fromLocal8Bit(getenv("PATH")); + if(path_envar.isNull()) { + path_envar = ""; + } + path_envar = python_path+";"+path_envar; + qDebug("New PATH envvar is: %s", qPrintable(path_envar)); + QString envar = "PATH="+path_envar; + putenv(envar.toLocal8Bit().data()); +} +#endif + QString SearchEngine::selectedCategory() const { return comboCategory->itemData(comboCategory->currentIndex()).toString(); } diff --git a/src/searchengine.h b/src/searchengine.h index c8343e5b4..0eafa817e 100644 --- a/src/searchengine.h +++ b/src/searchengine.h @@ -126,6 +126,9 @@ protected slots: void createCompleter(); void fillCatCombobox(); void searchTextEdited(QString); +#ifdef Q_WS_WIN + void checkForPythonExe(); +#endif }; #endif diff --git a/src/src.pro b/src/src.pro index b2289dcb2..1b456823a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -22,7 +22,7 @@ DEFINES += VERSION_BUGFIX=0 win32 { # Adapt these paths on Windows - INCLUDEPATH += $$quote(C:/qbittorrent/boost_1_40_0) + INCLUDEPATH += $$quote(C:/qbittorrent/boost_1_42_0) INCLUDEPATH += $$quote(C:/qbittorrent/libtorrent-rasterbar-0.14.10/include) INCLUDEPATH += $$quote(C:/qbittorrent/libtorrent-rasterbar-0.14.10/zlib) @@ -133,27 +133,27 @@ DEFINES += QT_USE_FAST_CONCATENATION QT_USE_FAST_OPERATOR_PLUS # win32:LIBS += -ltorrent -lboost_system # win32:LIBS += -lz ? win32 { - LIBS += -lssleay32 \ - -leay32 \ - -lws2_32 \ - -lwsock32 \ - -ladvapi32 \ - -lwinmm # Adapt these paths on Windows LIBS += C:/qbittorrent/libs/libtorrent.lib \ - C:/qbittorrent/libs/libboost_system.lib \ - C:/qbittorrent/libs/libboost_filesystem.lib \ - C:/qbittorrent/libs/libboost_thread.lib \ - C:/Qt/2010.02.1/mingw/lib/*.a \ - C:/Qt/2010.02.1/mingw/lib/libssleay32.a \ - C:/Qt/2010.02.1/mingw/lib/libeay32.a \ - C:/Qt/2010.02.1/mingw/lib/libws2_32.a \ + C:/qbittorrent/libs/libboost_system-mgw44-mt-s.lib \ + C:/qbittorrent/libs/libboost_filesystem-mgw44-mt-s.lib \ + C:/qbittorrent/libs/libboost_thread-mgw44-mt-s.lib \ + C:/OpenSSL/lib/MinGW/ssleay32.a \ + C:/OpenSSL/lib/MinGW/libeay32.a \ C:/Qt/2010.02.1/mingw/lib/libwsock32.a \ - C:/Qt/2010.02.1/mingw/lib/libadvapi32.a \ - C:/Qt/2010.02.1/mingw/lib/libwinmm.a \ - C:/Qt/2010.02.1/mingw/lib/libgdi32.a \ - -LC:/Qt/2010.02.1/mingw/lib/ + C:/Qt/2010.02.1/mingw/lib/libws2_32.a #\ +# -LC:/Qt/2010.02.1/mingw/lib/ +# C:/Qt/2010.02.1/mingw/lib/libadvapi32.a \ +# C:/Qt/2010.02.1/mingw/lib/libwinmm.a \ +# C:/Qt/2010.02.1/mingw/lib/libgdi32.a \ + +# LIBS += -lssleay32 \ +# -leay32 \ +# -lws2_32 \ +# -lwsock32 \ +# -ladvapi32 \ +# -lwinmm } os2:LIBS += -ltorrent-rasterbar \ @@ -177,6 +177,12 @@ os2:LIBS += -ltorrent-rasterbar \ } unix:!macx:contains(DEFINES, WITH_GEOIP_EMBEDDED):message("You chose to embed GeoIP database in qBittorrent executable.") +# Resource files +RESOURCES = icons.qrc \ + lang.qrc \ + search.qrc \ + webui.qrc + # Add GeoIP resource file if the GeoIP database # should be embedded in qBittorrent executable contains(DEFINES, WITH_GEOIP_EMBEDDED) { @@ -192,12 +198,6 @@ os2:LIBS += -ltorrent-rasterbar \ else:message("GeoIP database will not be embedded in qBittorrent executable.") } -# Resource files -RESOURCES = icons.qrc \ - lang.qrc \ - search.qrc \ - webui.qrc - # Translations TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \ $$LANG_PATH/qbittorrent_zh.ts \ diff --git a/src/supportedengines.h b/src/supportedengines.h index 42abd9330..6befad83d 100644 --- a/src/supportedengines.h +++ b/src/supportedengines.h @@ -39,6 +39,7 @@ #include #include #include +#include #include "misc.h" @@ -139,6 +140,7 @@ public: public slots: void update() { QProcess nova; + nova.setEnvironment(QProcess::systemEnvironment()); QStringList params; params << misc::searchEngineLocation()+QDir::separator()+"nova2.py"; params << "--capabilities"; @@ -149,6 +151,7 @@ public slots: QDomDocument xml_doc; if(!xml_doc.setContent(capabilities)) { std::cerr << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data() << std::endl; + std::cerr << "Error: " << nova.readAllStandardError().constData() << std::endl; return; } QDomElement root = xml_doc.documentElement();