Преглед изворни кода

Possible fix to find the web-client path on Linux

Tobias Hieta пре 8 година
родитељ
комит
2e6bc031bd
3 измењених фајлова са 28 додато и 8 уклоњено
  1. 1 1
      CMakeModules/LinuxConfiguration.cmake
  2. 6 1
      src/CMakeLists.txt
  3. 21 6
      src/shared/Paths.cpp

+ 1 - 1
CMakeModules/LinuxConfiguration.cmake

@@ -14,4 +14,4 @@ if (NOT BUILD_TARGET STREQUAL "RPI")
 endif()
 
 set(INSTALL_BIN_DIR bin)
-set(INSTALL_RESOURCE_DIR .)
+set(INSTALL_RESOURCE_DIR share/plexmediaplayer)

+ 6 - 1
src/CMakeLists.txt

@@ -116,7 +116,12 @@ if(WIN32)
   list(APPEND RESOURCE_FILES ${CMAKE_SOURCE_DIR}/bundle/win/iconres.rc)
 endif()
 
-add_resources(TARGET ${MAIN_TARGET} SOURCES ${WEB_CLIENT_DIR} DEST ${INSTALL_RESOURCE_DIR}/web-client-${WEB_CLIENT_VERSTR})
+set(RESOURCE_ROOT .)
+if(APPLE)
+  set(RESOURCE_ROOT Resources)
+endif()
+
+add_resources(TARGET ${MAIN_TARGET} SOURCES ${WEB_CLIENT_DIR} DEST ${RESOURCE_ROOT}/web-client-${WEB_CLIENT_VERSTR})
 if(NOT APPLE)
   install(DIRECTORY ${WEB_CLIENT_DIR} DESTINATION ${INSTALL_RESOURCE_DIR})
 endif()

+ 21 - 6
src/shared/Paths.cpp

@@ -29,16 +29,31 @@ static QDir writableLocation(QStandardPaths::StandardLocation loc)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
+// Try a couple of different strategies to find the file we are looking for.
+// 1) By looking next to the application binary
+// 2) By looking in binary/../Resources
+// 3) By looking in PREFIX/share/plexmediaplayer
+// 4) By looking in PREFIX/plexmediaplayer
+//
 QString Paths::resourceDir(const QString& file)
 {
-  auto resourceDir = QDir(QGuiApplication::applicationDirPath());
+  auto appResourceDir = QGuiApplication::applicationDirPath() + "/";
+  auto prefixDir = QString(PREFIX);
 
-#ifdef Q_OS_MAC
-  resourceDir.cdUp();
-  resourceDir.cd("Resources");
-#endif
+  QStringList possibleResourceDirs = {
+    appResourceDir,
+    appResourceDir + "../Resources/",
+    prefixDir + "/share/plexmediaplayer/",
+    prefixDir + "/plexmediaplayer/"
+  };
+
+  for (const auto& fileStr : possibleResourceDirs)
+  {
+    if (QFile::exists(fileStr + file))
+      return fileStr + file;
+  }
 
-  return resourceDir.filePath(file);
+  return appResourceDir + file;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////