Skip to content

Commit

Permalink
FS|DirectoryFeed: Option to not populate native subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 24, 2016
1 parent 52be20e commit a992ee7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
13 changes: 10 additions & 3 deletions doomsday/sdk/libcore/include/de/filesys/directoryfeed.h
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_DIRECTORYFEED_H
Expand Down Expand Up @@ -53,7 +53,13 @@ class DENG2_PUBLIC DirectoryFeed : public Feed
AllowWrite = 0x1,

/// Creates the native directory if not does not exist.
CreateIfMissing = 0x2
CreateIfMissing = 0x2,

/// When populating the contents of the folder, descend to native
/// subfolders.
PopulateNativeSubfolders = 0x4,

OnlyThisFolder = 0,
};
Q_DECLARE_FLAGS(Flags, Flag)

Expand All @@ -64,7 +70,8 @@ class DENG2_PUBLIC DirectoryFeed : public Feed
* @param nativePath Path of the native directory.
* @param mode Feed mode.
*/
DirectoryFeed(NativePath const &nativePath, Flags const &mode = 0);
DirectoryFeed(NativePath const &nativePath,
Flags const &mode = PopulateNativeSubfolders);

virtual ~DirectoryFeed();

Expand Down
54 changes: 34 additions & 20 deletions doomsday/sdk/libcore/src/filesys/directoryfeed.cpp
Expand Up @@ -65,8 +65,12 @@ void DirectoryFeed::populate(Folder &folder)
}
QStringList nameFilters;
nameFilters << "*";
foreach(QFileInfo entry,
dir.entryInfoList(nameFilters, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot))
QDir::Filters dirFlags = QDir::Files | QDir::NoDotAndDotDot;
if(_mode.testFlag(PopulateNativeSubfolders))
{
dirFlags |= QDir::Dirs;
}
foreach(QFileInfo entry, dir.entryInfoList(nameFilters, dirFlags))
{
if(entry.isDir())
{
Expand Down Expand Up @@ -113,30 +117,40 @@ void DirectoryFeed::populateSubFolder(Folder &folder, String const &entryName)

void DirectoryFeed::populateFile(Folder &folder, String const &entryName)
{
if(folder.has(entryName))
try
{
// Already has an entry for this, skip it (wasn't pruned so it's OK).
return;
}
if(folder.has(entryName))
{
// Already has an entry for this, skip it (wasn't pruned so it's OK).
return;
}

NativePath entryPath = _nativePath / entryName;
NativePath entryPath = _nativePath / entryName;

// Open the native file.
std::unique_ptr<NativeFile> nativeFile(new NativeFile(entryName, entryPath));
nativeFile->setStatus(fileStatus(entryPath));
if(_mode & AllowWrite)
{
nativeFile->setMode(File::Write);
}
// Open the native file.
std::unique_ptr<NativeFile> nativeFile(new NativeFile(entryName, entryPath));
nativeFile->setStatus(fileStatus(entryPath));
if(_mode & AllowWrite)
{
nativeFile->setMode(File::Write);
}

File *file = folder.fileSystem().interpret(nativeFile.release());
folder.add(file);
File *file = folder.fileSystem().interpret(nativeFile.release());
folder.add(file);

// We will decide on pruning this.
file->setOriginFeed(this);
// We will decide on pruning this.
file->setOriginFeed(this);

// Include files in the main index.
folder.fileSystem().index(*file);
// Include files in the main index.
folder.fileSystem().index(*file);
}
catch(StatusError const &er)
{
LOG_WARNING("Error with \"%s\" in %s: %s")
<< entryName
<< folder.description()
<< er.asText();
}
}

bool DirectoryFeed::prune(File &file) const
Expand Down

0 comments on commit a992ee7

Please sign in to comment.