Browse Source

Harmonize device-id and codecs location with PMS

Use the same directory as PMS, at least on Windows and OSX.

If the user uses PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR on OSX, the
location will still be different, as we don't read this environment
variable.
Vincent Lang 8 years ago
parent
commit
2cac068234
3 changed files with 30 additions and 2 deletions
  1. 2 2
      src/player/CodecsComponent.cpp
  2. 27 0
      src/shared/Paths.cpp
  3. 1 0
      src/shared/Paths.h

+ 2 - 2
src/player/CodecsComponent.cpp

@@ -112,13 +112,13 @@ QString Codecs::plexNameFromFF(QString ffname)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 static QString codecsRootPath()
 {
-  return Paths::dataDir("codecs") + QDir::separator();
+  return Paths::plexCommonDataDir("codecs") + QDir::separator();
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 static QString codecsPath()
 {
-  return codecsRootPath() + getBuildType() + "-" + g_codecVersion + QDir::separator();
+  return codecsRootPath() + "pmp-" + getBuildType() + "-" + g_codecVersion + QDir::separator();
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////

+ 27 - 0
src/shared/Paths.cpp

@@ -49,6 +49,33 @@ QString Paths::dataDir(const QString& file)
   return d.filePath(file);
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+QString Paths::plexCommonDataDir(const QString& file)
+{
+  // To spell it out: this is exactly what PMS does. Except we do not query
+  // PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR, and we use a different path
+  // on generic Unix.
+#ifdef Q_OS_MAC
+  QDir d(qgetenv("HOME"));
+  d.cd("Library");
+  d.cd("Application Support");
+#else
+  QDir d = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+#endif
+
+  if (!d.mkpath(d.absolutePath() + "/" + "Plex"))
+  {
+    QLOG_WARN() << "Failed to create directory:" << d.absolutePath();
+    return QString();
+  }
+
+  d.cd("Plex");
+
+  if (file.isEmpty())
+    return d.absolutePath();
+  return d.filePath(file);
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////
 QString Paths::cacheDir(const QString& file)
 {

+ 1 - 0
src/shared/Paths.h

@@ -13,6 +13,7 @@ namespace Paths
 {
   QString resourceDir(const QString& file = QString());
   QString dataDir(const QString& file = QString());
+  QString plexCommonDataDir(const QString& file = QString());
   QString cacheDir(const QString& file = QString());
   QString logDir(const QString& file = QString());
   QString socketName(const QString& serverName);