Platform folders
4.0.0
|
A C++ library to look for directories like My Documents
, ~/.config
, APPDATA%
, etc. so that you do not need to write platform-specific code
Source code • Latest release (4.0.0) • Doxygen documentation
There are a lot of platform abstraction libraries available. You can get graphics abstraction libraries, GUI abstraction libraries and file abstraction libraries.
But folder abstraction seems to be more difficult. My problem was that the code that found the place to save data was platform dependent. This cluttered my code and often I would not discover that it did not compile until moving it to the different platforms.
I have written a bit more about it here.
There are some alternatives that you might consider instead:
Both are properly more mature than this library. However they are both parts of large frameworks and using them with libraries outside the framework may not be that simple.
For Windows, the current version fetches the folders using SHGetKnownFolderPath. This requires Vista or newer.
This library uses the XDG user-dirs.
It should work on any Unix system that has the following headers available: pwd.h
, unistd.h
, and sys/types.h
Version 4.0.0 and forward uses hardcoded values for the directories on Mac OS X. Unlike the other operating systems the folders cannot be moved on a Mac and the translation is done in the UI. The versions 2.X and 3.X uses the deprecated FSFindFolder, which requires the CoreServices framework during linking. Version 1.X simple used the XDG specification.
This project should be compatible with things like Cmake's ExternalProject_Add if you wish to use it in your project.
You can also follow the build step below to install at a system level, and use Cmake's find_package.
Alternatively, you can just copy the sago folder into your program and manually link everything. If you use the last option and are using a library version from before 4.0.0: Remember to link to the CoreServices lib when compiling on Mac. This typically means passing "-framework CoreServices" during the linking phase.
Note that if you build in-tree, you can link against the Cmake alias sago::platform_folders
just like if you had used find_package.
Notes:
--target install
command.Linux/macOS:
Windows:
This sample program gets all folders from the system:
Versions up to 3.X.X should compile with any C++98 compiler.\ Versions from 4.0.0 and up require a C++11 compatible compiler.
The aim is to always support the default C++ compiler on the oldest supported version of Ubuntu. This is a very basic library and it is not supposed to force you to upgrade.
From version 3.0, Windows always encodes to UTF-8, and this will be the default on almost any other system. Before version 3.0, Windows was encoded in ANSI. Although the user may use any characters they want, I recommend that the program should have only ASCII characters in the source code itself.
Provided under the MIT license for the same reason XDG is licensed under it. So that you can quickly copy-paste the methods you need or just include the "sago"-folder.