I recently made this nice filebrowser that is preloading pictures and models by users choice.
Each time the user is changing the folder
is called. T is the filepath coming from a listbox entry the user has clicked on.
This procedure is filling up the “locations” registered in the assetmanager.
There is an AssetManager().unregisterLocator(XXX); option and I have seen, that all the locations are stored in an assetManager → handler → locatorList
How can I access the already registered locations?
Is there an option like AssetManager().unregisterLocator(everything) ?
Don’t register a locator for every absolute filepath. The locators act as a “root directory”, or a starting point for your asset. If the user is searching for assets on their filesystem then add the drive letter to the file locator once and be done.
Another option would be using the assetManager.loadAssetFromStream, which you can then just hand file streams to instead of trying to figure out the best “root folder” for an asset locator.
There is only one path registered by default; the resources folder. The only others added are by yourself, so just keep track of them when you add and remove them.
Don’t remove the first resources folder or nothing will work, like your gui, fonts, etc.
Both of you have good solutions.
As I register each time before I load a picture/model I could remove it directly after that (solution of @jayfella).
I like the solution of @QSDragon as well and will refactor my code in this way. I think using the rootpath as starting point is smart, as the link/URL is given by the listbox and it would only need a bit of String operations.
I have no idea about the loadAssetfromStream but will read about it.
Thanks for the input.
As a person of high experience with servers and security I definitely do not advocate blanket ruling a storage device like that. In some instances you won’t even be allowed. You should most certainly reduce the scope to the directory or parent directory, or even a pre defined “home”.