-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ofToDataPath simplification #7368
base: master
Are you sure you want to change the base?
Conversation
my angle on why multiple roots? the case of the .app bundle is one (that could be solved in different ways) but I see value for a system that searches for resources in different places, either automatically (OS-sanctioned areas, however to do that it means that there is already a bit of confusion, for instance: openFrameworks/addons/ofxSvg/src/ofxSvg.cpp Lines 32 to 52 in f71884f
where I'm heading is that if (auto concrete_file = ofConcreteDataPath(fileName)) {
auto buffer = ofBufferFromFile(concrete_file);
if (loadFromString(buffer.getText(), concrete_file)) isLoaded = true;
// NB optional adopts pointer operator so perhaps needed here or adapted further in
}
//else {
// fileName was not found in any dataPaths...
// but local code does not need to deal with path existence (good separation!)
// (a "file not found" warning would already be emitted within ofConcreteDataPath())
// nevertheless, if something meaningful has to happen here the nullopt `else` branch works
//} note that that's actually independent of searching into multiple places... sorry for not being totally structured! so (a) make ofToDataPath poly-directory and (b) make ofToDataPath confirm paths. and note that @arturoc mentions overhauling return types here #4998 (comment) where std:expected would work fine, so maybe we skip optional altogether (it's so pre-pandemic anyway) and head straight into expected? (am I scaring you enough yet?) (note that |
I totally agree with your view. maybe a vector of fs::path to look for, for all platforms, and macos has two paths already initialized. |
I will not be able to read carefully today, but one issue that has to be addressed is what happens when you construct a path for writing (as So there needs to be a "deterministic" dataPath that is used to write to. If this idea of multidatapath is to go somewhere, maybe the data paths need to be qualified in some way? brainstorm: also I had this on my reading list specifically around #1523 (comment) as evidently considerable work is into ofToDataPath et al. and whatever "upgrade" to the interface has to be carefully designed. and as far as the error checking, I think it is important to clearly define which step is responsible for the file existence or writability (I argue it is not the app or addon writer's responsibly), and from there look a a few concrete scenarios to test properly how a design would work in actual use. (I was a bit kidding about std::expected as a "valid path or nullopt" is exactly a use case for std::optional). [edit to add]: and in the case of an unfound file it is more a matter of handling a minor "disappointment" than an actuall "error" and should be processed as such. |
Thanks. I'll be reading carefully your comments later. Just a quick note: I don't think Poco::path should be used now we have fs. I appreciate you think some steps ahead. Anyway just to think of "here and now" I would like your opinion on this PR as it is, compared to the master code, if you see any downside on this change. |
oh no don't worry I'm not advocating poco at all! (that thread is from 2012) just pointing out the specific comment indicating there are tricky aspects to "low level" aspect |
I was starting to go through the specific changes and was quickly "drifting out" towards "thinking steps ahead"... ex: the section about finding the data/ folder in bundled macOS apps, I'm not sure which should be the default: checking first ../../.. means a user placing a bundled macOS app besides a folder name so what I mean is as far as "review" goes it helps to have specific goal or problems to check, so:
also line 386 of ofCubemap.cpp, going from:
to
is the perfect example of why |
Great, thanks @Artificel ofSetDataPathToBundle(); // horrible name |
about the tests of this PR. |
this approach is not ideal as the fact that the app is bundled might be a "later" decision. if you write hence the discussion about multiple dataPaths and ways of hinting/distinguishing them. maybe multiple data paths as free "search paths" is not the correct idea, and something like (I would also jot here not to forget the case of a multi-user linux system with a common (and while we're taking about dataPath I cannot also omit my reflection of making the function a validator of the given path, hence |
to complete the above: shader.load("dude"); // must be found in bundle
ofLoadImage("test_pattern.png"); // must be found in bundle
ofSaveImage("capture.png"); // cannot save within bundle -- automatic deduction of writable place?
ofLoadImage("capture.png"); // must be found either in or out of bundle!
// hence my initial "search path" idea" which is the transparentest or: shader.load(ofResourceData("dude"));
ofSaveImage(ofUserData("capture.png"));
ofLoadImage(ofUserData("capture.png"));
ofLoadImage("capture.png"); // defaults to user-space
|
Lots of deep insights here. Thanks @Artificel. Do you think code in this PR has equivalent functionality of openframeworks:master? |
yes! for the macOS bundle part, this is a good first step (i.e. it's not perfect but you can now bundle an app and have it running (combined with #7358 you can even copy it around with custom dylibs -- I'm doing just that)). for the general dataPath simplification, if the tests are good I don't see a problem but I'll let some other eyes with more experience with that code confirm. |
Great! I'm hoping #7358 get merged soon and I love the idea of separating the script |
outputPath = relativeDirDataPath / inputPath; | ||
} | ||
if (makeAbsolute) { | ||
outPath = dataPath / path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be an edge case here if you pass in an absolute path and makeAbsolute
is true.
ie: path is /Users/me/Desktop/image.jpg
if makeAbsolute is true and the path is already absolute then it would prepend dataPath ie: /Users/me/Downloads/OF/apps/myApp/bin/data/Users/Theo/Desktop/image.jpg
does this edge case exist in the original code? looks like it might?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I'll be investigating this better now
libs/openFrameworks/gl/ofCubeMap.cpp
Outdated
@@ -383,30 +383,33 @@ bool ofCubeMap::load( ofCubeMapSettings aSettings ) { | |||
// figure out the number of mip maps // | |||
data->maxMipLevels = log2(data->settings.preFilterRes) + 1; | |||
|
|||
std::string encFolder = data->settings.cacheDirectory; | |||
of::filesystem::path encFolder = data->settings.cacheDirectory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should prob be in another PR but fine for this one.
Maybe we should start using auto
instead of of::filesystem::path
for local vars going forward as it will make the code more adaptable in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes +1 for auto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this specific one should not be auto, because data->settings.cacheDirectory is a string, so I'm building an of::filesystem::path from that.
@dimitre Seems like a few of the tests are failing on Linux too: I think to merge this we should try and get it to pass the tests as is, as some of the small differences could cause real world issues. |
Yes, I think there is more to it, and I am investigating the issue now |
ofToDataPath can now be hugely simplified using filesystem functions.