All pastes #1665648 Raw Edit

Anonymous

public diff v1 · immutable
#1665648 ·published 2009-11-10 23:56 UTC
rendered paste body
diff --git a/xbmc/FileSystem/StackDirectory.cpp b/xbmc/FileSystem/StackDirectory.cppindex f62c5c7..6710451 100644--- a/xbmc/FileSystem/StackDirectory.cpp+++ b/xbmc/FileSystem/StackDirectory.cpp@@ -24,6 +24,7 @@ #include "Util.h" #include "FileItem.h" #include "StringUtils.h"+#include "AdvancedSettings.h"  #define PRE_2_1_STACK_COMPATIBILITY @@ -79,19 +80,93 @@ namespace DIRECTORY    CStdString CStackDirectory::GetStackedTitlePath(const CStdString &strPath)   {-    CStdString path, file, folder;-    int pos = strPath.Find(" , ");-    // remove "stack://" from the folder-    if (pos > 0)+    // Load up our REs+    VECCREGEXP  RegExps;+    CRegExp     tempRE(true);+    const CStdStringArray& strRegExps = g_advancedSettings.m_videoStackRegExps;+    CStdStringArray::const_iterator itRegExp = strRegExps.begin();+    vector<pair<int, CStdString> > badStacks;+    while (itRegExp != strRegExps.end())     {-      CUtil::Split(strPath.Left(pos), folder, file);-      file.Replace(",,", ",");-      folder = folder.Mid(8);-      CStdString title, volume;-      CUtil::GetVolumeFromFileName(file, title, volume);-      CUtil::AddFileToFolder(folder, title, path);+      tempRE.RegComp(*itRegExp);+      if (tempRE.GetCaptureTotal() == 4)+        RegExps.push_back(tempRE);+      else+        CLog::Log(LOGERROR, "Invalid video stack RE (%s). Must have exactly 4 captures.", itRegExp->c_str());+      itRegExp++;     }-    return path;+    return GetStackedTitlePath(strPath, RegExps);+  }++  CStdString CStackDirectory::GetStackedTitlePath(const CStdString &strPath, VECCREGEXP& RegExps)+  {+    CStackDirectory stack;+    CFileItemList   files;+    CStdString      File1,+                    File2,+                    strStackTitlePath,+                    strStackTitle,+                    strCommonDir        = CUtil::GetParentPath(strPath);+    +    stack.GetDirectory(strPath, files);++    if (files.Size() > 1)+    {++      File1 = CUtil::GetFileName(files[0]->m_strPath);+      File2 = CUtil::GetFileName(files[1]->m_strPath);++      std::vector<CRegExp>::iterator itRegExp = RegExps.begin();+      int offset = 0;++      while (itRegExp != RegExps.end())+      {+        if (itRegExp->RegFind(File1, offset) != -1)+        {+          CStdString Title1     = itRegExp->GetMatch(1),+                     Volume1    = itRegExp->GetMatch(2),+                     Ignore1    = itRegExp->GetMatch(3),+                     Extension1 = itRegExp->GetMatch(4);+          if (offset)+            Title1 = File1.substr(0, itRegExp->GetSubStart(2));+          if (itRegExp->RegFind(File2, offset) != -1)+          {+            CStdString Title2     = itRegExp->GetMatch(1),+                       Volume2    = itRegExp->GetMatch(2),+                       Ignore2    = itRegExp->GetMatch(3),+                       Extension2 = itRegExp->GetMatch(4);+            if (offset)+              Title2 = File2.substr(0, itRegExp->GetSubStart(2));+            if (Title1.Equals(Title2))+            {+              if (!Volume1.Equals(Volume2))+              {+                if (Ignore1.Equals(Ignore2) && Extension1.Equals(Extension2))+                {+                  // got it+                  strStackTitle = Title1 + Extension1;+                  itRegExp = RegExps.end();+                  break;+                }+                else // Invalid stack+                  break;+              }+              else // Early match, retry with offset+              {+                offset = itRegExp->GetSubStart(3);+                continue;+              }+            }+          }+        }+        offset = 0;+        itRegExp++;+      }+      if (!strCommonDir.empty() && !strStackTitle.empty())+        strStackTitlePath = strCommonDir + strStackTitle;+    }++    return strStackTitlePath;   }    CStdString CStackDirectory::GetFirstStackedFile(const CStdString &strPath)diff --git a/xbmc/FileSystem/StackDirectory.h b/xbmc/FileSystem/StackDirectory.hindex 63eefc9..3c67688 100644--- a/xbmc/FileSystem/StackDirectory.h+++ b/xbmc/FileSystem/StackDirectory.h@@ -22,6 +22,7 @@   #include "IDirectory.h"+#include "utils/RegExp.h"  namespace DIRECTORY {@@ -33,6 +34,7 @@ namespace DIRECTORY     virtual bool GetDirectory(const CStdString& strPath, CFileItemList& items);     virtual bool IsAllowed(const CStdString &strFile) const { return true; };     static CStdString GetStackedTitlePath(const CStdString &strPath);+    static CStdString GetStackedTitlePath(const CStdString &strPath, VECCREGEXP& RegExps);     static CStdString GetFirstStackedFile(const CStdString &strPath);     CStdString ConstructStackPath(const CFileItemList& items, const std::vector<int> &stack);     bool ConstructStackPath(const std::vector<CStdString> &paths, CStdString &stackedPath);diff --git a/xbmc/Util.cpp b/xbmc/Util.cppindex 29b9c6a..3e557b5 100644--- a/xbmc/Util.cpp+++ b/xbmc/Util.cpp@@ -470,6 +470,13 @@ void CUtil::GetCommonPath(CStdString& strParent, const CStdString& strPath)   } } +CStdString CUtil::GetParentPath(const CStdString& strPath)+{+  CStdString strReturn;+  GetParentPath(strPath, strReturn);+  return strReturn;+}+ bool CUtil::GetParentPath(const CStdString& strPath, CStdString& strParent) {   strParent = "";diff --git a/xbmc/Util.h b/xbmc/Util.hindex 2a34380..7355310 100644--- a/xbmc/Util.h+++ b/xbmc/Util.h@@ -75,6 +75,7 @@ public:   static void GetCommonPath(CStdString& strPath, const CStdString& strPath2);   static bool IsDOSPath(const CStdString &path);   static bool IsHD(const CStdString& strFileName);+  static CStdString GetParentPath(const CStdString& strPath);   static bool GetParentPath(const CStdString& strPath, CStdString& strParent);   static void GetQualifiedFilename(const CStdString &strBasePath, CStdString &strFilename);   static void RunShortcut(const char* szPath);diff --git a/xbmc/VideoInfoScanner.cpp b/xbmc/VideoInfoScanner.cppindex c51aa0a..19a8fda 100644--- a/xbmc/VideoInfoScanner.cpp+++ b/xbmc/VideoInfoScanner.cpp@@ -1252,6 +1252,8 @@ namespace VIDEO         nfoFile = CUtil::AddFileToFolder(strPath,"mymovies.xml");         if (CFile::Exists(nfoFile))           return nfoFile;+        else+          nfoFile.clear();       }     }     if (item->m_bIsFolder || (bGrabAny && nfoFile.IsEmpty()))