Browse Source

Windows execution fixes

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
338d4fd31e
  1. 22
      src/bittorrent.cpp
  2. 19
      src/downloadthread.cpp
  3. 10
      src/geoip.h
  4. 10
      src/geoip.qrc
  5. 18
      src/main.cpp
  6. 5
      src/misc.cpp
  7. 12
      src/preferences.h
  8. 67
      src/searchengine.cpp
  9. 3
      src/searchengine.h
  10. 48
      src/src.pro
  11. 3
      src/supportedengines.h

22
src/bittorrent.cpp

@ -944,6 +944,15 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
QString hash; QString hash;
boost::intrusive_ptr<torrent_info> t; boost::intrusive_ptr<torrent_info> 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 // Checking if BT_backup Dir exists
// create it if it is not // create it if it is not
if(! torrentBackup.exists()) { if(! torrentBackup.exists()) {
@ -2302,6 +2311,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit())); const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
if(index < 0) { if(index < 0) {
// Add file to torrent download list // 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); emit newDownloadedTorrent(file_path, url);
} else { } else {
url_skippingDlg.removeAt(index); url_skippingDlg.removeAt(index);

19
src/downloadthread.cpp

@ -72,26 +72,27 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
} }
// Success // Success
QString filePath; QString filePath;
QTemporaryFile tmpfile; QTemporaryFile *tmpfile = new QTemporaryFile;
tmpfile.setAutoRemove(false); tmpfile->setAutoRemove(false);
if (tmpfile.open()) { if (tmpfile->open()) {
filePath = tmpfile.fileName(); filePath = tmpfile->fileName();
qDebug("Temporary filename is: %s", qPrintable(filePath)); qDebug("Temporary filename is: %s", qPrintable(filePath));
if(reply->open(QIODevice::ReadOnly)) { if(reply->open(QIODevice::ReadOnly)) {
// TODO: Support GZIP compression // TODO: Support GZIP compression
QByteArray content = reply->readAll(); tmpfile->write(reply->readAll());
//qDebug("Read content: %s", content.data());
tmpfile.write(content);
reply->close(); reply->close();
tmpfile.close(); tmpfile->close();
delete tmpfile;
// Send finished signal // Send finished signal
emit downloadFinished(url, filePath); emit downloadFinished(url, filePath);
} else { } else {
// Error when reading the request // Error when reading the request
tmpfile.close(); tmpfile->close();
delete tmpfile;
emit downloadFailure(url, tr("I/O Error")); emit downloadFailure(url, tr("I/O Error"));
} }
} else { } else {
delete tmpfile;
emit downloadFailure(url, tr("I/O Error")); emit downloadFailure(url, tr("I/O Error"));
} }
} }

10
src/geoip.h

@ -68,13 +68,19 @@ protected:
// Create geoip folder is necessary // Create geoip folder is necessary
QDir gfolder(geoipFolder(false)); QDir gfolder(geoipFolder(false));
if(!gfolder.exists()) { 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 // Remove destination files
if(QFile::exists(geoipDBpath(false))) if(QFile::exists(geoipDBpath(false)))
QFile::remove(geoipDBpath(false)); QFile::remove(geoipDBpath(false));
// Copy from executable to hard disk // 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"); qDebug("Local Geoip database was updated");
} }
} }

10
src/geoip.qrc

@ -1,5 +1,5 @@
<RCC> <RCC>
<qresource prefix="/" > <qresource>
<file>geoip/GeoIP.dat</file> <file>geoip/GeoIP.dat</file>
</qresource> </qresource>
</RCC> </RCC>

18
src/main.cpp

@ -168,6 +168,13 @@ void useStyle(QApplication *app, QString style){
// Main // Main
int main(int argc, char *argv[]){ 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; QString locale;
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
@ -208,16 +215,10 @@ int main(int argc, char *argv[]){
std::cout << "disconnected\n"; std::cout << "disconnected\n";
} }
localSocket.close(); localSocket.close();
delete app;
return 0; return 0;
} }
// Create Application
#ifdef DISABLE_GUI
app = new QCoreApplication(argc, argv);
#else
app = new QApplication(argc, argv);
#endif
// Load translation // Load translation
locale = settings.value(QString::fromUtf8("Preferences/General/Locale"), QString()).toString(); locale = settings.value(QString::fromUtf8("Preferences/General/Locale"), QString()).toString();
QTranslator translator; QTranslator translator;
@ -341,7 +342,10 @@ int main(int argc, char *argv[]){
delete loader; delete loader;
#endif #endif
qDebug("Deleting app..."); qDebug("Deleting app...");
#ifndef Q_WS_WIN
// XXX: Why does it crash on Windows!?
delete app; delete app;
#endif
qDebug("App was deleted! All good."); qDebug("App was deleted! All good.");
return ret; return ret;
} }

5
src/misc.cpp

@ -74,6 +74,9 @@ QString misc::QDesktopServicesDataLocation() {
result = QString::fromWCharArray(path); result = QString::fromWCharArray(path);
if (!QCoreApplication::applicationName().isEmpty()) if (!QCoreApplication::applicationName().isEmpty())
result = result + QLatin1String("\\") + qApp->applicationName(); result = result + QLatin1String("\\") + qApp->applicationName();
if(!result.endsWith("\\"))
result += "\\";
return result;
#else #else
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html
@ -360,7 +363,7 @@ QString misc::BTBackupLocation() {
} }
QString misc::cacheLocation() { QString misc::cacheLocation() {
const QString &location = QDir::cleanPath(QDesktopServicesCacheLocation()); QString location = QDir::cleanPath(QDesktopServicesCacheLocation());
QDir locationDir(location); QDir locationDir(location);
if(!locationDir.exists()) if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath()); locationDir.mkpath(locationDir.absolutePath());

12
src/preferences.h

@ -983,6 +983,18 @@ public:
qBTRSS.setValue("hosts_cookies", hosts_table); 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 #endif // PREFERENCES_H

67
src/searchengine.cpp

@ -42,11 +42,17 @@
#include <QClipboard> #include <QClipboard>
#include <QMimeData> #include <QMimeData>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QFileDialog>
#ifdef Q_WS_WIN
#include <stdlib.h>
#endif
#include "searchengine.h" #include "searchengine.h"
#include "bittorrent.h" #include "bittorrent.h"
#include "downloadthread.h" #include "downloadthread.h"
#include "misc.h" #include "misc.h"
#include "preferences.h"
#include "searchlistdelegate.h" #include "searchlistdelegate.h"
#include "GUI.h" #include "GUI.h"
@ -72,13 +78,11 @@ SearchEngine::SearchEngine(GUI *parent, Bittorrent *BTSession) : QWidget(parent)
// Boolean initialization // Boolean initialization
search_stopped = false; search_stopped = false;
// Creating Search Process // Creating Search Process
searchProcess = new QProcess(this);
QStringList env = QProcess::systemEnvironment();
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
// add qBittorrent executable folder to PATH environment variable checkForPythonExe();
qDebug("qBittorrent executable path: %s", qPrintable(qApp->applicationDirPath()));
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+qApp->applicationDirPath());
#endif #endif
searchProcess = new QProcess(this);
QStringList env = QProcess::systemEnvironment();
searchProcess->setEnvironment(env); searchProcess->setEnvironment(env);
connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted())); connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted()));
connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); 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 { QString SearchEngine::selectedCategory() const {
return comboCategory->itemData(comboCategory->currentIndex()).toString(); return comboCategory->itemData(comboCategory->currentIndex()).toString();
} }

3
src/searchengine.h

@ -126,6 +126,9 @@ protected slots:
void createCompleter(); void createCompleter();
void fillCatCombobox(); void fillCatCombobox();
void searchTextEdited(QString); void searchTextEdited(QString);
#ifdef Q_WS_WIN
void checkForPythonExe();
#endif
}; };
#endif #endif

48
src/src.pro

@ -22,7 +22,7 @@ DEFINES += VERSION_BUGFIX=0
win32 { win32 {
# Adapt these paths on Windows # 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/include)
INCLUDEPATH += $$quote(C:/qbittorrent/libtorrent-rasterbar-0.14.10/zlib) 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 += -ltorrent -lboost_system
# win32:LIBS += -lz ? # win32:LIBS += -lz ?
win32 { win32 {
LIBS += -lssleay32 \
-leay32 \
-lws2_32 \
-lwsock32 \
-ladvapi32 \
-lwinmm
# Adapt these paths on Windows # Adapt these paths on Windows
LIBS += C:/qbittorrent/libs/libtorrent.lib \ LIBS += C:/qbittorrent/libs/libtorrent.lib \
C:/qbittorrent/libs/libboost_system.lib \ C:/qbittorrent/libs/libboost_system-mgw44-mt-s.lib \
C:/qbittorrent/libs/libboost_filesystem.lib \ C:/qbittorrent/libs/libboost_filesystem-mgw44-mt-s.lib \
C:/qbittorrent/libs/libboost_thread.lib \ C:/qbittorrent/libs/libboost_thread-mgw44-mt-s.lib \
C:/Qt/2010.02.1/mingw/lib/*.a \ C:/OpenSSL/lib/MinGW/ssleay32.a \
C:/Qt/2010.02.1/mingw/lib/libssleay32.a \ C:/OpenSSL/lib/MinGW/libeay32.a \
C:/Qt/2010.02.1/mingw/lib/libeay32.a \
C:/Qt/2010.02.1/mingw/lib/libws2_32.a \
C:/Qt/2010.02.1/mingw/lib/libwsock32.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/libws2_32.a #\
C:/Qt/2010.02.1/mingw/lib/libwinmm.a \ # -LC:/Qt/2010.02.1/mingw/lib/
C:/Qt/2010.02.1/mingw/lib/libgdi32.a \ # C:/Qt/2010.02.1/mingw/lib/libadvapi32.a \
-LC:/Qt/2010.02.1/mingw/lib/ # 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 \ 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.") 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 # Add GeoIP resource file if the GeoIP database
# should be embedded in qBittorrent executable # should be embedded in qBittorrent executable
contains(DEFINES, WITH_GEOIP_EMBEDDED) { contains(DEFINES, WITH_GEOIP_EMBEDDED) {
@ -192,12 +198,6 @@ os2:LIBS += -ltorrent-rasterbar \
else:message("GeoIP database will not be embedded in qBittorrent executable.") else:message("GeoIP database will not be embedded in qBittorrent executable.")
} }
# Resource files
RESOURCES = icons.qrc \
lang.qrc \
search.qrc \
webui.qrc
# Translations # Translations
TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \ TRANSLATIONS = $$LANG_PATH/qbittorrent_fr.ts \
$$LANG_PATH/qbittorrent_zh.ts \ $$LANG_PATH/qbittorrent_zh.ts \

3
src/supportedengines.h

@ -39,6 +39,7 @@
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QDir> #include <QDir>
#include <QApplication>
#include "misc.h" #include "misc.h"
@ -139,6 +140,7 @@ public:
public slots: public slots:
void update() { void update() {
QProcess nova; QProcess nova;
nova.setEnvironment(QProcess::systemEnvironment());
QStringList params; QStringList params;
params << misc::searchEngineLocation()+QDir::separator()+"nova2.py"; params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
params << "--capabilities"; params << "--capabilities";
@ -149,6 +151,7 @@ public slots:
QDomDocument xml_doc; QDomDocument xml_doc;
if(!xml_doc.setContent(capabilities)) { if(!xml_doc.setContent(capabilities)) {
std::cerr << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data() << std::endl; std::cerr << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data() << std::endl;
std::cerr << "Error: " << nova.readAllStandardError().constData() << std::endl;
return; return;
} }
QDomElement root = xml_doc.documentElement(); QDomElement root = xml_doc.documentElement();

Loading…
Cancel
Save