Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Facility to get standard paths  (Read 18692 times)

0 Members and 1 Guest are viewing this topic.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Facility to get standard paths
« on: January 08, 2015, 08:16:09 pm »
Currently there is no way for the user to retrieve the paths of standard locations in a cross-platform way.

One can check the environment variables using std::getenv() but often times you wouldn't be able to use their values directly without a bit more information about the target system.

As an example: On Linux systems, it might be typical to store user data in the HOME location, on Windows, there is also a HOME path, but that is not where user data is usually stored (APPDATA is used for this).

If an SFML application is installed by a user with administrative privileges and is to be used by unprivileged users, there would be no place to store per-user data since the binary directory would be read-only.

Other examples of useful paths might be: The current working directory, a directory where temporary data can be stored, the location where fonts are installed (yes... currently if you wanted to use installed fonts you would have a lot of pre-processor in your code).
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Facility to get standard paths
« Reply #1 on: January 08, 2015, 08:32:03 pm »
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #2 on: January 08, 2015, 08:48:31 pm »
Something that partially answers your needs, old but still working I guess: http://websvn.tuxfamily.org/filedetails.php?repname=hblog%2Fsvn&path=%2Fcpd%2Ftrunk%2Fcpd.hpp
SFML / OS X developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #3 on: January 08, 2015, 08:50:51 pm »
Awesome, I always assumed this was out of SFML's scope.

Could we also consider the executable directory? The current working directory isn't that great for (portably and reliably) loading resources, which is what most basic SFML programs need the filesystem for.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #4 on: January 08, 2015, 08:58:42 pm »
Loading resources is a complex issue: some OSes expect a specific kind of file hierarchy (e.g. OS X with bundled application, Linux with standard paths, mobiles OSes with sandboxing, ...). Then you have a different directory whereto save config, and another one to store temporary data... Before we commit to provide such functionality, as Qt does, let's make sure we understand what's at stake.  ;)
SFML / OS X developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #5 on: January 08, 2015, 09:50:42 pm »
Currently there is no way for the user to retrieve the paths of standard locations in a cross-platform way.
I agree. This is actually a fairly common need. I've had to implement things like this for various personal and work related, cross platform, projects multiple times - it would be nice if the SFML system module provided some of the basic stuff.

One can check the environment variables using std::getenv() but often times you wouldn't be able to use their values directly without a bit more information about the target system.
Environment variables contain a lot of useful information, but even on POSIX systems what is available and what they contain differs. As you say, it is essential to know what system you are on before using them. Some could probably be used in OS specific implementation of SFML functions though.

Other examples of useful paths might be: The current working directory,
Yes, the current working directory is useful, but is also one of the easier ones that might not necessarily need a SFML wrapper (although it might be convenient) since I believe all supported platforms (even Windows) supports the getcwd() function. But GetCurrentDirectory() might be a better choice on Windows, so yeah, maybe it ought to be wrapped.

a directory where temporary data can be stored,
Doesn't getenv("TMP") get you this on all supported platforms? I know Windows prefers TEMP, but it still sets/supports TMP as well IIRC.
But yes, I agree, a useful path for apps to know regardless of how SFML obtains it.

the location where fonts are installed (yes... currently if you wanted to use installed fonts you would have a lot of pre-processor in your code).
Certainly also useful.

Another path that may be useful to an application that we could consider providing is the path to the executable currently running. That's often useful to find resources located in a directory relative to your executable; On Linux (and Android I'd assume) you'd read the target of the /proc/self/exe symlink, on Windows you'd call GetModuleFileName(), on OS X _NSGetExecutablePath() gets the job done, FreeBSD has a sysctl for the purpose etc etc - all systems provide a way to get the path but they are all different which makes this an obvious candidate for something SFML could provide.
« Last Edit: January 08, 2015, 09:55:22 pm by Jesper Juhl »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Facility to get standard paths
« Reply #6 on: January 08, 2015, 09:54:07 pm »
Quote
Awesome, I always assumed this was out of SFML's scope.
As a multimedia library, SFML deals with resources, and resources needs paths. It's more and more important these days where everything is properly categorized and dispatched on OSes ("everything in the app directory" is an old pattern), especially on mobile systems where you cannot even work at all in the executable's directory.

Quote
Could we also consider the executable directory?
Why not.
Laurent Gomila - SFML developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #7 on: August 06, 2015, 06:47:12 pm »
This topic is getting a bit old, but if there is still interest in this I could cook up a proof-of-concept implementation for (at least) Linux and Windows for this and we could then continue discussions from there??

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Facility to get standard paths
« Reply #8 on: August 06, 2015, 07:09:41 pm »
I'm still interested. ;)

With a real implementation we might actually see the pros and cons of the API more clearly.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Facility to get standard paths
« Reply #9 on: August 06, 2015, 07:12:09 pm »
OK. I'll try to cook up something over the weekend/start of next week.

Arvamer

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Facility to get standard paths
« Reply #10 on: August 06, 2015, 10:35:29 pm »


As an example: On Linux systems, it might be typical to store user data in the HOME location,

But please use $XDG_DATA_HOME or if not set, $HOME/.local/share. Every Linux gamer say this :).


SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: Facility to get standard paths
« Reply #11 on: August 27, 2015, 12:42:51 pm »
As I ran into an issue with this recently I also support this request, it would be more convinient to have a SFML API for the basic directory stuff. And an additional useful feature would be to get the system time in a plattform independent SFML API, as I plan on displaying the actual system time ingame (like Diablo 3 e.g. just informational).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Facility to get standard paths
« Reply #12 on: August 27, 2015, 01:24:39 pm »
Quote
And an additional useful feature would be to get the system time in a plattform independent SFML API
No need, you can already do that with the standard library.
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Facility to get standard paths
« Reply #13 on: August 27, 2015, 01:28:29 pm »
I'd like it if SFML could handle files better too. Not sure if it's in its scope but maybe it should slightly expand its scope to allow for this because of how important it really is  ;)

an additional useful feature would be to get the system time in a plattform independent...
I did a really basic version of something like this here. It uses <chrono> but doesn't take into account fluxuations such as time offsets (Summer Time, for example).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Facility to get standard paths
« Reply #14 on: August 27, 2015, 02:44:04 pm »
Let's stay focused on the topic, ie. standard paths ;)
Laurent Gomila - SFML developer