aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/treedata/optional/common/nonfree.txt1
-rw-r--r--xbmc/Application.cpp8
-rw-r--r--xbmc/SystemGlobals.cpp5
-rw-r--r--xbmc/Util.cpp39
-rw-r--r--xbmc/filesystem/CMakeLists.txt6
-rw-r--r--xbmc/filesystem/DirectoryFactory.cpp11
-rw-r--r--xbmc/filesystem/FileDirectoryFactory.cpp56
-rw-r--r--xbmc/filesystem/FileFactory.cpp11
-rw-r--r--xbmc/filesystem/RarDirectory.cpp100
-rw-r--r--xbmc/filesystem/RarDirectory.h37
-rw-r--r--xbmc/filesystem/RarFile.cpp758
-rw-r--r--xbmc/filesystem/RarFile.h116
-rw-r--r--xbmc/filesystem/RarManager.cpp531
-rw-r--r--xbmc/filesystem/RarManager.h92
-rw-r--r--xbmc/filesystem/test/CMakeLists.txt1
-rw-r--r--xbmc/filesystem/test/TestRarFile.cpp651
-rw-r--r--xbmc/interfaces/builtins/ApplicationBuiltins.cpp7
-rw-r--r--xbmc/system.h8
-rw-r--r--xbmc/utils/URIUtils.cpp2
20 files changed, 8 insertions, 2437 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ff1be99ae..24ff1865e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,7 +41,6 @@ set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp")
option(VERBOSE "Enable verbose output?" OFF)
option(ENABLE_DVDCSS "Enable libdvdcss support?" ON)
option(ENABLE_UPNP "Enable UPnP support?" ON)
-option(ENABLE_NONFREE "Enable non-free components?" ON)
option(ENABLE_AIRTUNES "Enable AirTunes support?" ON)
option(ENABLE_OPTICAL "Enable optical support?" ON)
option(ENABLE_PYTHON "Enable python support?" ON)
@@ -194,10 +193,6 @@ if(ENABLE_UPNP)
list(APPEND DEP_DEFINES "-DUSE_UPNP=1")
endif()
-if(ENABLE_NONFREE)
- list(APPEND DEP_DEFINES "-DHAVE_XBMC_NONFREE=1")
-endif()
-
if(ENABLE_OPTICAL)
list(APPEND DEP_DEFINES -DHAS_DVD_DRIVE)
endif()
diff --git a/cmake/treedata/optional/common/nonfree.txt b/cmake/treedata/optional/common/nonfree.txt
deleted file mode 100644
index 470ed59752..0000000000
--- a/cmake/treedata/optional/common/nonfree.txt
+++ /dev/null
@@ -1 +0,0 @@
-lib/UnrarXLib unrarxlib # NONFREE
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index 9edc4d89ce..e8ca0593be 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -79,9 +79,6 @@
#include "GUILargeTextureManager.h"
#include "TextureCache.h"
#include "playlists/SmartPlayList.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "filesystem/RarManager.h"
-#endif
#include "playlists/PlayList.h"
#include "profiles/ProfilesManager.h"
#include "windowing/WindowingFactory.h"
@@ -2901,11 +2898,6 @@ void CApplication::Stop(int exitCode)
}
#endif
- CLog::Log(LOGNOTICE, "clean cached files!");
-#ifdef HAS_FILESYSTEM_RAR
- g_RarManager.ClearCache(true);
-#endif
-
#ifdef HAS_FILESYSTEM_SFTP
CSFTPSessionManager::DisconnectAllSessions();
#endif
diff --git a/xbmc/SystemGlobals.cpp b/xbmc/SystemGlobals.cpp
index 9050b41680..219d7d0778 100644
--- a/xbmc/SystemGlobals.cpp
+++ b/xbmc/SystemGlobals.cpp
@@ -33,13 +33,10 @@
#include "interfaces/python/XBPython.h"
#endif
-// Guarantee that CSpecialProtocol is initialized before and uninitialized after RarManager
+// Guarantee that CSpecialProtocol is initialized before and uninitialized after ZipManager
#include "filesystem/SpecialProtocol.h"
std::map<std::string, std::string> CSpecialProtocol::m_pathMap;
-#if defined(HAS_FILESYSTEM_RAR)
-#include "filesystem/RarManager.h"
-#endif
#include "filesystem/ZipManager.h"
#ifdef TARGET_RASPBERRY_PI
diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp
index badf9a55e2..0d04c8a0fe 100644
--- a/xbmc/Util.cpp
+++ b/xbmc/Util.cpp
@@ -55,9 +55,6 @@
#include "filesystem/MultiPathDirectory.h"
#include "filesystem/SpecialProtocol.h"
#include "filesystem/RSSDirectory.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "filesystem/RarManager.h"
-#endif
#ifdef HAS_UPNP
#include "filesystem/UPnPDirectory.h"
#endif
@@ -1933,35 +1930,18 @@ int CUtil::ScanArchiveForAssociatedItems(const std::string& strArchivePath,
if (!CDirectory::GetDirectory(zipURL, ItemList, "", DIR_FLAG_NO_FILE_DIRS))
return false;
}
- else
+ else if (URIUtils::HasExtension(strArchivePath, ".rar"))
{
-#ifdef HAS_FILESYSTEM_RAR
- // get _ALL_files in the rar, even those located in subdirectories because we set the bMask to false.
- // so now we dont have to find any subdirs anymore, all files in the rar is checked.
- if (!g_RarManager.GetFilesInRar(ItemList, strArchivePath, false, ""))
+ CURL pathToUrl(strArchivePath);
+ CURL rarURL = URIUtils::CreateArchivePath("rar", pathToUrl, "");
+ if (!CDirectory::GetDirectory(rarURL, ItemList, "", DIR_FLAG_NO_FILE_DIRS))
return false;
-#else
- return false;
-#endif
}
for (int it = 0; it < ItemList.Size(); ++it)
{
std::string strPathInRar = ItemList[it]->GetPath();
std::string strExt = URIUtils::GetExtension(strPathInRar);
- // checking for embedded archives
- if (URIUtils::IsArchive(strPathInRar))
- {
- std::string archInArch(strPathInRar);
- if (strExt == ".rar")
- {
- CURL pathToUrl(strArchivePath);
- archInArch = URIUtils::CreateArchivePath("rar", pathToUrl, strPathInRar).Get();
- }
-
- ScanArchiveForAssociatedItems(archInArch, videoNameNoExt, item_exts, associatedFiles);
- continue;
- }
// check that the found filename matches the movie filename
int fnl = videoNameNoExt.size();
if (fnl && !StringUtils::StartsWithNoCase(URIUtils::GetFileName(strPathInRar), videoNameNoExt))
@@ -1971,15 +1951,8 @@ int CUtil::ScanArchiveForAssociatedItems(const std::string& strArchivePath,
{
if (StringUtils::EqualsNoCase(strExt, ext))
{
- CURL pathToURL(strArchivePath);
- std::string strSourceUrl;
- if (URIUtils::HasExtension(strArchivePath, ".rar"))
- strSourceUrl = URIUtils::CreateArchivePath("rar", pathToURL, strPathInRar).Get();
- else
- strSourceUrl = strPathInRar;
-
- CLog::Log(LOGINFO, "%s: found associated file %s\n", __FUNCTION__, strSourceUrl.c_str());
- associatedFiles.push_back(strSourceUrl);
+ CLog::Log(LOGINFO, "%s: found associated file %s\n", __FUNCTION__, strPathInRar.c_str());
+ associatedFiles.push_back(strPathInRar);
nItemsAdded++;
break;
}
diff --git a/xbmc/filesystem/CMakeLists.txt b/xbmc/filesystem/CMakeLists.txt
index b4947a6fbd..fbade5f9b4 100644
--- a/xbmc/filesystem/CMakeLists.txt
+++ b/xbmc/filesystem/CMakeLists.txt
@@ -45,9 +45,6 @@ set(SOURCES AddonsDirectory.cpp
PlaylistFileDirectory.cpp
PluginDirectory.cpp
PVRDirectory.cpp
- RarDirectory.cpp
- RarFile.cpp
- RarManager.cpp
ResourceDirectory.cpp
ResourceFile.cpp
RSSDirectory.cpp
@@ -125,9 +122,6 @@ set(HEADERS AddonsDirectory.h
PlaylistFileDirectory.h
PluginDirectory.h
RSSDirectory.h
- RarDirectory.h
- RarFile.h
- RarManager.h
ResourceDirectory.h
ResourceFile.h
SFTPDirectory.h
diff --git a/xbmc/filesystem/DirectoryFactory.cpp b/xbmc/filesystem/DirectoryFactory.cpp
index c63fa24575..4c306638e3 100644
--- a/xbmc/filesystem/DirectoryFactory.cpp
+++ b/xbmc/filesystem/DirectoryFactory.cpp
@@ -73,9 +73,6 @@
#endif
#include "XbtDirectory.h"
#include "ZipDirectory.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "RarDirectory.h"
-#endif
#include "FileItem.h"
#include "URL.h"
#include "RSSDirectory.h"
@@ -141,14 +138,6 @@ IDirectory* CDirectoryFactory::Create(const CURL& url)
if (url.IsProtocol("apk")) return new CAPKDirectory();
#endif
if (url.IsProtocol("zip")) return new CZipDirectory();
- if (url.IsProtocol("rar"))
- {
-#ifdef HAS_FILESYSTEM_RAR
- return new CRarDirectory();
-#else
- CLog::Log(LOGWARNING, "%s - Compiled without non-free, rar support is disabled", __FUNCTION__);
-#endif
- }
if (url.IsProtocol("xbt")) return new CXbtDirectory();
if (url.IsProtocol("multipath")) return new CMultiPathDirectory();
if (url.IsProtocol("stack")) return new CStackDirectory();
diff --git a/xbmc/filesystem/FileDirectoryFactory.cpp b/xbmc/filesystem/FileDirectoryFactory.cpp
index edd50b7d25..58c978ef53 100644
--- a/xbmc/filesystem/FileDirectoryFactory.cpp
+++ b/xbmc/filesystem/FileDirectoryFactory.cpp
@@ -26,9 +26,6 @@
#include "UDFDirectory.h"
#include "RSSDirectory.h"
#endif
-#ifdef HAS_FILESYSTEM_RAR
-#include "RarDirectory.h"
-#endif
#if defined(TARGET_ANDROID)
#include "APKDirectory.h"
#endif
@@ -169,59 +166,6 @@ IFileDirectory* CFileDirectoryFactory::Create(const CURL& url, CFileItem* pItem,
}
return NULL;
}
- if (url.IsFileType("rar") || url.IsFileType("001"))
- {
- std::vector<std::string> tokens;
- const std::string strPath = url.Get();
- StringUtils::Tokenize(strPath,tokens,".");
- if (tokens.size() > 2)
- {
- if (url.IsFileType("001"))
- {
- if (StringUtils::EqualsNoCase(tokens[tokens.size()-2], "ts")) // .ts.001 - treat as a movie file to scratch some users itch
- return NULL;
- }
- std::string token = tokens[tokens.size()-2];
- if (StringUtils::StartsWith(token, "part")) // only list '.part01.rar'
- {
- // need this crap to avoid making mistakes - yeyh for the new rar naming scheme :/
- struct __stat64 stat;
- int digits = token.size()-4;
- std::string strFormat = StringUtils::Format("part%%0%ii", digits);
- std::string strNumber = StringUtils::Format(strFormat.c_str(), 1);
- std::string strPath2 = strPath;
- StringUtils::Replace(strPath2,token,strNumber);
- if (atoi(token.substr(4).c_str()) > 1 && CFile::Stat(strPath2,&stat) == 0)
- {
- pItem->m_bIsFolder = true;
- return NULL;
- }
- }
- }
-
- CURL rarURL = URIUtils::CreateArchivePath("rar", url);
-
- CFileItemList items;
- CDirectory::GetDirectory(rarURL, items, strMask);
- if (items.Size() == 0) // no files - hide this
- pItem->m_bIsFolder = true;
- else if (items.Size() == 1 && items[0]->m_idepth == 0x30 && !items[0]->m_bIsFolder)
- {
- // one STORED file - collapse it down
- *pItem = *items[0];
- }
- else
- {
-#ifdef HAS_FILESYSTEM_RAR
- // compressed or more than one file -> create a rar dir
- pItem->SetURL(rarURL);
- return new CRarDirectory;
-#else
- return NULL;
-#endif
- }
- return NULL;
- }
if (url.IsFileType("xbt"))
{
CURL xbtUrl = URIUtils::CreateArchivePath("xbt", url);
diff --git a/xbmc/filesystem/FileFactory.cpp b/xbmc/filesystem/FileFactory.cpp
index 4182ae1c28..fcf59b2e7c 100644
--- a/xbmc/filesystem/FileFactory.cpp
+++ b/xbmc/filesystem/FileFactory.cpp
@@ -47,9 +47,6 @@
#endif
#include "XbtFile.h"
#include "ZipFile.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "RarFile.h"
-#endif
#ifdef HAS_FILESYSTEM_SFTP
#include "SFTPFile.h"
#endif
@@ -124,14 +121,6 @@ IFile* CFileFactory::CreateLoader(const CURL& url)
if (url.IsProtocol("apk")) return new CAPKFile();
#endif
if (url.IsProtocol("zip")) return new CZipFile();
- else if (url.IsProtocol("rar"))
- {
-#ifdef HAS_FILESYSTEM_RAR
- return new CRarFile();
-#else
- CLog::Log(LOGWARNING, "%s - Compiled without non-free, rar support is disabled", __FUNCTION__);
-#endif
- }
else if (url.IsProtocol("xbt")) return new CXbtFile();
else if (url.IsProtocol("musicdb")) return new CMusicDatabaseFile();
else if (url.IsProtocol("videodb")) return new CVideoDatabaseFile();
diff --git a/xbmc/filesystem/RarDirectory.cpp b/xbmc/filesystem/RarDirectory.cpp
deleted file mode 100644
index fe1e613e10..0000000000
--- a/xbmc/filesystem/RarDirectory.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "RarDirectory.h"
-#include "RarManager.h"
-#include "utils/log.h"
-#include "utils/URIUtils.h"
-#include "URL.h"
-#include "FileItem.h"
-
-namespace XFILE
-{
- CRarDirectory::CRarDirectory()
- {
- }
-
- CRarDirectory::~CRarDirectory()
- {
- }
-
- bool CRarDirectory::GetDirectory(const CURL& urlOrig, CFileItemList& items)
- {
- CURL url(urlOrig);
-
- /* if this isn't a proper archive path, assume it's the path to a archive file */
- if (!urlOrig.IsProtocol("rar"))
- url = URIUtils::CreateArchivePath("rar", urlOrig);
-
- std::string strArchive = url.GetHostName();
- std::string strOptions = url.GetOptions();
- std::string strPathInArchive = url.GetFileName();
- url.SetOptions("");
-
- std::string strSlashPath = url.Get();
-
- // the RAR code depends on things having a "\" at the end of the path
- URIUtils::AddSlashAtEnd(strSlashPath);
-
- if (g_RarManager.GetFilesInRar(items,strArchive,true,strPathInArchive))
- {
- // fill in paths
- for( int iEntry=0;iEntry<items.Size();++iEntry)
- {
- if (items[iEntry]->IsParentFolder())
- continue;
- items[iEntry]->SetPath(URIUtils::AddFileToFolder(strSlashPath, items[iEntry]->GetPath() + strOptions));
- items[iEntry]->m_iDriveType = 0;
- //CLog::Log(LOGDEBUG, "RarXFILE::GetDirectory() retrieved file: %s", items[iEntry]->m_strPath.c_str());
- }
- return( true);
- }
- else
- {
- CLog::Log(LOGWARNING,"%s: rar lib returned no files in archive %s, likely corrupt",__FUNCTION__,strArchive.c_str());
- return( false );
- }
- }
-
- bool CRarDirectory::Exists(const CURL& url)
- {
- CFileItemList items;
- if (GetDirectory(url,items))
- return true;
-
- return false;
- }
-
- bool CRarDirectory::ContainsFiles(const CURL& url)
- {
- CFileItemList items;
- const std::string pathToUrl(url.Get());
- if (g_RarManager.GetFilesInRar(items, pathToUrl))
- {
- if (items.Size() > 1)
- return true;
-
- return false;
- }
-
- return false;
- }
-}
-
diff --git a/xbmc/filesystem/RarDirectory.h b/xbmc/filesystem/RarDirectory.h
deleted file mode 100644
index a77f2e13e5..0000000000
--- a/xbmc/filesystem/RarDirectory.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "IFileDirectory.h"
-
-namespace XFILE
-{
- class CRarDirectory : public IFileDirectory
- {
- public:
- CRarDirectory();
- ~CRarDirectory();
- virtual bool GetDirectory(const CURL& url, CFileItemList& items);
- virtual bool ContainsFiles(const CURL& url);
- virtual bool Exists(const CURL& url);
- virtual DIR_CACHE_TYPE GetCacheType(const CURL& url) const { return DIR_CACHE_ALWAYS; };
- };
-}
diff --git a/xbmc/filesystem/RarFile.cpp b/xbmc/filesystem/RarFile.cpp
deleted file mode 100644
index 6016bc203a..0000000000
--- a/xbmc/filesystem/RarFile.cpp
+++ /dev/null
@@ -1,758 +0,0 @@
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "system.h"
-#include "RarFile.h"
-#include <algorithm>
-#include <sys/stat.h>
-#include "Util.h"
-#include "utils/CharsetConverter.h"
-#include "utils/URIUtils.h"
-#include "URL.h"
-#include "Directory.h"
-#include "RarManager.h"
-#include "settings/AdvancedSettings.h"
-#include "FileItem.h"
-#include "utils/log.h"
-#include "UnrarXLib/rar.hpp"
-#include "utils/StringUtils.h"
-
-#ifndef TARGET_POSIX
-#include <process.h>
-#endif
-
-#ifdef TARGET_POSIX
-#include "linux/XTimeUtils.h"
-#endif
-
-using namespace XFILE;
-
-#define SEEKTIMOUT 30000
-
-#ifdef HAS_FILESYSTEM_RAR
-CRarFileExtractThread::CRarFileExtractThread()
- : CThread("RarFileExtract")
- , hRunning(true)
- , hQuit(true)
- , m_iSize(0)
-{
- m_pArc = NULL;
- m_pCmd = NULL;
- m_pExtract = NULL;
- StopThread();
- Create();
-}
-
-CRarFileExtractThread::~CRarFileExtractThread()
-{
- hQuit.Set();
- AbortableWait(hRestart);
- StopThread();
-}
-
-void CRarFileExtractThread::Start(Archive* pArc, CommandData* pCmd, CmdExtract* pExtract, int iSize)
-{
- m_pArc = pArc;
- m_pCmd = pCmd;
- m_pExtract = pExtract;
- m_iSize = iSize;
-
- m_pExtract->GetDataIO().hBufferFilled = new CEvent;
- m_pExtract->GetDataIO().hBufferEmpty = new CEvent;
- m_pExtract->GetDataIO().hSeek = new CEvent(true);
- m_pExtract->GetDataIO().hSeekDone = new CEvent;
- m_pExtract->GetDataIO().hQuit = new CEvent(true);
-
- hRunning.Set();
- hRestart.Set();
-}
-
-void CRarFileExtractThread::OnStartup()
-{
-}
-
-void CRarFileExtractThread::OnExit()
-{
-}
-
-void CRarFileExtractThread::Process()
-{
- while (AbortableWait(hQuit,1) != WAIT_SIGNALED)
- {
- if (AbortableWait(hRestart,1) == WAIT_SIGNALED)
- {
- bool Repeat = false;
- try
- {
- m_pExtract->ExtractCurrentFile(m_pCmd,*m_pArc,m_iSize,Repeat);
- }
- catch (int rarErrCode)
- {
- CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw a UnrarXLib error code of %d",rarErrCode);
- }
- catch (...)
- {
- CLog::Log(LOGERROR,"filerar CFileRarExtractThread::Process failed. CmdExtract::ExtractCurrentFile threw an Unknown exception");
- }
-
- hRunning.Reset();
- }
- }
- hRestart.Set();
-}
-#endif
-
-CRarFile::CRarFile()
-{
- m_strCacheDir.clear();
- m_strRarPath.clear();
- m_strPassword.clear();
- m_strPathInRar.clear();
- m_bFileOptions = 0;
-#ifdef HAS_FILESYSTEM_RAR
- m_pArc = NULL;
- m_pCmd = NULL;
- m_pExtract = NULL;
- m_pExtractThread = NULL;
-#endif
- m_szBuffer = NULL;
- m_szStartOfBuffer = NULL;
- m_iDataInBuffer = 0;
- m_bUseFile = false;
- m_bOpen = false;
- m_bSeekable = true;
- m_iFilePosition = 0;
- m_iFileSize = 0;
- m_iBufferStart = 0;
-}
-
-CRarFile::~CRarFile()
-{
-#ifdef HAS_FILESYSTEM_RAR
- if (!m_bOpen)
- return;
-
- if (m_bUseFile)
- {
- m_File.Close();
- g_RarManager.ClearCachedFile(m_strRarPath,m_strPathInRar);
- }
- else
- {
- CleanUp();
- if (m_pExtractThread)
- {
- delete m_pExtractThread;
- m_pExtractThread = NULL;
- }
- }
-#endif
-}
-
-bool CRarFile::Open(const CURL& url)
-{
- InitFromUrl(url);
- CFileItemList items;
- g_RarManager.GetFilesInRar(items,m_strRarPath,false);
- int i;
- for (i=0;i<items.Size();++i)
- {
- if (items[i]->GetLabel() == m_strPathInRar)
- break;
- }
-
- if (i<items.Size())
- {
- if (items[i]->m_idepth == 0x30) // stored
- {
- if (!OpenInArchive())
- return false;
-
- m_iFileSize = items[i]->m_dwSize;
- m_bOpen = true;
-
- // perform 'noidx' check
- CFileInfo* pFile = g_RarManager.GetFileInRar(m_strRarPath,m_strPathInRar);
- if (pFile)
- {
- if (pFile->m_iIsSeekable == -1)
- {
- if (Seek(-1,SEEK_END) == -1)
- {
- m_bSeekable = false;
- pFile->m_iIsSeekable = 0;
- }
- }
- else
- m_bSeekable = (pFile->m_iIsSeekable == 1);
- }
- return true;
- }
- else
- {
- CFileInfo* info = g_RarManager.GetFileInRar(m_strRarPath,m_strPathInRar);
- if ((!info || !CFile::Exists(info->m_strCachedPath)) && m_bFileOptions & EXFILE_NOCACHE)
- return false;
- m_bUseFile = true;
- std::string strPathInCache;
-
- if (!g_RarManager.CacheRarredFile(strPathInCache, m_strRarPath, m_strPathInRar,
- EXFILE_AUTODELETE | m_bFileOptions, m_strCacheDir,
- items[i]->m_dwSize))
- {
- CLog::Log(LOGERROR,"filerar::open failed to cache file %s",m_strPathInRar.c_str());
- return false;
- }
-
- if (!m_File.Open( strPathInCache ))
- {
- CLog::Log(LOGERROR,"filerar::open failed to open file in cache: %s",strPathInCache.c_str());
- return false;
- }
-
- m_bOpen = true;
- return true;
- }
- }
- return false;
-}
-
-bool CRarFile::Exists(const CURL& url)
-{
- InitFromUrl(url);
-
- // First step:
- // Make sure that the archive exists in the filesystem.
- if (!CFile::Exists(m_strRarPath, false))
- return false;
-
- // Second step:
- // Make sure that the requested file exists in the archive.
- bool bResult;
-
- if (!g_RarManager.IsFileInRar(bResult, m_strRarPath, m_strPathInRar))
- return false;
-
- return bResult;
-}
-
-int CRarFile::Stat(const CURL& url, struct __stat64* buffer)
-{
- memset(buffer, 0, sizeof(struct __stat64));
- if (Open(url))
- {
- buffer->st_size = GetLength();
- buffer->st_mode = _S_IFREG;
- Close();
- errno = 0;
- return 0;
- }
-
- if (CDirectory::Exists(url.Get()))
- {
- buffer->st_mode = _S_IFDIR;
- return 0;
- }
-
- errno = ENOENT;
- return -1;
-}
-
-bool CRarFile::OpenForWrite(const CURL&, bool)
-{
- return false;
-}
-
-ssize_t CRarFile::Read(void *lpBuf, size_t uiBufSize)
-{
-#ifdef HAS_FILESYSTEM_RAR
- if (!m_bOpen)
- return -1;
-
- if (uiBufSize > SSIZE_MAX)
- uiBufSize = SSIZE_MAX;
-
- if (m_bUseFile)
- return m_File.Read(lpBuf,uiBufSize);
-
- if (m_iFilePosition >= GetLength()) // we are done
- return 0;
-
- if( !m_pExtract->GetDataIO().hBufferEmpty->WaitMSec(5000) )
- {
- CLog::Log(LOGERROR, "%s - Timeout waiting for buffer to empty", __FUNCTION__);
- return -1;
- }
-
-
- uint8_t* pBuf = (uint8_t*)lpBuf;
- int64_t uicBufSize = uiBufSize;
- if (m_iDataInBuffer > 0)
- {
- int64_t iCopy = std::min(static_cast<int64_t>(uiBufSize), m_iDataInBuffer);
- memcpy(lpBuf,m_szStartOfBuffer,size_t(iCopy));
- m_szStartOfBuffer += iCopy;
- m_iDataInBuffer -= int(iCopy);
- pBuf += iCopy;
- uicBufSize -= iCopy;
- m_iFilePosition += iCopy;
- }
-
- while ((uicBufSize > 0) && m_iFilePosition < GetLength() )
- {
- if (m_iDataInBuffer <= 0)
- {
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,MAXWINMEMSIZE);
- m_szStartOfBuffer = m_szBuffer;
- m_iBufferStart = m_iFilePosition;
- }
-
- m_pExtract->GetDataIO().hBufferFilled->Set();
- m_pExtract->GetDataIO().hBufferEmpty->Wait();
-
- if (m_pExtract->GetDataIO().NextVolumeMissing)
- break;
-
- m_iDataInBuffer = MAXWINMEMSIZE-m_pExtract->GetDataIO().UnpackToMemorySize;
-
- if (m_iDataInBuffer < 0 ||
- m_iDataInBuffer > MAXWINMEMSIZE - (m_szStartOfBuffer - m_szBuffer))
- {
- // invalid data returned by UnrarXLib, prevent a crash
- CLog::Log(LOGERROR, "CRarFile::Read - Data buffer in inconsistent state");
- m_iDataInBuffer = 0;
- }
-
- if (m_iDataInBuffer == 0)
- break;
-
- if (m_iDataInBuffer > uicBufSize)
- {
- memcpy(pBuf,m_szStartOfBuffer,int(uicBufSize));
- m_szStartOfBuffer += uicBufSize;
- pBuf += int(uicBufSize);
- m_iFilePosition += uicBufSize;
- m_iDataInBuffer -= int(uicBufSize);
- uicBufSize = 0;
- }
- else
- {
- memcpy(pBuf,m_szStartOfBuffer,size_t(m_iDataInBuffer));
- m_iFilePosition += m_iDataInBuffer;
- m_szStartOfBuffer += m_iDataInBuffer;
- uicBufSize -= m_iDataInBuffer;
- pBuf += m_iDataInBuffer;
- m_iDataInBuffer = 0;
- }
- }
-
- m_pExtract->GetDataIO().hBufferEmpty->Set();
-
- return (ssize_t)(uiBufSize-uicBufSize);
-#else
- return 0;
-#endif
-}
-
-void CRarFile::Close()
-{
-#ifdef HAS_FILESYSTEM_RAR
- if (!m_bOpen)
- return;
-
- if (m_bUseFile)
- {
- m_File.Close();
- g_RarManager.ClearCachedFile(m_strRarPath,m_strPathInRar);
- m_bOpen = false;
- }
- else
- {
- CleanUp();
- if (m_pExtractThread)
- {
- delete m_pExtractThread;
- m_pExtractThread = NULL;
- }
- m_bOpen = false;
- }
-#endif
-}
-
-int64_t CRarFile::Seek(int64_t iFilePosition, int iWhence)
-{
-#ifdef HAS_FILESYSTEM_RAR
- if (!m_bOpen)
- return -1;
-
- if (!m_bSeekable)
- return -1;
-
- if (m_bUseFile)
- return m_File.Seek(iFilePosition,iWhence);
-
- if( !m_pExtract->GetDataIO().hBufferEmpty->WaitMSec(SEEKTIMOUT) )
- {
- CLog::Log(LOGERROR, "%s - Timeout waiting for buffer to empty", __FUNCTION__);
- return -1;
- }
-
- m_pExtract->GetDataIO().hBufferEmpty->Set();
-
- switch (iWhence)
- {
- case SEEK_CUR:
- if (iFilePosition == 0)
- return m_iFilePosition; // happens sometimes
-
- iFilePosition += m_iFilePosition;
- break;
- case SEEK_END:
- if (iFilePosition == 0) // do not seek to end
- {
- m_iFilePosition = this->GetLength();
- m_iDataInBuffer = 0;
- m_iBufferStart = this->GetLength();
-
- return this->GetLength();
- }
-
- iFilePosition += GetLength();
- case SEEK_SET:
- break;
- default:
- return -1;
- }
-
- if (iFilePosition > this->GetLength())
- return -1;
-
- if (iFilePosition == m_iFilePosition) // happens a lot
- return m_iFilePosition;
-
- if ((iFilePosition >= m_iBufferStart) && (iFilePosition < m_iBufferStart+MAXWINMEMSIZE)
- && (m_iDataInBuffer > 0)) // we are within current buffer
- {
- m_iDataInBuffer = MAXWINMEMSIZE-(iFilePosition-m_iBufferStart);
- m_szStartOfBuffer = m_szBuffer+MAXWINMEMSIZE-m_iDataInBuffer;
- m_iFilePosition = iFilePosition;
-
- return m_iFilePosition;
- }
-
- if (iFilePosition < m_iBufferStart )
- {
- CleanUp();
- if (!OpenInArchive())
- return -1;
-
- if( !m_pExtract->GetDataIO().hBufferEmpty->WaitMSec(SEEKTIMOUT) )
- {
- CLog::Log(LOGERROR, "%s - Timeout waiting for buffer to empty", __FUNCTION__);
- return -1;
- }
- m_pExtract->GetDataIO().hBufferEmpty->Set();
- m_pExtract->GetDataIO().m_iSeekTo = iFilePosition;
- }
- else
- m_pExtract->GetDataIO().m_iSeekTo = iFilePosition;
-
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,MAXWINMEMSIZE);
- m_pExtract->GetDataIO().hSeek->Set();
- m_pExtract->GetDataIO().hBufferFilled->Set();
- if( !m_pExtract->GetDataIO().hSeekDone->WaitMSec(SEEKTIMOUT))
- {
- CLog::Log(LOGERROR, "%s - Timeout waiting for seek to finish", __FUNCTION__);
- return -1;
- }
-
- if (m_pExtract->GetDataIO().NextVolumeMissing)
- {
- m_iFilePosition = m_iFileSize;
- return -1;
- }
-
- if( !m_pExtract->GetDataIO().hBufferEmpty->WaitMSec(SEEKTIMOUT) )
- {
- CLog::Log(LOGERROR, "%s - Timeout waiting for buffer to empty", __FUNCTION__);
- return -1;
- }
- m_iDataInBuffer = m_pExtract->GetDataIO().m_iSeekTo; // keep data
- m_iBufferStart = m_pExtract->GetDataIO().m_iStartOfBuffer;
-
- if (m_iDataInBuffer < 0 || m_iDataInBuffer > MAXWINMEMSIZE)
- {
- // invalid data returned by UnrarXLib, prevent a crash
- CLog::Log(LOGERROR, "CRarFile::Seek - Data buffer in inconsistent state");
- m_iDataInBuffer = 0;
- return -1;
- }
-
- m_szStartOfBuffer = m_szBuffer+MAXWINMEMSIZE-m_iDataInBuffer;
- m_iFilePosition = iFilePosition;
-
- return m_iFilePosition;
-#else
- return -1;
-#endif
-}
-
-int64_t CRarFile::GetLength()
-{
- if (!m_bOpen)
- return 0;
-
- if (m_bUseFile)
- return m_File.GetLength();
-
- return m_iFileSize;
-}
-
-int64_t CRarFile::GetPosition()
-{
- if (!m_bOpen)
- return -1;
-
- if (m_bUseFile)
- return m_File.GetPosition();
-
- return m_iFilePosition;
-}
-
-ssize_t CRarFile::Write(const void* lpBuf, size_t uiBufSize)
-{
- return -1;
-}
-
-void CRarFile::Flush()
-{
- if (m_bUseFile)
- m_File.Flush();
-}
-
-void CRarFile::InitFromUrl(const CURL& url)
-{
- m_strCacheDir = g_advancedSettings.m_cachePath;//url.GetDomain();
- URIUtils::AddSlashAtEnd(m_strCacheDir);
- m_strRarPath = url.GetHostName();
- m_strPassword = url.GetUserName();
- m_strPathInRar = url.GetFileName();
-
- std::vector<std::string> options;
- if (!url.GetOptions().empty())
- StringUtils::Tokenize(url.GetOptions().substr(1), options, "&");
-
- m_bFileOptions = 0;
-
- for(std::vector<std::string>::iterator it = options.begin();it != options.end(); ++it)
- {
- size_t iEqual = (*it).find('=');
- if(iEqual != std::string::npos)
- {
- std::string strOption = StringUtils::Left((*it), iEqual);
- std::string strValue = StringUtils::Mid((*it), iEqual+1);
-
- if( strOption == "flags" )
- m_bFileOptions = atoi(strValue.c_str());
- else if( strOption == "cache" )
- m_strCacheDir = strValue;
- }
- }
-
-}
-
-void CRarFile::CleanUp()
-{
-#ifdef HAS_FILESYSTEM_RAR
- try
- {
- if (m_pExtractThread)
- {
- if (m_pExtractThread->hRunning.WaitMSec(1))
- {
- m_pExtract->GetDataIO().hQuit->Set();
- while (m_pExtractThread->hRunning.WaitMSec(1))
- Sleep(1);
- }
- delete m_pExtract->GetDataIO().hBufferFilled;
- delete m_pExtract->GetDataIO().hBufferEmpty;
- delete m_pExtract->GetDataIO().hSeek;
- delete m_pExtract->GetDataIO().hSeekDone;
- delete m_pExtract->GetDataIO().hQuit;
- }
- if (m_pExtract)
- {
- delete m_pExtract;
- m_pExtract = NULL;
- }
- if (m_pArc)
- {
- delete m_pArc;
- m_pArc = NULL;
- }
- if (m_pCmd)
- {
- delete m_pCmd;
- m_pCmd = NULL;
- }
- if (m_szBuffer)
- {
- delete[] m_szBuffer;
- m_szBuffer = NULL;
- m_szStartOfBuffer = NULL;
- }
- }
- catch (int rarErrCode)
- {
- CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an UnrarXLib error code of %d",rarErrCode);
- }
- catch (...)
- {
- CLog::Log(LOGERROR,"filerar failed in UnrarXLib while deleting CFileRar with an Unknown exception");
- }
-#endif
-}
-
-bool CRarFile::OpenInArchive()
-{
-#ifdef HAS_FILESYSTEM_RAR
- try
- {
- int iHeaderSize;
-
- InitCRC();
-
- m_pCmd = new CommandData;
- if (!m_pCmd)
- {
- CleanUp();
- return false;
- }
-
- // Set the arguments for the extract command
- strcpy(m_pCmd->Command, "X");
-
- m_pCmd->AddArcName(const_cast<char*>(m_strRarPath.c_str()),NULL);
-
- strncpy(m_pCmd->ExtrPath, m_strCacheDir.c_str(), sizeof (m_pCmd->ExtrPath) - 2);
- m_pCmd->ExtrPath[sizeof (m_pCmd->ExtrPath) - 2] = 0;
- AddEndSlash(m_pCmd->ExtrPath);
-
- // Set password for encrypted archives
- if (m_strPassword.length() > MAXPASSWORD - 1)
- CLog::Log(LOGWARNING,"OpenInArchive: Supplied password is too long %d", (int) m_strPassword.length());
- strncpy(m_pCmd->Password, m_strPassword.c_str(), sizeof (m_pCmd->Password) - 1);
- m_pCmd->Password[sizeof (m_pCmd->Password) - 1] = 0;
-
- m_pCmd->ParseDone();
-
- // Open the archive
- m_pArc = new Archive(m_pCmd);
- if (!m_pArc)
- {
- CleanUp();
- return false;
- }
- if (!m_pArc->WOpen(m_strRarPath.c_str(),NULL))
- {
- CleanUp();
- return false;
- }
- if (!(m_pArc->IsOpened() && m_pArc->IsArchive(true)))
- {
- CleanUp();
- return false;
- }
-
- m_pExtract = new CmdExtract;
- if (!m_pExtract)
- {
- CleanUp();
- return false;
- }
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
- m_pExtract->GetDataIO().SetCurrentCommand(*(m_pCmd->Command));
- struct FindData FD;
- if (FindFile::FastFind(m_strRarPath.c_str(),NULL,&FD))
- m_pExtract->GetDataIO().TotalArcSize+=FD.Size;
- m_pExtract->ExtractArchiveInit(m_pCmd,*m_pArc);
-
- while (true)
- {
- if ((iHeaderSize = m_pArc->ReadHeader()) <= 0)
- {
- CleanUp();
- return false;
- }
-
- if (m_pArc->GetHeaderType() == FILE_HEAD)
- {
- std::string strFileName;
-
- if (wcslen(m_pArc->NewLhd.FileNameW) > 0)
- {
- g_charsetConverter.wToUTF8(m_pArc->NewLhd.FileNameW, strFileName);
- }
- else
- {
- g_charsetConverter.unknownToUTF8(m_pArc->NewLhd.FileName, strFileName);
- }
-
- /* replace back slashes into forward slashes */
- /* this could get us into troubles, file could two different files, one with / and one with \ */
- StringUtils::Replace(strFileName, '\\', '/');
-
- if (strFileName == m_strPathInRar)
- {
- break;
- }
- }
-
- m_pArc->SeekToNext();
- }
-
- m_szBuffer = new uint8_t[MAXWINMEMSIZE];
- m_szStartOfBuffer = m_szBuffer;
- m_pExtract->GetDataIO().SetUnpackToMemory(m_szBuffer,0);
- m_iDataInBuffer = -1;
- m_iFilePosition = 0;
- m_iBufferStart = 0;
-
- delete m_pExtractThread;
- m_pExtractThread = new CRarFileExtractThread();
- m_pExtractThread->Start(m_pArc,m_pCmd,m_pExtract,iHeaderSize);
-
- return true;
- }
- catch (int rarErrCode)
- {
- CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an UnrarXLib error code of %d",rarErrCode);
- return false;
- }
- catch (...)
- {
- CLog::Log(LOGERROR,"filerar failed in UnrarXLib while CFileRar::OpenInArchive with an Unknown exception");
- return false;
- }
-#else
- return false;
-#endif
-}
-
diff --git a/xbmc/filesystem/RarFile.h b/xbmc/filesystem/RarFile.h
deleted file mode 100644
index 58b6576500..0000000000
--- a/xbmc/filesystem/RarFile.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-// FileRar.h: interface for the CRarFile class.
-
-#pragma once
-#ifndef FILERAR_H_
-#define FILERAR_H_
-
-#include "File.h"
-#include "IFile.h"
-#include "threads/Thread.h"
-#include "threads/Event.h"
-
-class CmdExtract;
-class CommandData;
-class Archive;
-
-namespace XFILE
-{
-#ifdef HAS_FILESYSTEM_RAR
- class CRarFileExtractThread : public CThread
- {
- public:
- CRarFileExtractThread();
- ~CRarFileExtractThread();
-
- void Start(Archive* pArc, CommandData* pCmd, CmdExtract* pExtract, int iSize);
-
- virtual void OnStartup();
- virtual void OnExit();
- virtual void Process();
-
- CEvent hRunning;
- CEvent hRestart;
- CEvent hQuit;
-
- protected:
- Archive* m_pArc;
- CommandData* m_pCmd;
- CmdExtract* m_pExtract;
- int m_iSize;
- };
-#endif
-
- class CRarFile : public IFile
- {
- public:
- CRarFile();
- CRarFile(bool bSeekable); // used for caching files
- virtual ~CRarFile();
- virtual int64_t GetPosition();
- virtual int64_t GetLength();
- virtual bool Open(const CURL& url);
- virtual bool Exists(const CURL& url);
- virtual int Stat(const CURL& url, struct __stat64* buffer);
- virtual ssize_t Read(void* lpBuf, size_t uiBufSize);
- virtual ssize_t Write(const void* lpBuf, size_t uiBufSize);
- virtual int64_t Seek(int64_t iFilePosition, int iWhence=SEEK_SET);
- virtual void Close();
- virtual void Flush();
-
- virtual bool OpenForWrite(const CURL& url, bool);
- unsigned int Write(void *lpBuf, int64_t uiBufSize);
-
- protected:
- std::string m_strCacheDir;
- std::string m_strRarPath;
- std::string m_strPassword;
- std::string m_strPathInRar;
- BYTE m_bFileOptions;
- void Init();
- void InitFromUrl(const CURL& url);
- bool OpenInArchive();
- void CleanUp();
-
- int64_t m_iFilePosition;
- int64_t m_iFileSize;
- // rar stuff
- bool m_bUseFile;
- bool m_bOpen;
- bool m_bSeekable;
- CFile m_File; // for packed source
-#ifdef HAS_FILESYSTEM_RAR
- Archive* m_pArc;
- CommandData* m_pCmd;
- CmdExtract* m_pExtract;
- CRarFileExtractThread* m_pExtractThread;
-#endif
- uint8_t* m_szBuffer;
- uint8_t* m_szStartOfBuffer;
- int64_t m_iDataInBuffer;
- int64_t m_iBufferStart;
- };
-
-}
-
-#endif // FILERAR_H_
-
diff --git a/xbmc/filesystem/RarManager.cpp b/xbmc/filesystem/RarManager.cpp
deleted file mode 100644
index 9b6a79e1db..0000000000
--- a/xbmc/filesystem/RarManager.cpp
+++ /dev/null
@@ -1,531 +0,0 @@
-/*
- * Copyright (C) 2005-2015 Team Kodi
- * http://kodi.tv
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Kodi; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "system.h"
-#include "Application.h"
-#include "RarManager.h"
-#include "Util.h"
-#include "utils/CharsetConverter.h"
-#include "utils/URIUtils.h"
-#include "threads/SingleLock.h"
-#include "Directory.h"
-#include "SpecialProtocol.h"
-#include "settings/AdvancedSettings.h"
-#include "FileItem.h"
-#include "utils/log.h"
-#include "filesystem/File.h"
-#include "URL.h"
-
-#include "dialogs/GUIDialogYesNo.h"
-#include "dialogs/GUIDialogProgress.h"
-#include "guilib/GUIWindowManager.h"
-#include "utils/StringUtils.h"
-#include "utils/Variant.h"
-
-#include <set>
-
-#ifdef TARGET_POSIX
-#include "linux/XFileUtils.h"
-#endif
-
-#define EXTRACTION_WARN_SIZE 50*1024*1024
-
-using namespace XFILE;
-
-CFileInfo::CFileInfo()
- : m_bAutoDel{true}
- , m_iUsed{0}
- , m_iOffset{0}
- , m_iIsSeekable{-1}
-{
-}
-
-/////////////////////////////////////////////////
-CRarManager::CRarManager()
-{
-}
-
-CRarManager::~CRarManager()
-{
- ClearCache(true);
-}
-
-class progress_info
-{
-public:
- progress_info(const std::string &file) : heading(file), shown(false), showTime(200) // 200ms to show...
- {
- }
- ~progress_info()
- {
- if (shown && g_application.IsCurrentThread())
- {
- // close progress dialog
- CGUIDialogProgress* dlg = g_windowManager.GetWindow<CGUIDialogProgress>();
- if (dlg)
- dlg->Close();
- }
- }
- /*! \brief Progress callback from rar manager.
- \return true to continue processing, false to cancel.
- */
- bool progress(int progress, const char *text)
- {
- bool cont(true);
- if ((shown || showTime.IsTimePast()) && g_application.IsCurrentThread())
- {
- // grab the busy and show it
- CGUIDialogProgress* dlg = g_windowManager.GetWindow<CGUIDialogProgress>();
- if (dlg)
- {
- if (!shown)
- {
- dlg->SetHeading(CVariant{heading});
- dlg->Open();
- }
- if (progress >= 0)
- {
- dlg->ShowProgressBar(true);
- dlg->SetPercentage(progress);
- }
- if (text)
- dlg->SetLine(1, CVariant{text});
- cont = !dlg->IsCanceled();
- shown = true;
- // tell render loop to spin
- dlg->Progress();
- }
- }
- return cont;
- };
-private:
- std::string heading;
- bool shown;
- XbmcThreads::EndTime showTime;
-};
-
-/*! \brief Rar progress callback.
- \return false to halt progress, true to continue
- */
-bool ProgressCallback(void *context, int progress, const char *text)
-{
- progress_info* info = (progress_info*)context;
- if (info)
- return info->progress(progress, text);
- return true;
-}
-
-bool CRarManager::CacheRarredFile(std::string& strPathInCache, const std::string& strRarPath, const std::string& strPathInRar, BYTE bOptions, const std::string& strDir, const int64_t iSize)
-{
-#ifdef HAS_FILESYSTEM_RAR
- CSingleLock lock(m_CritSection);
-
- //If file is listed in the cache, then use listed copy or cleanup before overwriting.
- bool bOverwrite = (bOptions & EXFILE_OVERWRITE) != 0;
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator j = m_ExFiles.find( strRarPath );
- CFileInfo* pFile=NULL;
- if( j != m_ExFiles.end() )
- {
- pFile = GetFileInRar(strRarPath,strPathInRar);
- if (pFile)
- {
- if (pFile->m_bIsCanceled())
- return false;
-
- if( CFile::Exists( pFile->m_strCachedPath) )
- {
- if( !bOverwrite )
- {
- strPathInCache = pFile->m_strCachedPath;
- pFile->m_iUsed++;
- return true;
- }
-
- CFile::Delete(pFile->m_strCachedPath);
- pFile->m_iUsed++;
- }
- }
- }
-
- int iRes = 0;
- if (iSize > EXTRACTION_WARN_SIZE)
- {
- CGUIDialogYesNo* pDialog = g_windowManager.GetWindow<CGUIDialogYesNo>();
- if (pDialog)
- {
- pDialog->SetHeading(CVariant{120});
- pDialog->SetLine(0, CVariant{645});
- pDialog->SetLine(1, CVariant{URIUtils::GetFileName(strPathInRar)});
- pDialog->SetLine(2, CVariant{""});
- pDialog->Open();
-
- if (!pDialog->IsConfirmed())
- iRes = 2; // pretend to be canceled
- }
- }
- if (CheckFreeSpace(strDir) < iSize && iRes != 2)
- {
- ClearCache();
- if (CheckFreeSpace(strDir) < iSize)
- {
- CFileItemList items;
- CDirectory::GetDirectory(g_advancedSettings.m_cachePath,items);
- items.Sort(SortBySize, SortOrderDescending);
- while (items.Size() && CheckFreeSpace(strDir) < iSize)
- {
- if (!items[0]->m_bIsFolder)
- if (!CFile::Delete(items[0]->GetPath()))
- break;
-
- items.Remove(0);
- }
- if (!items.Size())
- return false;
- }
- }
-
- std::string strPath = strPathInRar;
-#ifndef TARGET_POSIX
- StringUtils::Replace(strPath, '/', '\\');
-#endif
- //g_charsetConverter.unknownToUTF8(strPath);
- std::string strCachedPath = URIUtils::AddFileToFolder(
- CSpecialProtocol::TranslatePath(strDir), "rarfolder%04d",
- URIUtils::GetFileName(strPathInRar));
- strCachedPath = CUtil::GetNextPathname(strCachedPath, 9999);
- if (strCachedPath.empty())
- {
- CLog::Log(LOGWARNING, "Could not cache file %s", (strRarPath + strPathInRar).c_str());
- return false;
- }
- strCachedPath = CUtil::MakeLegalPath(strCachedPath);
- int64_t iOffset = -1;
- if (iRes != 2)
- {
- if (pFile)
- {
- if (pFile->m_iOffset != -1)
- iOffset = pFile->m_iOffset;
- }
-
-
- if (iOffset == -1 && j != m_ExFiles.end()) // grab from list
- {
- for( ArchiveList_struct* pIterator = j->second.first; pIterator; pIterator = pIterator->next)
- {
- std::string strName;
-
- /* convert to utf8 */
- if( pIterator->item.NameW && wcslen(pIterator->item.NameW) > 0)
- g_charsetConverter.wToUTF8(pIterator->item.NameW, strName);
- else
- g_charsetConverter.unknownToUTF8(pIterator->item.Name, strName);
- if (strName == strPath)
- {
- iOffset = pIterator->item.iOffset;
- break;
- }
- }
- }
- bool bShowProgress=false;
- if (iSize > 1024*1024 || iSize == -2) // 1MB
- bShowProgress=true;
-
- std::string strDir2 = URIUtils::GetDirectory(strCachedPath);
- URIUtils::RemoveSlashAtEnd(strDir2);
- if (!CDirectory::Exists(strDir2))
- CDirectory::Create(strDir2);
- progress_info info(CURL(strPath).GetWithoutUserDetails());
- iRes = urarlib_get(const_cast<char*>(strRarPath.c_str()), const_cast<char*>(strDir2.c_str()),
- const_cast<char*>(strPath.c_str()),NULL,&iOffset,bShowProgress ? ProgressCallback : NULL, &info);
- }
- if (iRes == 0)
- {
- CLog::Log(LOGERROR,"failed to extract file: %s",strPathInRar.c_str());
- return false;
- }
-
- if(!pFile)
- {
- CFileInfo fileInfo;
- fileInfo.m_strPathInRar = strPathInRar;
- if (j == m_ExFiles.end())
- {
- ArchiveList_struct* pArchiveList;
- if(ListArchive(strRarPath,pArchiveList))
- {
- m_ExFiles.insert(std::make_pair(strRarPath, std::make_pair(pArchiveList, std::vector<CFileInfo>())));
- j = m_ExFiles.find(strRarPath);
- }
- else
- return false;
- }
- j->second.second.push_back(fileInfo);
- pFile = &(j->second.second[j->second.second.size()-1]);
- pFile->m_iUsed = 1;
- }
- pFile->m_strCachedPath = strCachedPath;
- pFile->m_bAutoDel = (bOptions & EXFILE_AUTODELETE) != 0;
- pFile->m_iOffset = iOffset;
- strPathInCache = pFile->m_strCachedPath;
-
- if (iRes == 2) //canceled
- {
- pFile->watch.StartZero();
- CFile::Delete(pFile->m_strCachedPath);
- return false;
- }
-#endif
- return true;
-}
-
-// NB: The rar manager expects paths in rars to be terminated with a "\".
-bool CRarManager::GetFilesInRar(CFileItemList& vecpItems, const std::string& strRarPath,
- bool bMask, const std::string& strPathInRar)
-{
-#ifdef HAS_FILESYSTEM_RAR
- CSingleLock lock(m_CritSection);
-
- ArchiveList_struct* pFileList = NULL;
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator it = m_ExFiles.find(strRarPath);
- if (it == m_ExFiles.end())
- {
- if( urarlib_list((char*) strRarPath.c_str(), &pFileList, NULL) )
- m_ExFiles.insert(std::make_pair(strRarPath, std::make_pair(pFileList, std::vector<CFileInfo>())));
- else
- {
- if( pFileList ) urarlib_freelist(pFileList);
- return false;
- }
- }
- else
- pFileList = it->second.first;
-
- CFileItemPtr pFileItem;
- std::vector<std::string> vec;
- std::set<std::string> dirSet;
- StringUtils::Tokenize(strPathInRar,vec,"/");
- unsigned int iDepth = vec.size();
-
- ArchiveList_struct* pIterator;
- std::string strCompare = strPathInRar;
- if (!URIUtils::HasSlashAtEnd(strCompare) && !strCompare.empty())
- strCompare += '/';
- for( pIterator = pFileList; pIterator ; pIterator = pIterator->next )
- {
- std::string strName;
-
- /* convert to utf8 */
- if( pIterator->item.NameW && wcslen(pIterator->item.NameW) > 0)
- g_charsetConverter.wToUTF8(pIterator->item.NameW, strName);
- else
- g_charsetConverter.unknownToUTF8(pIterator->item.Name, strName);
-
- /* replace back slashes into forward slashes */
- /* this could get us into troubles, file could two different files, one with / and one with \ */
- StringUtils::Replace(strName, '\\', '/');
-
- if (bMask)
- {
- if (!strstr(strName.c_str(),strCompare.c_str()))
- continue;
-
- vec.clear();
- StringUtils::Tokenize(strName,vec,"/");
- if (vec.size() < iDepth)
- continue;
- }
-
- unsigned int iMask = (pIterator->item.HostOS==3 ? 0x0040000:16); // win32 or unix attribs?
- if (((pIterator->item.FileAttr & iMask) == iMask) || (vec.size() > iDepth+1 && bMask)) // we have a directory
- {
- if (!bMask) continue;
- if (vec.size() == iDepth)
- continue; // remove root of listing
-
- if (dirSet.find(vec[iDepth]) == dirSet.end())
- {
- dirSet.insert(vec[iDepth]);
- pFileItem.reset(new CFileItem(vec[iDepth]));
- pFileItem->SetPath(vec[iDepth] + '/');
- pFileItem->m_bIsFolder = true;
- pFileItem->m_idepth = pIterator->item.Method;
- pFileItem->m_iDriveType = pIterator->item.HostOS;
- //pFileItem->m_lEndOffset = long(pIterator->item.iOffset);
- }
- }
- else
- {
- if (vec.size() == iDepth+1 || !bMask)
- {
- if (vec.empty())
- pFileItem.reset(new CFileItem(strName));
- else
- pFileItem.reset(new CFileItem(vec[iDepth]));
- pFileItem->SetPath(strName.c_str()+strPathInRar.size());
- pFileItem->m_dwSize = pIterator->item.UnpSize;
- pFileItem->m_idepth = pIterator->item.Method;
- pFileItem->m_iDriveType = pIterator->item.HostOS;
- //pFileItem->m_lEndOffset = long(pIterator->item.iOffset);
- }
- }
- if (pFileItem)
- vecpItems.Add(pFileItem);
-
- pFileItem.reset();
- }
- return vecpItems.Size() > 0;
-#else
- return false;
-#endif
-}
-
-bool CRarManager::ListArchive(const std::string& strRarPath, ArchiveList_struct* &pArchiveList)
-{
-#ifdef HAS_FILESYSTEM_RAR
- return urarlib_list((char*) strRarPath.c_str(), &pArchiveList, NULL) == 1;
-#else
- return false;
-#endif
-}
-
-CFileInfo* CRarManager::GetFileInRar(const std::string& strRarPath, const std::string& strPathInRar)
-{
-#ifdef HAS_FILESYSTEM_RAR
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator j = m_ExFiles.find(strRarPath);
- if (j == m_ExFiles.end())
- return NULL;
-
- for (std::vector<CFileInfo>::iterator it2=j->second.second.begin(); it2 != j->second.second.end(); ++it2)
- if (it2->m_strPathInRar == strPathInRar)
- return &(*it2);
-#endif
- return NULL;
-}
-
-bool CRarManager::GetPathInCache(std::string& strPathInCache, const std::string& strRarPath, const std::string& strPathInRar)
-{
-#ifdef HAS_FILESYSTEM_RAR
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator j = m_ExFiles.find(strRarPath);
- if (j == m_ExFiles.end())
- return false;
-
- for (std::vector<CFileInfo>::iterator it2=j->second.second.begin(); it2 != j->second.second.end(); ++it2)
- if (it2->m_strPathInRar == strPathInRar)
- return CFile::Exists(it2->m_strCachedPath);
-#endif
- return false;
-}
-
-bool CRarManager::IsFileInRar(bool& bResult, const std::string& strRarPath, const std::string& strPathInRar)
-{
-#ifdef HAS_FILESYSTEM_RAR
- bResult = false;
- CFileItemList ItemList;
-
- if (!GetFilesInRar(ItemList,strRarPath,false))
- return false;
-
- int it;
- for (it=0;it<ItemList.Size();++it)
- {
- if (strPathInRar.compare(ItemList[it]->GetPath()) == 0)
- break;
- }
- if (it != ItemList.Size())
- bResult = true;
-
- return true;
-#else
- return false;
-#endif
-}
-
-void CRarManager::ClearCache(bool force)
-{
-#ifdef HAS_FILESYSTEM_RAR
- CSingleLock lock(m_CritSection);
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator j;
- for (j = m_ExFiles.begin() ; j != m_ExFiles.end() ; ++j)
- {
-
- for (std::vector<CFileInfo>::iterator it2 = j->second.second.begin(); it2 != j->second.second.end(); ++it2)
- {
- CFileInfo* pFile = &(*it2);
- if (pFile->m_bAutoDel && (pFile->m_iUsed < 1 || force))
- CFile::Delete( pFile->m_strCachedPath );
- }
- urarlib_freelist(j->second.first);
- }
-
- m_ExFiles.clear();
-#endif
-}
-
-void CRarManager::ClearCachedFile(const std::string& strRarPath, const std::string& strPathInRar)
-{
-#ifdef HAS_FILESYSTEM_RAR
- CSingleLock lock(m_CritSection);
-
- std::map<std::string, std::pair<ArchiveList_struct*, std::vector<CFileInfo> > >::iterator j = m_ExFiles.find(strRarPath);
- if (j == m_ExFiles.end())
- {
- return; // no such subpath
- }
-
- for (std::vector<CFileInfo>::iterator it = j->second.second.begin(); it != j->second.second.end(); ++it)
- {
- if (it->m_strPathInRar == strPathInRar)
- if (it->m_iUsed > 0)
- {
- it->m_iUsed--;
- break;
- }
- }
-#endif
-}
-
-void CRarManager::ExtractArchive(const std::string& strArchive, const std::string& strPath)
-{
-#ifdef HAS_FILESYSTEM_RAR
- std::string strPath2(strPath);
- URIUtils::RemoveSlashAtEnd(strPath2);
- if (!urarlib_get(const_cast<char*>(strArchive.c_str()), const_cast<char*>(strPath2.c_str()),NULL))
- {
- CLog::Log(LOGERROR,"rarmanager::extractarchive error while extracting %s", strArchive.c_str());
- return;
- }
-#endif
-}
-
-int64_t CRarManager::CheckFreeSpace(const std::string& strDrive)
-{
- ULARGE_INTEGER lTotalFreeBytes;
-#ifdef TARGET_WINDOWS
- std::wstring path;
- g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(strDrive), path);
-#else
- auto path = CSpecialProtocol::TranslatePath(strDrive);
-#endif
- if (GetDiskFreeSpaceEx(path.c_str(), NULL, NULL, &lTotalFreeBytes))
- return lTotalFreeBytes.QuadPart;
-
- return 0;
-}
diff --git a/xbmc/filesystem/RarManager.h b/xbmc/filesystem/RarManager.h
deleted file mode 100644
index c7f557d520..0000000000
--- a/xbmc/filesystem/RarManager.h
+++ /dev/null
@@ -1,92 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "threads/CriticalSection.h"
-#include "UnrarXLib/UnrarX.hpp"
-#include "utils/Stopwatch.h"
-#include "utils/GlobalsHandling.h"
-
-class CFileItemList;
-
-#define EXFILE_OVERWRITE 1
-#define EXFILE_AUTODELETE 2
-#define EXFILE_UNIXPATH 4
-#define EXFILE_NOCACHE 8
-#define RAR_DEFAULT_CACHE "special://temp/"
-#define RAR_DEFAULT_PASSWORD ""
-
-class CFileInfo{
-public:
- CFileInfo();
- ~CFileInfo() = default;
- std::string m_strCachedPath;
- std::string m_strPathInRar;
- bool m_bAutoDel;
- int m_iUsed;
- int64_t m_iOffset;
-
- bool m_bIsCanceled()
- {
- if (watch.IsRunning())
- if (watch.GetElapsedSeconds() < 3)
- return true;
-
- watch.Stop();
- return false;
- }
- CStopWatch watch;
- int m_iIsSeekable;
-};
-
-class CRarManager
-{
-public:
- CRarManager();
- ~CRarManager();
- bool CacheRarredFile(std::string& strPathInCache, const std::string& strRarPath,
- const std::string& strPathInRar, uint8_t bOptions = EXFILE_AUTODELETE,
- const std::string& strDir =RAR_DEFAULT_CACHE, const int64_t iSize=-1);
- bool GetPathInCache(std::string& strPathInCache, const std::string& strRarPath,
- const std::string& strPathInRar = "");
- bool GetFilesInRar(CFileItemList& vecpItems, const std::string& strRarPath,
- bool bMask=true, const std::string& strPathInRar="");
- CFileInfo* GetFileInRar(const std::string& strRarPath, const std::string& strPathInRar);
- bool IsFileInRar(bool& bResult, const std::string& strRarPath, const std::string& strPathInRar);
- void ClearCache(bool force=false);
- void ClearCachedFile(const std::string& strRarPath, const std::string& strPathInRar);
- void ExtractArchive(const std::string& strArchive, const std::string& strPath);
-protected:
-
- bool ListArchive(const std::string& strRarPath, ArchiveList_struct* &pArchiveList);
- std::map<std::string, std::pair<ArchiveList_struct*,std::vector<CFileInfo> > > m_ExFiles;
- CCriticalSection m_CritSection;
-
- int64_t CheckFreeSpace(const std::string& strDrive);
-};
-
-XBMC_GLOBAL_REF(CRarManager, g_RarManager);
-#define g_RarManager XBMC_GLOBAL_USE(CRarManager)
-
diff --git a/xbmc/filesystem/test/CMakeLists.txt b/xbmc/filesystem/test/CMakeLists.txt
index 5d77633658..6946a6e56a 100644
--- a/xbmc/filesystem/test/CMakeLists.txt
+++ b/xbmc/filesystem/test/CMakeLists.txt
@@ -1,7 +1,6 @@
set(SOURCES TestDirectory.cpp
TestFile.cpp
TestFileFactory.cpp
- TestRarFile.cpp
TestZipFile.cpp)
core_add_test_library(filesystem_test)
diff --git a/xbmc/filesystem/test/TestRarFile.cpp b/xbmc/filesystem/test/TestRarFile.cpp
deleted file mode 100644
index 0d33a2530a..0000000000
--- a/xbmc/filesystem/test/TestRarFile.cpp
+++ /dev/null
@@ -1,651 +0,0 @@
-/*
- * Copyright (C) 2005-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "system.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "filesystem/Directory.h"
-#include "filesystem/File.h"
-#include "filesystem/RarManager.h"
-#include "URL.h"
-#include "utils/URIUtils.h"
-#include "FileItem.h"
-#include "test/TestUtils.h"
-#include "utils/StringUtils.h"
-
-#include <errno.h>
-
-#include "gtest/gtest.h"
-
-#ifndef S_IFLNK
-#define S_IFLNK 0120000
-#endif
-
-TEST(TestRarFile, Read)
-{
- XFILE::CFile file;
- char buf[20];
- memset(&buf, 0, sizeof(buf));
- std::string reffile, strpathinrar;
- CFileItemList itemlist;
-
- reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.rar");
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(reffile), "");
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(rarUrl, itemlist, "",
- XFILE::DIR_FLAG_NO_FILE_DIRS));
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1716, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
- // Manual clear to avoid shutdown race
- g_RarManager.ClearCache();
- file.Close();
-}
-
-TEST(TestRarFile, Exists)
-{
- std::string reffile, strpathinrar;
- CFileItemList itemlist;
-
- reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.rar");
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(reffile), "");
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(rarUrl, itemlist, "",
- XFILE::DIR_FLAG_NO_FILE_DIRS));
- strpathinrar = itemlist[0]->GetPath();
-
- EXPECT_TRUE(XFILE::CFile::Exists(strpathinrar));
-
- // Manual clear to avoid shutdown race
- g_RarManager.ClearCache();
-}
-
-TEST(TestRarFile, Stat)
-{
- struct __stat64 buffer;
- std::string reffile, strpathinrar;
- CFileItemList itemlist;
-
- reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.rar");
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(reffile), "");
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(rarUrl, itemlist, "",
- XFILE::DIR_FLAG_NO_FILE_DIRS));
- strpathinrar = itemlist[0]->GetPath();
-
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &buffer));
- EXPECT_TRUE(buffer.st_mode | _S_IFREG);
-
- // Manual clear to avoid shutdown race
- g_RarManager.ClearCache();
-}
-
-/* Test case to test for graceful handling of corrupted input.
- * NOTE: The test case is considered a "success" as long as the corrupted
- * file was successfully generated and the test case runs without a segfault.
- */
-TEST(TestRarFile, CorruptedFile)
-{
- XFILE::CFile *file;
- char buf[16];
- memset(&buf, 0, sizeof(buf));
- std::string reffilepath, strpathinrar, str;
- CFileItemList itemlist;
- unsigned int size, i;
- int64_t count = 0;
-
- reffilepath = XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt.rar");
- ASSERT_TRUE((file = XBMC_CREATECORRUPTEDFILE(reffilepath, ".rar")) != NULL);
- std::cout << "Reference file generated at '" << XBMC_TEMPFILEPATH(file) << "'" << std::endl;
-
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(XBMC_TEMPFILEPATH(file)), "");
- if (!XFILE::CDirectory::GetDirectory(rarUrl, itemlist, "",
- XFILE::DIR_FLAG_NO_FILE_DIRS))
- {
- XBMC_DELETETEMPFILE(file);
- SUCCEED();
- return;
- }
- if (itemlist.IsEmpty())
- {
- XBMC_DELETETEMPFILE(file);
- SUCCEED();
- return;
- }
- strpathinrar = itemlist[0]->GetPath();
-
- if (!file->Open(strpathinrar))
- {
- XBMC_DELETETEMPFILE(file);
- SUCCEED();
- return;
- }
- std::cout << "file->GetLength(): " <<
- testing::PrintToString(file->GetLength()) << std::endl;
- std::cout << "file->Seek(file->GetLength() / 2, SEEK_CUR) return value: " <<
- testing::PrintToString(file->Seek(file->GetLength() / 2, SEEK_CUR)) << std::endl;
- std::cout << "file->Seek(0, SEEK_END) return value: " <<
- testing::PrintToString(file->Seek(0, SEEK_END)) << std::endl;
- std::cout << "file->Seek(0, SEEK_SET) return value: " <<
- testing::PrintToString(file->Seek(0, SEEK_SET)) << std::endl;
- std::cout << "File contents:" << std::endl;
- while ((size = file->Read(buf, sizeof(buf))) > 0)
- {
- str = StringUtils::Format(" %08llX", count);
- std::cout << str << " ";
- count += size;
- for (i = 0; i < size; i++)
- {
- str = StringUtils::Format("%02X ", buf[i]);
- std::cout << str;
- }
- while (i++ < sizeof(buf))
- std::cout << " ";
- std::cout << " [";
- for (i = 0; i < size; i++)
- {
- if (buf[i] >= ' ' && buf[i] <= '~')
- std::cout << buf[i];
- else
- std::cout << ".";
- }
- std::cout << "]" << std::endl;
- }
- file->Close();
- XBMC_DELETETEMPFILE(file);
-
- // Manual clear to avoid shutdown race
- g_RarManager.ClearCache();
-}
-
-TEST(TestRarFile, StoredRAR)
-{
- XFILE::CFile file;
- char buf[20];
- memset(&buf, 0, sizeof(buf));
- std::string reffile, strpathinrar;
- CFileItemList itemlist, itemlistemptydir;
- struct __stat64 stat_buffer;
-
- reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/refRARstored.rar");
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(reffile), "");
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(rarUrl, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /reffile.txt */
- /*
- * NOTE: Use of Seek gives inconsistent behavior from when seeking through
- * an uncompressed RAR archive. See TestRarFile.Read test case.
- */
- strpathinrar = itemlist[1]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
- file.Close();
-
- /* /testsymlink -> testdir/reffile.txt */
- strpathinrar = itemlist[2]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlink"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- /*
- * FIXME: Reading symlinks in RARs is currently broken. It takes a long time
- * to read them and they produce erroneous results. The expected result is
- * the target paths of the symlinks.
- */
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(19, file.GetLength());
- file.Close();
-
- /* /testsymlinksubdir -> testdir/testsubdir/reffile.txt */
- strpathinrar = itemlist[3]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlinksubdir"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(30, file.GetLength());
- file.Close();
-
- /* /testdir/ */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- itemlist.Clear();
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /testdir/reffile.txt */
- strpathinrar = itemlist[1]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
- file.Close();
-
- /* /testdir/testemptysubdir */
- strpathinrar = itemlist[2]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testemptysubdir"));
- //! @todo Should this set the itemlist to an empty list instead?
- EXPECT_FALSE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlistemptydir));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- //! @todo FIXME: This directory appears a second time as a file
- strpathinrar = itemlist[3]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir"));
-
- /* /testdir/testsymlink -> testsubdir/reffile.txt */
- strpathinrar = itemlist[4]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsymlink"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(22, file.GetLength());
- file.Close();
-
- /* /testdir/testsubdir/ */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir/"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- itemlist.Clear();
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /testdir/testsubdir/reffile.txt */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar,
- "/testdir/testsubdir/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(-1, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-100, file.Seek(-100, SEEK_SET));
- file.Close();
-}
-
-TEST(TestRarFile, NormalRAR)
-{
- XFILE::CFile file;
- char buf[20];
- memset(&buf, 0, sizeof(buf));
- std::string reffile, strpathinrar;
- CFileItemList itemlist, itemlistemptydir;
- struct __stat64 stat_buffer;
-
- reffile = XBMC_REF_FILE_PATH("xbmc/filesystem/test/refRARnormal.rar");
- CURL rarUrl = URIUtils::CreateArchivePath("rar", CURL(reffile), "");
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(rarUrl, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /reffile.txt */
- strpathinrar = itemlist[1]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1716, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
- file.Close();
-
- /* /testsymlink -> testdir/reffile.txt */
- strpathinrar = itemlist[2]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlink"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- /*
- * FIXME: Reading symlinks in RARs is currently broken. It takes a long time
- * to read them and they produce erroneous results. The expected result is
- * the target paths of the symlinks.
- */
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(19, file.GetLength());
- file.Close();
-
- /* /testsymlinksubdir -> testdir/testsubdir/reffile.txt */
- strpathinrar = itemlist[3]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testsymlinksubdir"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(30, file.GetLength());
- file.Close();
-
- /* /testdir/ */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- itemlist.Clear();
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /testdir/reffile.txt */
- strpathinrar = itemlist[1]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1716, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
- file.Close();
-
- /* /testdir/testemptysubdir */
- strpathinrar = itemlist[2]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testemptysubdir"));
- /* @todo Should this set the itemlist to an empty list instead? */
- EXPECT_FALSE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlistemptydir));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- /* FIXME: This directory appears a second time as a file */
- strpathinrar = itemlist[3]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir"));
-
- /* /testdir/testsymlink -> testsubdir/reffile.txt */
- strpathinrar = itemlist[4]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsymlink"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFLNK);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(22, file.GetLength());
- file.Close();
-
- /* /testdir/testsubdir/ */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar, "/testdir/testsubdir/"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFDIR);
-
- itemlist.Clear();
- ASSERT_TRUE(XFILE::CDirectory::GetDirectory(strpathinrar, itemlist));
- itemlist.Sort(SortByPath, SortOrderAscending);
-
- /* /testdir/testsubdir/reffile.txt */
- strpathinrar = itemlist[0]->GetPath();
- ASSERT_TRUE(StringUtils::EndsWith(strpathinrar,
- "/testdir/testsubdir/reffile.txt"));
- EXPECT_EQ(0, XFILE::CFile::Stat(strpathinrar, &stat_buffer));
- EXPECT_TRUE((stat_buffer.st_mode & S_IFMT) | S_IFREG);
-
- ASSERT_TRUE(file.Open(strpathinrar));
- EXPECT_EQ(0, file.GetPosition());
- EXPECT_EQ(1616, file.GetLength());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_TRUE(file.ReadString(buf, sizeof(buf)));
- EXPECT_EQ(39, file.GetPosition());
- EXPECT_STREQ("an award-winning fr", buf);
- EXPECT_EQ(100, file.Seek(100));
- EXPECT_EQ(100, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(120, file.GetPosition());
- EXPECT_TRUE(!memcmp("ent hub for digital ", buf, sizeof(buf) - 1));
- EXPECT_EQ(220, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(220, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(240, file.GetPosition());
- EXPECT_TRUE(!memcmp("rs, XBMC is a non-pr", buf, sizeof(buf) - 1));
- EXPECT_EQ(1596, file.Seek(-(int64_t)sizeof(buf), SEEK_END));
- EXPECT_EQ(1596, file.GetPosition());
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(1616, file.GetPosition());
- EXPECT_TRUE(!memcmp("multimedia jukebox.\n", buf, sizeof(buf) - 1));
- EXPECT_EQ(1716, file.Seek(100, SEEK_CUR));
- EXPECT_EQ(1716, file.GetPosition());
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(sizeof(buf), file.Read(buf, sizeof(buf)));
- file.Flush();
- EXPECT_EQ(20, file.GetPosition());
- EXPECT_TRUE(!memcmp("About\n-----\nXBMC is ", buf, sizeof(buf) - 1));
- EXPECT_EQ(0, file.Seek(0, SEEK_SET));
- EXPECT_EQ(-1, file.Seek(-100, SEEK_SET));
- file.Close();
-
- // Manual clear to avoid shutdown race
- g_RarManager.ClearCache();
-}
-#endif /*HAS_FILESYSTEM_RAR*/
diff --git a/xbmc/interfaces/builtins/ApplicationBuiltins.cpp b/xbmc/interfaces/builtins/ApplicationBuiltins.cpp
index 2ea99d19fc..1e05ad04ed 100644
--- a/xbmc/interfaces/builtins/ApplicationBuiltins.cpp
+++ b/xbmc/interfaces/builtins/ApplicationBuiltins.cpp
@@ -22,9 +22,6 @@
#include "Application.h"
#include "ServiceBroker.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "filesystem/RarManager.h"
-#endif
#include "filesystem/ZipManager.h"
#include "messaging/ApplicationMessenger.h"
#include "input/Key.h"
@@ -61,10 +58,6 @@ static int Extract(const std::vector<std::string>& params)
if (URIUtils::IsZIP(params[0]))
g_ZipManager.ExtractArchive(params[0],strDestDirect);
-#ifdef HAS_FILESYSTEM_RAR
- else if (URIUtils::IsRAR(params[0]))
- g_RarManager.ExtractArchive(params[0],strDestDirect);
-#endif
else
CLog::Log(LOGERROR, "Extract, No archive given");
diff --git a/xbmc/system.h b/xbmc/system.h
index 278413d4bd..6360ee2706 100644
--- a/xbmc/system.h
+++ b/xbmc/system.h
@@ -78,14 +78,6 @@
#endif
#endif
-/**********************
- * Non-free Components
- **********************/
-
-#if defined(HAVE_XBMC_NONFREE)
- #define HAS_FILESYSTEM_RAR
-#endif
-
/*****************
* Win32 Specific
*****************/
diff --git a/xbmc/utils/URIUtils.cpp b/xbmc/utils/URIUtils.cpp
index f13a71b2af..f209b46dd9 100644
--- a/xbmc/utils/URIUtils.cpp
+++ b/xbmc/utils/URIUtils.cpp
@@ -1261,7 +1261,7 @@ CURL URIUtils::CreateArchivePath(const std::string& type,
/* NOTE: on posix systems, the replacement of \ with / is incorrect.
Ideally this would not be done. We need to check that the ZipManager
- and RarManager code (and elsewhere) doesn't pass in non-posix paths.
+ code (and elsewhere) doesn't pass in non-posix paths.
*/
std::string strBuffer(pathInArchive);
StringUtils::Replace(strBuffer, '\\', '/');