Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getdirectory: Use flags rather than a bunch of bools #658

Merged
merged 3 commits into from Apr 6, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion xbmc/Application.cpp
Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions xbmc/FileItem.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down
20 changes: 11 additions & 9 deletions xbmc/Util.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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(".."))
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -2386,7 +2389,6 @@ void CUtil::ScanForExternalSubtitles(const CStdString& strMovie, std::vector<CSt
}
}
}
g_directoryCache.ClearDirectory(strLookInPaths[step]);
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/GUIDialogAddonInfo.cpp
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions xbmc/addons/GUIDialogAddonSettings.cpp
Expand Up @@ -916,9 +916,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)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/Skin.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogFileBrowser.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogMediaSource.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/AFPDirectory.cpp
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions xbmc/filesystem/AddonsDirectory.cpp
Expand Up @@ -40,8 +40,6 @@ namespace XFILE

CAddonsDirectory::CAddonsDirectory(void)
{
m_allowPrompting = true;
m_cacheDirectory = DIR_CACHE_ONCE;
}

CAddonsDirectory::~CAddonsDirectory(void)
Expand Down
29 changes: 17 additions & 12 deletions xbmc/filesystem/Directory.cpp
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
27 changes: 19 additions & 8 deletions xbmc/filesystem/Directory.h
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/filesystem/DirectoryCache.cpp
Expand Up @@ -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();
}
}
Expand Down
47 changes: 5 additions & 42 deletions xbmc/filesystem/IDirectory.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down