Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/file/vfs/vfs_populate.cpp
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | Status vfs_Populate(VfsDirectory* directory) | ||||
RETURN_STATUS_IF_ERR(helper.AddEntries()); | RETURN_STATUS_IF_ERR(helper.AddEntries()); | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
Status vfs_Attach(VfsDirectory* directory, const PRealDirectory& realDirectory) | Status vfs_Attach(VfsDirectory* directory, const PRealDirectory& realDirectory) | ||||
{ | { | ||||
PRealDirectory existingRealDir = directory->AssociatedDirectory(); | |||||
// Don't allow replacing the real directory by a lower-priority one. | |||||
if (!existingRealDir || existingRealDir->Priority() < realDirectory->Priority()) | |||||
{ | |||||
// This ordering is peculiar but useful, as it "defers" the population call. | |||||
// If there is already a real directory, we will replace it (and lose track of it), | |||||
// so we'll populate it right away, but the 'new' real directory can wait until we access it. | |||||
RETURN_STATUS_IF_ERR(vfs_Populate(directory)); | RETURN_STATUS_IF_ERR(vfs_Populate(directory)); | ||||
directory->SetAssociatedDirectory(realDirectory); | directory->SetAssociatedDirectory(realDirectory); | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
// We are attaching a lower-priority real directory. | |||||
// Because of deferred population, we need to immediately populate this new directory. | |||||
bool shouldPop = directory->ShouldPopulate(); | |||||
// This sets "should populate" to true, so the vfs_Populate call below immediately populates. | |||||
directory->SetAssociatedDirectory(realDirectory); | |||||
RETURN_STATUS_IF_ERR(vfs_Populate(directory)); | |||||
// Reset to the higher priority realDirectory, which resets ShouldPopulate to true. | |||||
directory->SetAssociatedDirectory(existingRealDir); | |||||
// Avoid un-necessary repopulation by clearing the flag. | |||||
if (!shouldPop) | |||||
directory->ShouldPopulate(); | |||||
return INFO::OK; | |||||
} |
Wildfire Games · Phabricator