Skip to content

Commit

Permalink
libcore|FS: Refreshing the /packs folder
Browse files Browse the repository at this point in the history
Added a PackageLoader method for refreshing the /packs folder.
AssetObserver will now notify about asset changes synchronously
if the folder is being populated in the main thread.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent f83774c commit cd4bbb0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/filesys/packagefeed.h
Expand Up @@ -41,7 +41,7 @@ class DENG2_PUBLIC PackageFeed : public Feed
public:
PackageFeed(PackageLoader &loader, LinkMode linkMode = LinkIdentifier);

void setFilter(Filter filter);
void setFilter(const Filter &filter);

PackageLoader &loader();

Expand Down
8 changes: 8 additions & 0 deletions doomsday/libs/core/include/de/filesys/packageloader.h
Expand Up @@ -106,6 +106,14 @@ class DENG2_PUBLIC PackageLoader

void unloadAll();

/**
* Repopulate the /packs folder synchronously. The loaded packages are present as links
* under /packs, as are all the assets provided by the loaded packages.
*
* The /packs folder is not automatically refreshed after packages are loaded/unloaded.
*/
void refresh();

bool isLoaded(String const &packageId) const;

bool isLoaded(File const &file) const;
Expand Down
11 changes: 7 additions & 4 deletions doomsday/libs/core/src/filesys/assetobserver.cpp
Expand Up @@ -33,7 +33,6 @@ DENG2_PIMPL(AssetObserver)
, DENG2_OBSERVES(FileIndex, Removal)
{
const std::regex pattern;
LoopCallback mainCall;

static FileIndex const &linkIndex() {
return App::fileSystem().indexFor(DENG2_TYPE_NAME(LinkFile));
Expand All @@ -58,8 +57,8 @@ DENG2_PIMPL(AssetObserver)
// Only matching assets cause notifications.
if (!std::regex_match(link.name().toStdString(), pattern)) return;

String const ident = assetIdentifier(link);
mainCall.enqueue([this, ident] ()
const String ident = assetIdentifier(link);
Loop::mainCall([this, ident]()
{
DENG2_FOR_PUBLIC_AUDIENCE2(Availability, i)
{
Expand All @@ -73,10 +72,14 @@ DENG2_PIMPL(AssetObserver)
// Only matching assets cause notifications.
if (!std::regex_match(link.name().toStdString(), pattern)) return;

const String ident = assetIdentifier(link);
Loop::mainCall([this, ident]()
{
DENG2_FOR_PUBLIC_AUDIENCE2(Availability, i)
{
i->assetAvailabilityChanged(assetIdentifier(link), Removed);
i->assetAvailabilityChanged(ident, Removed);
}
});
}

DENG2_PIMPL_AUDIENCE(Availability)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/filesys/packagefeed.cpp
Expand Up @@ -95,7 +95,7 @@ PackageFeed::PackageFeed(PackageLoader &loader, LinkMode linkMode)
: d(new Impl(this, loader, linkMode))
{}

void PackageFeed::setFilter(Filter filter)
void PackageFeed::setFilter(const Filter &filter)
{
d->filter = filter;
}
Expand Down
6 changes: 6 additions & 0 deletions doomsday/libs/core/src/filesys/packageloader.cpp
Expand Up @@ -512,6 +512,12 @@ void PackageLoader::unloadAll()
}
}

void PackageLoader::refresh()
{
LOG_AS("PackageLoader");
FS::locate<Folder>("/packs").populate(Folder::PopulateOnlyThisFolder);
}

bool PackageLoader::isLoaded(String const &packageId) const
{
// Split ID, check version too if specified.
Expand Down

0 comments on commit cd4bbb0

Please sign in to comment.