Dans quel répertoire écrire le jeu sauvegarder fichiers / données?

37

J'ai besoin d'une liste définie de répertoires, un ou plusieurs par plate-forme, indiquant où placer les fichiers de sauvegarde du jeu et les autres données générées . Soit sur la base de la spécification de développeur du système d'exploitation, soit parce qu'il s'agit d'une utilisation courante s'il n'y a pas de recommandation.

Veuillez fournir une réponse par plate - forme , avec des répertoires différents. En outre, il est préférable d’obtenir l’emplacement du répertoire en C ++ ou C , car c’est le langage dans lequel vous aurez plus de difficultés.

Emplacements:

  • Données de jeu du joueur (parties sauvegardées, configuration).
  • Données de jeu partagées (comme les meilleurs scores ou la configuration pour tous les utilisateurs de l'ordinateur).
  • Données de jeu temporaires (répertoire de cache).
Klaim
la source
1
You should probably put all answers into one, since there isn't a single answer to accept?
Zolomon
@Zolomon The problem is that one answer with all the platforms will be too big I think. In particular if you add mobile/tablet platforms...
Klaim
il est peut-être intéressant de noter (puisqu'il y a peut-être davantage de personnes partageant cette opinion) qu'au moins je déteste les jeux lorsque les jeux ne sont pas sauvegardés dans leurs répertoires respectueux (d'installation). J'aime les jeux où les utilisateurs du jeu sont créés dans le jeu, sans qu'il soit nécessaire de se cacher: les ordinateurs que j'utilise pour les jeux ne sont jamais suffisamment multi-utilisateurs pour utiliser les utilisateurs du système d'exploitation. Ou s'il doit l'utiliser, j'aime les jeux qui le font en interne. Peut-être pas le cas, mais: l'idée d'un utilisateur OS = un utilisateur de jeu alterego est également inquiétante. note je suis un joueur de windows. sur * unix c'est différent, le FS fixe force le concept (il n'y a pas de lecteurs)
n611x007
@naxa If that can "consolate" you, I'm making a game that have a players account management inside, but players account still have to be stored in user's account for OS security reasons. I might store them in shared repo too, not sure. Also, I'll need to allow users to keep data online at some point.
Klaim
3
@naxa The problem is that on Vista, Windows7, Windows8, unless specifically run as administrator, the programs wont be able to write to Program Files\Game-Install-Dir\. I believe this holds true on more recent Linux and OSX versions too.
Nate

Réponses:

23

Windows (Xp and following)

Based on:

These locations assume that Windows is installed on the C: disk. Append your own directory with game name or game company then game name to these directories.


If you use Window 8 Metro-style application, you'll have to use a specific API instead of trying to reach directories. Read:


Player's game data

Windows Vista et suivants:

C: \ Utilisateurs \ {nom d'utilisateur} \ AppData \ Roaming

Windows XP:

C: \ Documents and Settings \ {nom d'utilisateur} \ Données d'application

Vous pouvez automatiquement obtenir la bonne adresse dépendante du nom d'utilisateur en récupérant la APPDATAvariable d'environnement .

Standard C (tous les compilateurs):

char* appdata = getenv("APPDATA");

Visual Studio 20xx ( évitez que getenv () ne soit averti que ce n'est pas sûr ) - Style non métropolitain:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "APPDATA" ); 

Utilisateurs Boost : au moment où j'écris ce fichier boost.filesystem (c'est aussi un brouillon de la bibliothèque de système de fichiers proposée au prochain standard C ++) n'implémente pas encore une fonction pour fournir le bon répertoire. Cependant, il y a eu des discussions à ce sujet auparavant . N'hésitez pas à mettre à jour cette section si les choses ont changé.


Données de jeu partagées

Windows Vista et suivants:

C: \ ProgramData

Windows XP:

C: \ Documents and Settings \ Tous les utilisateurs

You can automatically get the right address by getting the PROGRAMDATA environment variable.

Standard C (all compilers):

char* appdata = getenv("PROGRAMDATA");

Visual Studio 20xx (avoid getenv() warning saying it's not safe) - non Metro Style:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "PROGRAMDATA" ); 

Boost users: at the moment I write this boost.filesystem (that is also a draft of the filesystem library proposed to the next C++ standard) doesn't implement yet a function to provide the right directory. However, there have been discussions about this before. Please feel free to update this section if things changed.


Temporary game data

Windows Vista and following:

C:\ProgramData

Windows Xp:

C:\Documents and Settings\{username}\Local Settings\Temp

You can automatically get the right address by getting the TEMP environment variable.

C++ Boost users: there is a simple cross-platform boost.filesystem function for this

namespace bfs = boost::filesystem;
const bfs::path TEMP_DIR = bfs::system_complete( bfs::temp_directory_path() ); // system_complete() call is optional

Standard C (all compilers):

char* appdata = getenv("TEMP");

Visual Studio 20xx (avoid getenv() warning saying it's not safe) - non Metro Style:

char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "TEMP" ); 
Klaim
la source
4
On Vista and up, game saves should preferable be placed in the special "Saved games" folder. More info here: msdn.microsoft.com/en-us/library/windows/desktop/… Look for "FOLDERID_SavedGames"
Durza007
1
You should never be trying to guess the path yourself or construct it from environment variables, really. On Vista and above, you should call SHGetKnownFolderPath (msdn.microsoft.com/en-us/library/bb762188.aspx) and on XP and below use SHGetFolderPath (msdn.microsoft.com/en-us/library/bb762181.aspx)
Kylotan
@Kylotan and Durza007, I'm a bit short on time, feel free to edit this answer as necessary. Made this answer community wiki.
Klaim
I think it's important to say that the msdn documentation suggests using SHGetKnownFolderPath since SHGetFolderPath is just a wrapper for the new method and is only supported for backward compatibility.
Kagemusha
16

MacOS

Based on:

In unix-based OS, the ~ directory is automatically located at the user's home directory where user-specific data are located. This means that whatever the language, on these platforms you can access automatically this folder by using ~ instead of using a OS-specific function. Also note that / is the root path of the whole system, not a path to the root of the main disk.

Append your own directory with game name or game company then game name to these directories.


Player's game data

Apple's guideline is to locate save and config files there to make them saved automatically in the cloud if available:

~/Documents

However, it is better (and more often used) practice to locate these files in:

~/Library/Application Support/

Just know that in this case the files will not be saved automatically to the cloud. If you want the player to choose, use the platform's API to make him choose.

Shared game data

/Library/Application Support

Notice that there is no ~, it's not relative to user's home but to system's root.

Temporary game data:

If the data don't need to be kept between executions:

/tmp

If the data need to be kept between executions;

/Library/Caches (for MacOSX)

C++ Boost users: there is a simple cross-platform boost.filesystem function for this

namespace bfs = boost::filesystem;
const bfs::path TEMP_DIR = bfs::system_complete( bfs::temp_directory_path() ); // system_complete() call is optional
Klaim
la source
4
Do not place anything in ~/Documents. That is for the user to choose to organize; you should never write to a fixed path inside Documents. Your game should use ~/Library/Application Support/Your App Name/ for saves and other user data.
Kevin Reid
@KevinReid "Documents that the user creates and sees in an app's user interface—for example the document browsers in Pages, Numbers, and Keynote should be stored in the Documents directory. Another example of files that might go in the Documents directory are saved games, again because they are something that an app could potentially provide some sort of method for selecting." -- Source: Apple's recommendation, in the first link. Did I miss something?
Klaim
2
In all of those the emphasis is on selecting. The user chooses what they are named and where they go. Files which the user does not manage should not be placed in Documents, because Documents is the user's namespace, not the developer's. (Disclaimer: I do not claim that my advice is in alignment with Apple's documentation. I do claim that it reflects the majority of practice among designed-for-Mac applications and that users will be happier with it.)
Kevin Reid
Also, there were no “Library” directories on pre-X Mac OS. The “(OS X)” remarks in the linked documentation are contrasting with iOS, which is a completely different question since iOS does not expose a filesystem to the user.
Kevin Reid
@KevinReid I'll update the Library stuff, thanks. However for what you say about selecting and Documents, this seems contradictory. Save games are user-relative, not application or developer relative. Well it depends on the game, which is why there is also a shared game data directory. So I don't understand what you mean exactly. Is there some rational somewhere about that?
Klaim
13

Linux Debian (Ubuntu, Fedora, etc.)

Based on:

In unix-based OS, the ~ directory is automatically located at the user's home directory where user-specific data are located. This means that whatever the language, on these platforms you can access automatically this folder by using ~ instead of using a OS-specific function. Also note that / is the root path of the whole system, not a path to the root of the main disk.

Ajoutez votre propre répertoire avec le nom du jeu ou la société du jeu, puis le nom du jeu à ces répertoires.


Données de jeu du joueur

Traditionnellement, pour le jeu Aquaria, ce serait:

~ / .aquaria

Notez que les répertoires et les fichiers commençant par . will be hidden by default to the user.

La plupart des ordinateurs de bureau essaient maintenant de se conformer à la spécification XDG , qui recommande

$ XDG_CONFIG_HOME / aquaria

ou

$ XDG_DATA_HOME / aquaria

pour la configuration et les sauvegardes à la place.

Si $XDG_CONFIG_HOMEnon défini utiliser:

~ / .config / aquaria

ou

~ / .local / aquaria

Cela consiste principalement à désencombrer le répertoire de base de l'utilisateur et à permettre aux utilisateurs d'exécuter plusieurs profils d'une application s'ils le jugent nécessaire. Il existe également d'autres répertoires dédiés spécifiques à l'utilisateur dans la spécification.

Données de jeu partagées

/ var / jeux /

Shared config files should be located in

/etc/games/

Temporary game data

/tmp

Klaim
la source
1
To elaborate: a game "Aquaria" should put its game data in ~/.aquaria (or ~/.config/Aquaria). It's frowned upon to have a world-writable directory in /var; the general way of making that happen is to create a user account for your game and make it the only account that can write to that directory (and then use setuid when normal people are playing the game). This might be more work than you want.
dhasenan
Well, actually, most desktops now try to adhere to the XDG specification, which recommends $XDG_CONFIG_HOME/aquaria (or ~/.config/aquaria if not set) and $XDG_DATA_HOME/aquaria (or ~/.local/aquaria) for configuration and savegames instead (see standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). This is mostly to unclutter user's home directory, as well as allow users to run multiple profiles of an application if they deem it necessary. There are also other dedicated user-specific directories in the specification.
liori
@liori I'll update the answers tomorrow if I can find time, sorry for the delay. If you feel like it and have the time, please feel free to update the info. It's useful to me too.
Klaim