Quellcode durchsuchen

CodecsComponent: delete old unneeded codecs

Vincent Lang vor 7 Jahren
Ursprung
Commit
45c74c4a46
3 geänderte Dateien mit 47 neuen und 3 gelöschten Zeilen
  1. 45 1
      src/player/CodecsComponent.cpp
  2. 1 1
      src/player/CodecsComponent.h
  3. 1 1
      src/player/PlayerComponent.cpp

+ 45 - 1
src/player/CodecsComponent.cpp

@@ -2,6 +2,7 @@
 #include <QString>
 #include <Qt>
 #include <QDir>
+#include <QDirIterator>
 #include <QDomAttr>
 #include <QDomDocument>
 #include <QDomNode>
@@ -410,7 +411,7 @@ static bool probeDecoder(QString decoder, QString resourceName)
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-void Codecs::probeCodecs()
+static void probeCodecs()
 {
   if (g_deviceID.isEmpty())
     throw FatalException("Could not read device-id.");
@@ -440,6 +441,49 @@ void Codecs::probeCodecs()
   Codecs::updateCachedCodecList();
 }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+static void deleteOldCodecs()
+{
+  QStringList neededPaths = {
+    codecsPath(),
+  };
+
+  for (auto entry : QDir(codecsRootPath()).entryList(QDir::Dirs | QDir::NoDotAndDotDot))
+  {
+    QDir entryPath = codecsRootPath();
+    if (!entryPath.cd(entry))
+      continue;
+
+    bool needed = false;
+
+    for (auto neededPath : neededPaths)
+    {
+      if (entryPath.absolutePath() == QDir(neededPath).absolutePath())
+      {
+        needed = true;
+        break;
+      }
+    }
+
+    if (needed)
+      continue;
+
+    // Same version, but different platform -> just keep it.
+    if (entry.startsWith(g_codecVersion + "-"))
+      continue;
+
+    QLOG_DEBUG() << "Deleting old directory: " << entryPath.absolutePath();
+    entryPath.removeRecursively();
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+void Codecs::initCodecs()
+{
+  deleteOldCodecs();
+  probeCodecs();
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 bool CodecsFetcher::codecNeedsDownload(const CodecDriver& codec)
 {

+ 1 - 1
src/player/CodecsComponent.h

@@ -120,7 +120,7 @@ class Codecs
 public:
   static void preinitCodecs();
 
-  static void probeCodecs();
+  static void initCodecs();
 
   static QString plexNameToFF(QString plex);
 

+ 1 - 1
src/player/PlayerComponent.cpp

@@ -168,7 +168,7 @@ bool PlayerComponent::componentInitialize()
           this, &PlayerComponent::setAudioConfiguration);
 
   initializeCodecSupport();
-  Codecs::probeCodecs();
+  Codecs::initCodecs();
 
   QString codecInfo;
   for (auto codec : Codecs::getCachedCodecList())