浏览代码

Move local sockets to default path. This fixes a startup error on OSX

Fixes #45
Tobias Hieta 9 年之前
父节点
当前提交
a625ef1a9f
共有 4 个文件被更改,包括 21 次插入5 次删除
  1. 1 2
      src/shared/LocalJsonClient.cpp
  2. 1 3
      src/shared/LocalJsonServer.cpp
  3. 16 0
      src/shared/Paths.cpp
  4. 3 0
      src/shared/Paths.h

+ 1 - 2
src/shared/LocalJsonClient.cpp

@@ -5,12 +5,11 @@
 #include "Paths.h"
 #include "LocalJsonClient.h"
 #include "LocalJsonServer.h"
-#include "utils/Utils.h"
 
 /////////////////////////////////////////////////////////////////////////////////////////
 LocalJsonClient::LocalJsonClient(const QString serverPath, QObject* parent) : QLocalSocket(parent)
 {
-  m_serverPath = Paths::dataDir(serverPath);
+  m_serverPath = Paths::socketName(serverPath);
   connect(this, &QLocalSocket::readyRead, this, &LocalJsonClient::readyRead);
 }
 

+ 1 - 3
src/shared/LocalJsonServer.cpp

@@ -6,13 +6,11 @@
 #include "Paths.h"
 #include "QsLog.h"
 
-#include <QFile>
-
 /////////////////////////////////////////////////////////////////////////////////////////
 LocalJsonServer::LocalJsonServer(const QString& serverName, QObject* parent) : QObject(parent)
 {
   m_server = new QLocalServer(this);
-  m_serverName = Paths::dataDir(serverName);
+  m_serverName = Paths::socketName(serverName);
 
   connect(m_server, &QLocalServer::newConnection, this, &LocalJsonServer::serverClientConnected);
 }

+ 16 - 0
src/shared/Paths.cpp

@@ -2,6 +2,9 @@
 // Created by Tobias Hieta on 01/09/15.
 //
 
+#include "settings/SettingsSection.h"
+#include "settings/SettingsComponent.h"
+#include "utils/Utils.h"
 #include "Paths.h"
 
 #include <QDir>
@@ -72,3 +75,16 @@ QString Paths::logDir(const QString& file)
   return ldir.filePath(file);
 #endif
 }
+
+/////////////////////////////////////////////////////////////////////////////////////////
+QString Paths::socketName(const QString& serverName)
+{
+  QString userName = qgetenv("USER");
+
+  if(userName.isEmpty())
+    userName = qgetenv("USERNAME");
+  if(userName.isEmpty())
+    userName = "unknown";
+
+  return QString("pmp_%1_%2.sock").arg(serverName).arg(userName);
+}

+ 3 - 0
src/shared/Paths.h

@@ -6,6 +6,8 @@
 #define KONVERGO_PATHS_H
 
 #include <QString>
+#include <QUrl>
+#include <QVariant>
 
 namespace Paths
 {
@@ -13,6 +15,7 @@ namespace Paths
   QString dataDir(const QString& file = QString());
   QString cacheDir(const QString& file = QString());
   QString logDir(const QString& file = QString());
+  QString socketName(const QString& serverName);
 };
 
 #endif //KONVERGO_PATHS_H