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

Author Topic: File system  (Read 8447 times)

0 Members and 1 Guest are viewing this topic.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
File system
« on: January 11, 2017, 05:39:34 am »
Can we please have some file system features?
I wish I didn't had to add boost::filesystem as a dependency, it's so janky.
Start small, no need for directory iteration, but a sf::getAppPath() to get the application data directory would be nice.

I haven't used it, but it looks like SDL does just that with char* SDL_GetBasePath(void).

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: File system
« Reply #1 on: January 11, 2017, 06:31:48 am »
C++17 will have a file system library, so I guess it's not worth starting to develop yet another one in SFML ;)
Laurent Gomila - SFML developer

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: File system
« Reply #2 on: January 11, 2017, 07:10:09 am »
C++17 filesystem is already supported well by recent compilers.  ;)

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: File system
« Reply #3 on: January 11, 2017, 02:33:58 pm »
Nice! That's life changing actually. Thanks for letting me know!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: File system
« Reply #4 on: January 11, 2017, 08:09:13 pm »
I'd say that a normal filesystem API is not a good fit for a game since in vast majority of games you don't go beyond own folders, care about rest of the OS, etc.
That's why I like physfs so much: https://www.icculus.org/physfs/
It's prefect for games with it's mount points and using archives.
I guess you could write similar system using any API but what for if this exists and is so well tested?
SFML could probably wrap it but there isn't really a point IMO, it's easy to use as is, it's just a few calls.
Back to C++ gamedev with SFML in May 2023

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: File system
« Reply #5 on: January 21, 2017, 05:27:36 am »
I'd say that a normal filesystem API is not a good fit for a game since in vast majority of games you don't go beyond own folders, care about rest of the OS, etc.

Almost all games need to read and write save files, configuration/setting files (e.g. user-set graphics options or keyboard mappings), often write logs, often write screenshots, etc.  And these need to go in the appropriate places (outside of the game's own folders) for a bunch of reasons, most notably because game files are often installed into read-only directories.


FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: File system
« Reply #6 on: January 21, 2017, 03:21:18 pm »
Well, then this folder where you store that is one of your 'own folders' too. You can set your write folder to somewhere in %appdata% or wherever and then also add that path to search path to read configs from it first so your default ones in game directory are shadowed by them. You still don't need to go wild traveling around the entire filesystem, bother with system specific stuff (except at launch) and so on.

PHYSFS has even a shortcut for a similar(ish) config: https://www.icculus.org/physfs/docs/html/physfs_8h.html#afef8700f714b6800ff688372c540bfe2

But if you want to shotgun files all over the place like put configs in home, screenshot in Pictures, etc. then I can't get behind that, that'd be so annoying to me as a user/player to find, delete or use.

And it's not like going out of your install directory is some golden standard anyway (I've seen Minecraft do it.. and I've had mixed feelings about it, my %appdata% and Windows are on C and my games are on D, so I don't want my games taking up space on my precious lightning fast SSD just because someone assumed something).

I've also seen many small games that you just unzip and they don't do anything anywhere except their own folder and I really like that because more than once I had a game break itself and I had to delete and unzip it again because config got corrupt or something. It's the 0 bother approach to me to use, dig into files out of interest, delete them, move them to another PC, etc. Steam also has games save into their own directory somewhere in SteamLibrary/steamapps/common or so. Many installed games do it too.
Back to C++ gamedev with SFML in May 2023

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: File system
« Reply #7 on: January 22, 2017, 03:48:39 pm »
I'm with you FRex that games most often should just use one writable directory outside of the install directory.  But the install directory is very often non-writable.  And depending on how you distribute your game (e.g. most major digital distributors), you don't have control of where the install directory is.  So you do need to query the OS on an appropriate writeable directory.  If PHYSFS handles this, then great! 

Sure, with a zip file installation, anything goes.  But that isn't appropriate for any commercial games or applications these days.  Again, especially if you're selling it through a digital distributor like Steam.

Steam also has games save into their own directory somewhere in SteamLibrary/steamapps/common or so. Many installed games do it too.

I think you may be mistaken about this.  Steam, on Windows, by default, installs its games inside the Program Files (x86) directory.  Which is non-writeable.  Any game which tried to save files here would fail.  I think Steam on linux has a similar setup, but I can't remember for sure.

Most of my steam games seem to write their writeable game files inside of the Documents directory or AppData directory.
« Last Edit: January 22, 2017, 04:06:26 pm by Jabberwocky »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: File system
« Reply #8 on: January 22, 2017, 06:33:37 pm »
Quote
If PHYSFS handles this, then great!
It can find User dir and that's all. But I'm extremely against using that. Not only is it annoying (see below) but it's also more dangerous. I don't want someone's coding mistake to wipe out my Documents or %appdata% (and it's not like indies games are all made by geniuses who don't make mistakes).


Quote
Sure, with a zip file installation, anything goes.  But that isn't appropriate for any commercial games or applications these days.
I really don't see why not, it's faster, easier and less dangerous. I can't imagine a sane person that is outside of mainstream crowd enough to buy indies be like "Oh, I won't play this game I bought because I hate that I must click once and unzip, something that any windows since XP can do, instead of double clicking an installator exe and clicking next 5 times" and then not play the game. I can imagine however someone being pissed when something breaks and is impossible (or uses some arcane registry digging or looking around in random spots for files) to fix.

Registry and config leftovers cleaning is its own science by now on Windows. I just found leftover of klei config in my Documents folder, on my C, despite telling steam to always use my D. That's just stupid. Now imagine it was broken or (god forbid) broken AND in registry under some idiotic name that I could never figure out. Reinstalling the game should give a clean slate, not create some quasi fresh state where saves and configs may or may not be present from the last installation. Some games (Killing Floor has cache, CaveStory+ has logs) seem to write to the steam library folder so I have no idea what's up with that.

People who play indie games got used to zips I'd say. On gamejolt the few games I've played came in plain zips (and I hope they don't sneakily write their files somewhere or crap into my registry...). If I ever get to distribute a game again it will be a zip and that's it. It's not worth the effort in my opinion to figure out the 'proper' directories to save stuff to, create an installer that just looks professional but does nothing special, etc.
Back to C++ gamedev with SFML in May 2023