SFML community forums

General => Feature requests => Topic started by: AshleyF on June 13, 2017, 02:04:12 am

Title: Standardised cross-platform file access
Post by: AshleyF on June 13, 2017, 02:04:12 am
Dear Laurent and Associates,

Would it be possible to standardise cross-platform file access?

For instance, on the Mac:

// ... To get the path to these resources, use the helper
// function `resourcePath()` from ResourcePath.hpp

...

// Here is a small helper for you! Have a look.
#include "ResourcePath.hpp"

int main(int, char const**)
{
...
    if (!icon.loadFromFile(resourcePath() + "icon.png")) {
        return EXIT_FAILURE;
    }
...

As illustrated, an additional 'resourcePath() +' exists on Mac, which on PC, and I gather also Linux, doesn't.

If a solution could be devised, I'm quite sure cross-platform development would be even better.

Kind regards,

AshleyF
Title: Re: Standardised cross-platform file access
Post by: Hiura on June 14, 2017, 11:06:55 am
Generally speaking, go for standard filesystem API (http://en.cppreference.com/w/cpp/experimental/fs). With SFML we don't plan to reimplement this at all. If you C++ compiler/standard library don't support this yet, there are plenty of stable project doing just that in a correct way.

As for the `resourcePath` function, this one is really specific to Mac and application bundle. It is not clear how one should implement this function on Linux or Windows so that's why it's not part of SFML itself but "only" part of the Xcode template. The implementation for other OS is likely to depend on how you ship your application to your users so we cannot predict what it should look like. Thankfully, it's fairly trivial to do it for your project: you just need to define the function after all. ;-)