Permalink
Browse files

Merge pull request #658 from jmarshallnz/getdirectory_flags

Getdirectory: Use flags rather than a bunch of bools
  • Loading branch information...
2 parents 4979418 + f1c6e77 commit 426c1cf12470143ea92e799f972b9c3ba60f8ede @jmarshallnz jmarshallnz committed Apr 6, 2012
View
@@ -1866,7 +1866,7 @@ bool CApplication::LoadUserWindows()
{
CLog::Log(LOGINFO, "Loading user windows, path %s", vecSkinPath[i].c_str());
CFileItemList items;
- if (CDirectory::GetDirectory(vecSkinPath[i], items, ".xml", false))
+ if (CDirectory::GetDirectory(vecSkinPath[i], items, ".xml", DIR_FLAG_NO_FILE_DIRS))
{
for (int i = 0; i < items.Size(); ++i)
{
View
@@ -2071,7 +2071,7 @@ void CFileItemList::StackFolders()
if (bMatch)
{
CFileItemList items;
- CDirectory::GetDirectory(item->GetPath(),items,g_settings.m_videoExtensions,true);
+ CDirectory::GetDirectory(item->GetPath(),items,g_settings.m_videoExtensions);
// optimized to only traverse listing once by checking for filecount
// and recording last file item for later use
int nFiles = 0;
@@ -2874,11 +2874,11 @@ CStdString CFileItem::GetLocalFanart() const
return "";
CFileItemList items;
- CDirectory::GetDirectory(strDir, items, g_settings.m_pictureExtensions, false, false, DIR_CACHE_ALWAYS, false, true);
+ CDirectory::GetDirectory(strDir, items, g_settings.m_pictureExtensions, DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO);
if (IsOpticalMediaFile())
{ // grab from the optical media parent folder as well - see GetUserVideoThumb
CFileItemList moreItems;
- CDirectory::GetDirectory(GetLocalMetadataPath(), moreItems, g_settings.m_pictureExtensions, false, false, DIR_CACHE_ALWAYS, false, true);
+ CDirectory::GetDirectory(GetLocalMetadataPath(), moreItems, g_settings.m_pictureExtensions, DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO);
items.Append(moreItems);
}
@@ -3127,7 +3127,7 @@ CStdString CFileItem::FindTrailer() const
CStdString strDir;
URIUtils::GetDirectory(strFile, strDir);
CFileItemList items;
- CDirectory::GetDirectory(strDir, items, g_settings.m_videoExtensions, true, false, DIR_CACHE_ALWAYS, false, true);
+ CDirectory::GetDirectory(strDir, items, g_settings.m_videoExtensions, DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO);
URIUtils::RemoveExtension(strFile);
strFile += "-trailer";
CStdString strFile3 = URIUtils::AddFileToFolder(strDir, "movie-trailer");
View
@@ -710,7 +710,7 @@ void CUtil::RemoveTempFiles()
{
CStdString searchPath = g_settings.GetDatabaseFolder();
CFileItemList items;
- if (!XFILE::CDirectory::GetDirectory(searchPath, items, ".tmp", false))
+ if (!XFILE::CDirectory::GetDirectory(searchPath, items, ".tmp", DIR_FLAG_NO_FILE_DIRS))
return;
for (int i = 0; i < items.Size(); ++i)
@@ -747,7 +747,7 @@ void CUtil::ClearTempFonts()
return;
CFileItemList items;
- CDirectory::GetDirectory(searchPath, items, "", false, false, XFILE::DIR_CACHE_NEVER);
+ CDirectory::GetDirectory(searchPath, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_BYPASS_CACHE);
for (int i=0; i<items.Size(); ++i)
{
@@ -801,7 +801,7 @@ CStdString CUtil::GetNextFilename(const CStdString &fn_template, int max)
name.Format(fn_template.c_str(), 0);
CFileItemList items;
- if (!CDirectory::GetDirectory(searchPath, items, mask, false))
+ if (!CDirectory::GetDirectory(searchPath, items, mask, DIR_FLAG_NO_FILE_DIRS))
return name;
items.SetFastLookup(true);
@@ -1651,7 +1651,7 @@ void CUtil::DeleteDirectoryCache(const CStdString &prefix)
{
CStdString searchPath = "special://temp/";
CFileItemList items;
- if (!XFILE::CDirectory::GetDirectory(searchPath, items, ".fi", false))
+ if (!XFILE::CDirectory::GetDirectory(searchPath, items, ".fi", DIR_FLAG_NO_FILE_DIRS))
return;
for (int i = 0; i < items.Size(); ++i)
@@ -1776,7 +1776,10 @@ int CUtil::GMTZoneCalc(int iRescBiases, int iHour, int iMinute, int &iMinuteNew)
void CUtil::GetRecursiveListing(const CStdString& strPath, CFileItemList& items, const CStdString& strMask, bool bUseFileDirectories)
{
CFileItemList myItems;
- CDirectory::GetDirectory(strPath,myItems,strMask,bUseFileDirectories);
+ int flags = DIR_FLAG_DEFAULTS;
+ if (!bUseFileDirectories)
+ flags |= DIR_FLAG_NO_FILE_DIRS;
+ CDirectory::GetDirectory(strPath,myItems,strMask,flags);
for (int i=0;i<myItems.Size();++i)
{
if (myItems[i]->m_bIsFolder)
@@ -1789,7 +1792,7 @@ void CUtil::GetRecursiveListing(const CStdString& strPath, CFileItemList& items,
void CUtil::GetRecursiveDirsListing(const CStdString& strPath, CFileItemList& item)
{
CFileItemList myItems;
- CDirectory::GetDirectory(strPath,myItems,"",false);
+ CDirectory::GetDirectory(strPath,myItems,"",DIR_FLAG_NO_FILE_DIRS);
for (int i=0;i<myItems.Size();++i)
{
if (myItems[i]->m_bIsFolder && !myItems[i]->GetPath().Equals(".."))
@@ -2358,7 +2361,7 @@ void CUtil::ScanForExternalSubtitles(const CStdString& strMovie, std::vector<CSt
{
CFileItemList items;
- CDirectory::GetDirectory(strLookInPaths[step], items,".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|.ass|.idx|.ifo|.rar|.zip",false);
+ CDirectory::GetDirectory(strLookInPaths[step], items,".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|.ass|.idx|.ifo|.rar|.zip",DIR_FLAG_NO_FILE_DIRS);
int fnl = strMovieFileNameNoExt.size();
for (int j = 0; j < items.Size(); j++)
@@ -2386,7 +2389,6 @@ void CUtil::ScanForExternalSubtitles(const CStdString& strMovie, std::vector<CSt
}
}
}
- g_directoryCache.ClearDirectory(strLookInPaths[step]);
}
}
@@ -2430,7 +2432,7 @@ int CUtil::ScanArchiveForSubtitles( const CStdString& strArchivePath, const CStd
{
CStdString strZipPath;
URIUtils::CreateArchivePath(strZipPath,"zip",strArchivePath,"");
- if (!CDirectory::GetDirectory(strZipPath,ItemList,"",false))
+ if (!CDirectory::GetDirectory(strZipPath,ItemList,"",DIR_FLAG_NO_FILE_DIRS))
return false;
}
else
@@ -377,7 +377,7 @@ void CGUIDialogAddonInfo::OnJobComplete(unsigned int jobID, bool success,
void CGUIDialogAddonInfo::GrabRollbackVersions()
{
CFileItemList items;
- XFILE::CDirectory::GetDirectory("special://home/addons/packages/",items,".zip",false);
+ XFILE::CDirectory::GetDirectory("special://home/addons/packages/",items,".zip",DIR_FLAG_NO_FILE_DIRS);
items.Sort(SORT_METHOD_LABEL,SORT_ORDER_ASC);
for (int i=0;i<items.Size();++i)
{
@@ -918,9 +918,9 @@ vector<CStdString> CGUIDialogAddonSettings::GetFileEnumValues(const CStdString &
// fetch directory
CFileItemList items;
if (!mask.IsEmpty())
- CDirectory::GetDirectory(fullPath, items, mask, false);
+ CDirectory::GetDirectory(fullPath, items, mask, XFILE::DIR_FLAG_NO_FILE_DIRS);
else
- CDirectory::GetDirectory(fullPath, items, "", false);
+ CDirectory::GetDirectory(fullPath, items, "", XFILE::DIR_FLAG_NO_FILE_DIRS);
vector<CStdString> values;
for (int i = 0; i < items.Size(); ++i)
View
@@ -105,7 +105,7 @@ void CSkinInfo::Start(const CStdString &strBaseDir)
if (!m_resolutions.size())
{ // try falling back to whatever resolutions exist in the directory
CFileItemList items;
- CDirectory::GetDirectory(Path(), items, "", false);
+ CDirectory::GetDirectory(Path(), items, "", DIR_FLAG_NO_FILE_DIRS);
for (int i = 0; i < items.Size(); i++)
{
RESOLUTION_INFO res;
@@ -893,7 +893,7 @@ void CGUIDialogFileBrowser::OnAddNetworkLocation()
{
// verify the path by doing a GetDirectory.
CFileItemList items;
- if (CDirectory::GetDirectory(path, items, "", false, true) || CGUIDialogYesNo::ShowAndGetInput(1001,1002,1003,1004))
+ if (CDirectory::GetDirectory(path, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_ALLOW_PROMPT) || CGUIDialogYesNo::ShowAndGetInput(1001,1002,1003,1004))
{ // add the network location to the shares list
CMediaSource share;
share.strPath = path; //setPath(path);
@@ -327,7 +327,7 @@ void CGUIDialogMediaSource::OnOK()
VECSOURCES *shares = g_settings.GetSourcesFromType(m_type);
if (shares)
shares->push_back(share);
- if (share.strPath.Left(9).Equals("plugin://") || CDirectory::GetDirectory(share.strPath, items, "", false, true) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
+ if (share.strPath.Left(9).Equals("plugin://") || CDirectory::GetDirectory(share.strPath, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_ALLOW_PROMPT) || CGUIDialogYesNo::ShowAndGetInput(1001,1025,1003,1004))
{
m_confirmed = true;
Close();
@@ -184,7 +184,7 @@ void CGUIDialogSmartPlaylistRule::OnBrowse()
CStdString path = "special://videoplaylists/";
if (m_type.Equals("songs") || m_type.Equals("albums"))
path = "special://musicplaylists/";
- XFILE::CDirectory::GetDirectory(path, items, ".xsp",false,false,XFILE::DIR_CACHE_ONCE,true,true);
+ XFILE::CDirectory::GetDirectory(path, items, ".xsp", XFILE::DIR_FLAG_NO_FILE_DIRS);
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr item = items[i];
@@ -132,7 +132,7 @@ bool CAFPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items
{
if (afpError == CAfpConnection::AfpAuth)
{
- if (m_allowPrompting)
+ if (m_flags & DIR_FLAG_ALLOW_PROMPT)
{
RequireAuthentication(url.Get());
}
@@ -200,7 +200,7 @@ bool CAFPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items
{
struct stat info = {0};
- if (m_extFileInfo && g_advancedSettings.m_sambastatfiles)
+ if ((m_flags & DIR_FLAG_NO_FILE_INFO)==0 && g_advancedSettings.m_sambastatfiles)
{
// make sure we use the authenticated path wich contains any default username
CStdString strFullName = strDirName + strFile;
@@ -40,8 +40,6 @@ namespace XFILE
CAddonsDirectory::CAddonsDirectory(void)
{
- m_allowPrompting = true;
- m_cacheDirectory = DIR_CACHE_ONCE;
}
CAddonsDirectory::~CAddonsDirectory(void)
@@ -118,7 +118,15 @@ CDirectory::CDirectory()
CDirectory::~CDirectory()
{}
-bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, CStdString strMask /*=""*/, bool bUseFileDirectories /* = true */, bool allowPrompting /* = false */, DIR_CACHE_TYPE cacheDirectory /* = DIR_CACHE_ONCE */, bool extFileInfo /* = true */, bool allowThreads /* = false */, bool getHidden /* = false */)
+bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, const CStdString &strMask /*=""*/, int flags /*=DIR_FLAG_DEFAULTS*/, bool allowThreads /* = false */)
+{
+ CHints hints;
+ hints.flags = flags;
+ hints.mask = strMask;
+ return GetDirectory(strPath, items, hints);
+}
+
+bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, const CHints &hints, bool allowThreads)
{
try
{
@@ -128,19 +136,16 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C
return false;
// check our cache for this path
- if (g_directoryCache.GetDirectory(strPath, items, cacheDirectory == DIR_CACHE_ALWAYS))
+ if (g_directoryCache.GetDirectory(strPath, items, (hints.flags & DIR_FLAG_READ_CACHE) == DIR_FLAG_READ_CACHE))
items.SetPath(strPath);
else
{
// need to clear the cache (in case the directory fetch fails)
// and (re)fetch the folder
- if (cacheDirectory != DIR_CACHE_NEVER)
+ if (hints.flags & DIR_FLAG_BYPASS_CACHE)
g_directoryCache.ClearDirectory(strPath);
- pDirectory->SetAllowPrompting(allowPrompting);
- pDirectory->SetCacheDirectory(cacheDirectory);
- pDirectory->SetUseFileDirectories(bUseFileDirectories);
- pDirectory->SetExtFileInfo(extFileInfo);
+ pDirectory->SetFlags(hints.flags);
bool result = false, cancel = false;
while (!result && !cancel)
@@ -187,19 +192,19 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C
}
// cache the directory, if necessary
- if (cacheDirectory != DIR_CACHE_NEVER)
+ if (hints.flags & DIR_FLAG_BYPASS_CACHE)
g_directoryCache.SetDirectory(strPath, items, pDirectory->GetCacheType(strPath));
}
// now filter for allowed files
- pDirectory->SetMask(strMask);
+ pDirectory->SetMask(hints.mask);
for (int i = 0; i < items.Size(); ++i)
{
CFileItemPtr item = items[i];
// TODO: we shouldn't be checking the gui setting here;
// callers should use getHidden instead
if ((!item->m_bIsFolder && !pDirectory->IsAllowed(item->GetPath())) ||
- (item->GetProperty("file:hidden").asBoolean() && !getHidden && !g_guiSettings.GetBool("filelists.showhidden")))
+ (item->GetProperty("file:hidden").asBoolean() && !(hints.flags & DIR_FLAG_GET_HIDDEN) && !g_guiSettings.GetBool("filelists.showhidden")))
{
items.Remove(i);
i--; // don't confuse loop
@@ -208,8 +213,8 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, C
// Should any of the files we read be treated as a directory?
// Disable for database folders, as they already contain the extracted items
- if (bUseFileDirectories && !items.IsMusicDb() && !items.IsVideoDb() && !items.IsSmartPlayList())
- FilterFileDirectories(items, strMask);
+ if (!(hints.flags & DIR_FLAG_NO_FILE_DIRS) && !items.IsMusicDb() && !items.IsVideoDb() && !items.IsSmartPlayList())
+ FilterFileDirectories(items, hints.mask);
return true;
}
@@ -34,15 +34,26 @@ class CDirectory
CDirectory(void);
virtual ~CDirectory(void);
+ class CHints
+ {
+ public:
+ CHints() : flags(DIR_FLAG_DEFAULTS)
+ {
+ };
+ CStdString mask;
+ int flags;
+ };
+
+ static bool GetDirectory(const CStdString& strPath
+ , CFileItemList &items
+ , const CStdString &strMask=""
+ , int flags=DIR_FLAG_DEFAULTS
+ , bool allowThreads=false);
+
static bool GetDirectory(const CStdString& strPath
- , CFileItemList &items
- , CStdString strMask=""
- , bool bUseFileDirectories=true
- , bool allowPrompting=false
- , DIR_CACHE_TYPE cacheDirectory=DIR_CACHE_ONCE
- , bool extFileInfo=true
- , bool allowThreads=false
- , bool getHidden=false);
+ , CFileItemList &items
+ , const CHints &hints
+ , bool allowThreads=false);
static bool Create(const CStdString& strPath);
static bool Exists(const CStdString& strPath);
@@ -222,7 +222,7 @@ void CDirectoryCache::InitCache(set<CStdString>& dirs)
{
const CStdString& strDir = *it;
CFileItemList items;
- CDirectory::GetDirectory(strDir, items, "", false);
+ CDirectory::GetDirectory(strDir, items, "", DIR_FLAG_NO_FILE_DIRS);
items.Clear();
}
}
@@ -33,10 +33,7 @@ using namespace XFILE;
IDirectory::IDirectory(void)
{
m_strFileMask = "";
- m_allowPrompting = false;
- m_cacheDirectory = DIR_CACHE_NEVER;
- m_useFileDirectories = false;
- m_extFileInfo = true;
+ m_flags = DIR_FLAG_DEFAULTS;
}
IDirectory::~IDirectory(void)
@@ -103,46 +100,12 @@ void IDirectory::SetMask(const CStdString& strMask)
}
/*!
- \brief Set whether the directory handlers can prompt the user.
- \param allowPrompting Set true to allow prompting to occur (default is false).
-
- Directory handlers should only prompt the user as a direct result of the
- users actions.
- */
-
-void IDirectory::SetAllowPrompting(bool allowPrompting)
-{
- m_allowPrompting = allowPrompting;
-}
-
-/*!
- \brief Set whether the directory should be cached by our directory cache.
- \param cacheDirectory Set DIR_CACHE_NEVER or DIR_CACHE_ALWAYS to enable or disable caching (default is DIR_CACHE_ONCE).
- */
-
-void IDirectory::SetCacheDirectory(DIR_CACHE_TYPE cacheDirectory)
-{
- m_cacheDirectory = cacheDirectory;
-}
-
-/*!
- \brief Set whether the directory should allow file directories.
- \param useFileDirectories Set true to enable file directories (default is true).
- */
-
-void IDirectory::SetUseFileDirectories(bool useFileDirectories)
-{
- m_useFileDirectories = useFileDirectories;
-}
-
-/*!
- \brief Set whether the GetDirectory call will retrieve extended file information (stat calls for example).
- \param extFileInfo Set true to enable extended file info (default is true).
+ \brief Set the flags for this directory handler.
+ \param flags - \sa XFILE::DIR_FLAG for a description.
*/
-
-void IDirectory::SetExtFileInfo(bool extFileInfo)
+void IDirectory::SetFlags(int flags)
{
- m_extFileInfo = extFileInfo;
+ m_flags = flags;
}
bool IDirectory::ProcessRequirements()
Oops, something went wrong.

0 comments on commit 426c1cf

Please sign in to comment.