I digged through the API docs and found out, that it’s already supported:
static void setDelegate ( FileUtils * delegate )
static
You can inherit from platform dependent implementation of FileUtils, such as FileUtilsAndroid, and use this function to set delegate, then FileUtils will invoke delegate’s implementation.
Fox example, your resources are encrypted, so you need to decrypt it after reading data from resources, then you can implement all getXXX functions, and engine will invoke your own getXX functions when reading data of resources.
If you don’t want to system default implementation after setting delegate, you can just pass nullptr to this function.
Warning
It will delete previous delegate
The issue with this is, that a simple decryption hast to be implemented for every platform.
But isn’t that a typo?
If you don’t want to system default implementation after setting delegate, you can just pass nullptr to this function.
It should read:
If you want to use the system default implementation after setting delegate, you can just pass nullptr to this function.
Because it will create the platform specific instance, if the pointer is zero. E.g.: Apple:
FileUtils* FileUtils::getInstance()
{
if (s_sharedFileUtils == nullptr)
{
s_sharedFileUtils = new (std::nothrow) FileUtilsApple();
if(!s_sharedFileUtils->init())
{
delete s_sharedFileUtils;
s_sharedFileUtils = nullptr;
CCLOG("ERROR: Could not init CCFileUtilsApple");
}
}
return s_sharedFileUtils;
}