backport r34295
authorspiff_ <spiff_@svn>
Wed, 29 Sep 2010 11:57:26 +0000 (11:57 +0000)
committerspiff_ <spiff_@svn>
Wed, 29 Sep 2010 11:57:26 +0000 (11:57 +0000)
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/branches/Dharma@34296 568bbfeb-2a22-0410-94d2-cc84cf5bfa90

xbmc/FileSystem/RarManager.cpp
xbmc/Util.cpp
xbmc/Util.h

index 4753042..9294bf9 100644 (file)
@@ -144,7 +144,17 @@ bool CRarManager::CacheRarredFile(CStdString& strPathInCache, const CStdString&
   strPath.Replace('/', '\\');
 #endif
   //g_charsetConverter.unknownToUTF8(strPath);
-
+  CStdString strCachedPath;
+  CUtil::AddFileToFolder(strDir + "rarfolder%04d", CUtil::GetFileName(strPathInRar), strCachedPath);
+  strCachedPath = CUtil::GetNextPathname(strCachedPath, 9999);
+  if (strCachedPath.IsEmpty())
+  {
+    CLog::Log(LOGWARNING, "Could not cache file %s", (strRarPath + strPathInRar).c_str());
+    return false;
+  }
+  strCachedPath = CUtil::MakeLegalPath(strCachedPath);
+  CStdString strCachedDir;
+  CUtil::GetDirectory(strCachedPath, strCachedDir);
   int64_t iOffset = -1;
   if (iRes != 2)
   {
@@ -177,8 +187,10 @@ bool CRarManager::CacheRarredFile(CStdString& strPathInCache, const CStdString&
     if (iSize > 1024*1024 || iSize == -2) // 1MB
       bShowProgress=true;
 
-    CStdString strDir2(strDir);
+    CStdString strDir2(strCachedDir);
     CUtil::RemoveSlashAtEnd(strDir2);
+    if (!CDirectory::Exists(strDir2))
+      CDirectory::Create(strDir2);
     iRes = urarlib_get(const_cast<char*>(strRarPath.c_str()), const_cast<char*>(strDir2.c_str()),
                        const_cast<char*>(strPath.c_str()),NULL,&iOffset,bShowProgress);
   }
@@ -207,8 +219,7 @@ bool CRarManager::CacheRarredFile(CStdString& strPathInCache, const CStdString&
     pFile = &(j->second.second[j->second.second.size()-1]);
     pFile->m_iUsed = 1;
   }
-  CUtil::AddFileToFolder(strDir,CUtil::GetFileName(strPathInRar),pFile->m_strCachedPath); // GetFileName
-  pFile->m_strCachedPath = CUtil::MakeLegalPath(pFile->m_strCachedPath);
+  pFile->m_strCachedPath = strCachedPath;
   pFile->m_bAutoDel = (bOptions & EXFILE_AUTODELETE) != 0;
   pFile->m_iOffset = iOffset;
   strPathInCache = pFile->m_strCachedPath;
index 543a6ed..85b3b0c 100644 (file)
@@ -1969,6 +1969,21 @@ CStdString CUtil::GetNextFilename(const CStdString &fn_template, int max)
   return "";
 }
 
+CStdString CUtil::GetNextPathname(const CStdString &path_template, int max)
+{
+  if (!path_template.Find("%04d"))
+    return "";
+  
+  for (int i = 0; i <= max; i++)
+  {
+    CStdString name;
+    name.Format(path_template.c_str(), i);
+    if (!CFile::Exists(name))
+      return name;
+  }
+  return "";
+}
+
 void CUtil::Tokenize(const CStdString& path, vector<CStdString>& tokens, const string& delimiters)
 {
   // Tokenize ripped from http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-7.html
index 24d0a2d..d014607 100644 (file)
@@ -156,6 +156,7 @@ public:
   static void ThumbCacheClear();
   static void PlayDVD(const CStdString& strProtocol="dvd");
   static CStdString GetNextFilename(const CStdString &fn_template, int max);
+  static CStdString GetNextPathname(const CStdString &path_template, int max);
   static void TakeScreenshot();
   static void TakeScreenshot(const CStdString &filename, bool sync);
   static void Tokenize(const CStdString& path, std::vector<CStdString>& tokens, const std::string& delimiters);