mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-09 20:01:08 +00:00
Windows execution fixes
This commit is contained in:
parent
58a36f7cfd
commit
338d4fd31e
@ -944,6 +944,15 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||
QString hash;
|
||||
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
|
||||
// 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);
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
10
src/geoip.h
10
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");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>geoip/GeoIP.dat</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
<RCC>
|
||||
<qresource>
|
||||
<file>geoip/GeoIP.dat</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
18
src/main.cpp
18
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;
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -42,11 +42,17 @@
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QFileDialog>
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
#ifdef Q_WS_WIN
|
||||
checkForPythonExe();
|
||||
#endif
|
||||
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());
|
||||
#endif
|
||||
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();
|
||||
}
|
||||
|
@ -126,6 +126,9 @@ protected slots:
|
||||
void createCompleter();
|
||||
void fillCatCombobox();
|
||||
void searchTextEdited(QString);
|
||||
#ifdef Q_WS_WIN
|
||||
void checkForPythonExe();
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
48
src/src.pro
48
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 \
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <QProcess>
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
|
||||
#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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user