macOS: search for data within .app bundle if not found besides app #7361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(this started as an issue, morphed into a discussion, but since I had super-circumscribed and functional code on hand to support the argument I went for the PR)
when bundling stuff with
OF_BUNDLE_DATA_FOLDER = 1
in macOS, things in there are not automatically found at runtime.this PR augments defaultDataPath() to check if there is a
../Resources/data/
if the usual one fails.NOTE: this means that a
data
directory besides an app will override one that would have been internally bundled -- it could lead to confusion if by coincidence a user has adata
folder besides the app. however there is also value to being able to conveniently override the internal data (less hassle than fishing in the package contents).maybe it should be the other way around? (bundled has precedence if it exists? no confusion possible) but then it means most of the times exceptions are triggered to fall back on the traditional external data. (maybe not dramatic as file access is generally not a hot spot?)
or maybe a compile-time #define would switch between cases based on if
OF_BUNDLE_DATA_FOLDER = 1
? so the app is built coherently for only one case? not sure what would be the pattern for that.BUT... maybe the real fix is to work at higher level and allow multiple data folders: not look for the existence of a
data
folder but the existence of the actual file within a list of potentialdata
folders (like the good old MaxMSP "search paths"). this would allow to have a bundled data for required ressources (ex: shaders, interface elements, etc), and an external data for user ressources (ex: movies). with a configurable list, a few places could be searched, like~/Documents/AppName/
to keep the app and data separated in some good practice manner (looking at iCloud)... also maybe bridgeofxiPhoneGetDocumentsDirectory()
(useful for file sharing) & al.it could be argued that a developper toggling
OF_BUNDLE_DATA_FOLDER = 1
is aware that the stuff will be elsewhere and could then be expected to callofSetDataPathRoot("../Resources/data/")
to fish the ressources there but it's an additional step to perform "consciously" (and it changes the default data path), and thinking about this at this point I find that (3) - (multiple data folders) is interesting as a general feature (but requires more design and work than the scope of this PR)SO: the current PR makes it so that a bundled data folder works transparently, with no impact on "normal" macOS apps (and a very slight risk of confusion for bundled apps users, which is much better than not working), holding the fort until a generalized multi-datapath strategy is implemented, if that is determined to be a good idea.
#changelog #osx