From a98a002d57d1f92f9f593741c36b03f88a6fcf5f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 27 Mar 2010 09:03:37 +0000 Subject: [PATCH] Compilation fix on Windows (getuid missing) --- src/GUI.cpp | 14 +++++++++++++- src/main.cpp | 13 +++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index fc74ffa97..83d4abd64 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -66,6 +66,10 @@ #include "propertieswidget.h" #include "statusbar.h" +#ifdef W_WS_WIN +#include +#endif + using namespace libtorrent; #define TIME_TRAY_BALLOON 5000 @@ -161,7 +165,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis processParams(torrentCmdLine); // Use a tcp server to allow only one instance of qBittorrent localServer = new QLocalServer(); - QString uid = QString::number(getuid()); + QString uid = ""; +#ifdef Q_WS_WIN + char buffer[255] = {0}; + DWORD buffer_len; + if (!GetUserName(buffer, &buffer_len)) + uid = QString(buffer) +#else + uid = QString::number(getuid()); +#endif #ifdef Q_WS_X11 if(QFile::exists(QDir::tempPath()+QDir::separator()+QString("qBittorrent-")+uid)) { // Socket was not closed cleanly diff --git a/src/main.cpp b/src/main.cpp index 622ef3dfe..0e9a34733 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,8 @@ #include #include #include "stacktrace.h" +#else +#include #endif #include @@ -169,7 +171,6 @@ void useStyle(QApplication *app, QString style){ // Main int main(int argc, char *argv[]){ - QFile file; QString locale; QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); #ifndef DISABLE_GUI @@ -178,7 +179,15 @@ int main(int argc, char *argv[]){ //Check if there is another instance running QLocalSocket localSocket; - QString uid = QString::number(getuid()); + QString uid; +#ifdef Q_WS_WIN + char buffer[255] = {0}; + DWORD buffer_len; + if (!GetUserName(buffer, &buffer_len)) + uid = QString(buffer) +#else + uid = QString::number(getuid()); +#endif localSocket.connectToServer("qBittorrent-"+uid, QIODevice::WriteOnly); if (localSocket.waitForConnected(1000)){ std::cout << "Another qBittorrent instance is already running...\n";