macOS: search for data within .app bundle if not found besides app#7361
macOS: search for data within .app bundle if not found besides app#7361artificiel wants to merge 1 commit intoopenframeworks:masterfrom
Conversation
|
Hey @artificiel check it out this conversation here chalet-org/chalet#231 |
|
ah! chalet, interesting, @rewrking puts the finger on the same lines of code this PR is about, so yes, this would fix that chalet problem (if it's still a problem). it does reinforce the case for multiple paths, as indeed "required ressources" like shaders are not the same as "user ressources" like assets. (although i've seen very few apps that offer an "asset management experience" in terms of end-user-facing interface, this would ease the way towards it (and an appstore distributed-app has a kind of implicit "real" end-user in mind (vs the developer-users-working-on-a-single-instance-of-a-project we mostly are)). and to confirm: yes: "Contents/resources" is the right place: the build phase correctly uses
to which the Xcode script appends so there is a bit of untangling of scenarios to be had about "end end user" vs "C++ interface user" design, but i still think that (a) this PR is immediately useful as it simplifies the developer-user's life ( |
|
+1 for this change |
|
@Artificel finally filesystem PR is merged #7110 Please take a look if you have the time. |
|
great! |
|
covered by #7368 |
(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 = 1in 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
datadirectory besides an app will override one that would have been internally bundled -- it could lead to confusion if by coincidence a user has adatafolder 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
datafolder but the existence of the actual file within a list of potentialdatafolders (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 = 1is 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