I'm current开发者_Go百科ly writing a program in C that needs to store configuration files, and various cache files on disk, as well as some static data files that never change, and that can safely be shared for all users.
I want to store these files in the appropriate location of the OS, in a portable way if possible…
For example, on GNU/Linux :
$XDG_CONFIG_HOME/<program_rame>/ -- for configuration files
$XDG_CACHE_HOME/<program_name>/ -- for cache files
$XDG_DATA_DIRS/<program_name>/ -- for static files
And, if these are unset, I can use the recommended default values ("~/.config", "~/.cache" and "/usr/share"). GNU/Linux is the easy one.
However, on Windows, I have no idea how to find the equivalent of these. I think it's going to be somewhere in AppData, but where ? And, most importantly, how do I get this programatically ? And what about other OSes (especially Mac OS, since most other UNIXes could use the "GNU/Linux" method as well) ?
I'm open to all solutions, whether it requires a library or not. Thanks in advance for your help !
Windows has so called known folder IDs, formerly (before Vista) known as special item IDs, or CSIDL. For instance in the folder referenced by FOLDERID_LocalAppData
(that is %USERPROFILE%\AppData\Local
) might be what you're looking for. I'm not on Windows and thus I don't know which C-API these values provide. However, chances are that these folders are also available as environment variables (e.g. %LOCALAPPDATA%
).
精彩评论