git repos / blockattack-game

blame: source/misc/embedded_libs/PlatformFolders-4.2.0/README.md

normal view · raw

c74066db Poul Sander 2022-02-16 12:14 1
# PlatformFolders [![Build Status](https://travis-ci.org/sago007/PlatformFolders.svg?branch=master)](https://travis-ci.org/sago007/PlatformFolders) [![AppVeyor](https://img.shields.io/appveyor/ci/sago007/PlatformFolders.svg?label=Windows)](https://ci.appveyor.com/project/sago007/platformfolders) [![license](https://img.shields.io/github/license/sago007/PlatformFolders.svg)](https://raw.githubusercontent.com/sago007/PlatformFolders/master/LICENSE) [![Join the chat at https://gitter.im/PlatformFolders/Lobby](https://badges.gitter.im/PlatformFolders/Lobby.svg)](https://gitter.im/PlatformFolders/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/729e36adcf5c4523bd136de1b33441cb)](https://www.codacy.com/app/github_43/PlatformFolders?utm_source=github.com&utm_medium=referral&utm_content=sago007/PlatformFolders&utm_campaign=Badge_Grade)
c74066db Poul Sander 2022-02-16 12:14 2
c74066db Poul Sander 2022-02-16 12:14 3
A C++ library to look for directories like `My Documents`, `~/.config`, `%APPDATA%`, etc. so that you do not need to write platform-specific code
c74066db Poul Sander 2022-02-16 12:14 4
c74066db Poul Sander 2022-02-16 12:14 5
[Source code](https://github.com/sago007/PlatformFolders) • [Latest release](https://github.com/sago007/PlatformFolders/releases/latest) • [Doxygen documentation](https://sago007.github.io/PlatformFolders/html/doxygen/)
c74066db Poul Sander 2022-02-16 12:14 6
c74066db Poul Sander 2022-02-16 12:14 7
## Rationale
c74066db Poul Sander 2022-02-16 12:14 8
c74066db Poul Sander 2022-02-16 12:14 9
There are a lot of platform abstraction libraries available. You can get graphics abstraction libraries, GUI abstraction libraries and file abstraction libraries.
c74066db Poul Sander 2022-02-16 12:14 10
c74066db Poul Sander 2022-02-16 12:14 11
But folder abstraction seems to be more difficult.
c74066db Poul Sander 2022-02-16 12:14 12
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.
c74066db Poul Sander 2022-02-16 12:14 13
c74066db Poul Sander 2022-02-16 12:14 14
[I have written a bit more about it here.](https://sago007.blogspot.dk/2015/10/abstraction-for-special-folders.html)
c74066db Poul Sander 2022-02-16 12:14 15
c74066db Poul Sander 2022-02-16 12:14 16
There are some alternatives that you might consider instead:
c74066db Poul Sander 2022-02-16 12:14 17
c74066db Poul Sander 2022-02-16 12:14 18
* [QStandardPaths](https://doc.qt.io/qt-5/qstandardpaths.html)
c74066db Poul Sander 2022-02-16 12:14 19
* [glib](https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html)
c74066db Poul Sander 2022-02-16 12:14 20
c74066db Poul Sander 2022-02-16 12:14 21
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.
c74066db Poul Sander 2022-02-16 12:14 22
c74066db Poul Sander 2022-02-16 12:14 23
## Operating System Support
c74066db Poul Sander 2022-02-16 12:14 24
c74066db Poul Sander 2022-02-16 12:14 25
### Windows
c74066db Poul Sander 2022-02-16 12:14 26
c74066db Poul Sander 2022-02-16 12:14 27
For Windows, the current version fetches the folders using SHGetKnownFolderPath. This requires Vista or newer.
c74066db Poul Sander 2022-02-16 12:14 28
c74066db Poul Sander 2022-02-16 12:14 29
### Linux
c74066db Poul Sander 2022-02-16 12:14 30
c74066db Poul Sander 2022-02-16 12:14 31
This library uses the [XDG user-dirs.](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
c74066db Poul Sander 2022-02-16 12:14 32
c74066db Poul Sander 2022-02-16 12:14 33
It should work on any Unix system that has the following headers available: `pwd.h`, `unistd.h`, and `sys/types.h`
c74066db Poul Sander 2022-02-16 12:14 34
c74066db Poul Sander 2022-02-16 12:14 35
### macOS
c74066db Poul Sander 2022-02-16 12:14 36
c74066db Poul Sander 2022-02-16 12:14 37
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.
c74066db Poul Sander 2022-02-16 12:14 38
The versions 2.X and 3.X uses the deprecated FSFindFolder, which requires the CoreServices framework during linking.
c74066db Poul Sander 2022-02-16 12:14 39
Version 1.X simple used the XDG specification.
c74066db Poul Sander 2022-02-16 12:14 40
c74066db Poul Sander 2022-02-16 12:14 41
## Usage
c74066db Poul Sander 2022-02-16 12:14 42
c74066db Poul Sander 2022-02-16 12:14 43
This project should be compatible with things like [Cmake's ExternalProject_Add](https://cmake.org/cmake/help/latest/module/ExternalProject.html?highlight=externalproject_add#command:externalproject_add) if you wish to use it in your project.
c74066db Poul Sander 2022-02-16 12:14 44
c74066db Poul Sander 2022-02-16 12:14 45
You can also follow the [build step](#building) below to install at a system level, and use [Cmake's find_package](https://cmake.org/cmake/help/latest/command/find_package.html).
c74066db Poul Sander 2022-02-16 12:14 46
c74066db Poul Sander 2022-02-16 12:14 47
```cmake
c74066db Poul Sander 2022-02-16 12:14 48
# Specifying a version is optional -- note it follows Semver
c74066db Poul Sander 2022-02-16 12:14 49
find_package(platform_folders 3.1.0 REQUIRED)
c74066db Poul Sander 2022-02-16 12:14 50
# Which imports the linkable library "sago::platform_folders"
c74066db Poul Sander 2022-02-16 12:14 51
# Use it like so...
c74066db Poul Sander 2022-02-16 12:14 52
target_link_libraries(EXEORLIBNAME PRIVATE sago::platform_folders)
c74066db Poul Sander 2022-02-16 12:14 53
```
c74066db Poul Sander 2022-02-16 12:14 54
c74066db Poul Sander 2022-02-16 12:14 55
Alternatively, you can just copy the [sago](https://github.com/sago007/PlatformFolders/tree/master/sago) folder into your program and manually link everything.
c74066db Poul Sander 2022-02-16 12:14 56
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.
c74066db Poul Sander 2022-02-16 12:14 57
c74066db Poul Sander 2022-02-16 12:14 58
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.
c74066db Poul Sander 2022-02-16 12:14 59
c74066db Poul Sander 2022-02-16 12:14 60
### Building
c74066db Poul Sander 2022-02-16 12:14 61
c74066db Poul Sander 2022-02-16 12:14 62
**Notes:**
c74066db Poul Sander 2022-02-16 12:14 63
c74066db Poul Sander 2022-02-16 12:14 64
* Until 4.0.0 macOS required the CoreServices framework during linking.
c74066db Poul Sander 2022-02-16 12:14 65
* If you don't want to install, remove the `--target install` command.
c74066db Poul Sander 2022-02-16 12:14 66
c74066db Poul Sander 2022-02-16 12:14 67
Linux/macOS:
c74066db Poul Sander 2022-02-16 12:14 68
c74066db Poul Sander 2022-02-16 12:14 69
```
c74066db Poul Sander 2022-02-16 12:14 70
mkdir -p build && cd build
c74066db Poul Sander 2022-02-16 12:14 71
cmake -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release ..
c74066db Poul Sander 2022-02-16 12:14 72
sudo cmake --build . --target install
c74066db Poul Sander 2022-02-16 12:14 73
```
c74066db Poul Sander 2022-02-16 12:14 74
c74066db Poul Sander 2022-02-16 12:14 75
Windows:
c74066db Poul Sander 2022-02-16 12:14 76
c74066db Poul Sander 2022-02-16 12:14 77
```
c74066db Poul Sander 2022-02-16 12:14 78
mkdir build && cd build
c74066db Poul Sander 2022-02-16 12:14 79
cmake -DBUILD_TESTING=OFF ..
c74066db Poul Sander 2022-02-16 12:14 80
runas /user:Administrator "cmake --build . --config Release --target install"
c74066db Poul Sander 2022-02-16 12:14 81
```
c74066db Poul Sander 2022-02-16 12:14 82
c74066db Poul Sander 2022-02-16 12:14 83
## Example Usage
c74066db Poul Sander 2022-02-16 12:14 84
c74066db Poul Sander 2022-02-16 12:14 85
This sample program gets all folders from the system:
c74066db Poul Sander 2022-02-16 12:14 86
c74066db Poul Sander 2022-02-16 12:14 87
```cpp
c74066db Poul Sander 2022-02-16 12:14 88
#include <sago/platform_folders.h>
c74066db Poul Sander 2022-02-16 12:14 89
#include <iostream>
c74066db Poul Sander 2022-02-16 12:14 90
#include <string>
c74066db Poul Sander 2022-02-16 12:14 91
c74066db Poul Sander 2022-02-16 12:14 92
int main()
c74066db Poul Sander 2022-02-16 12:14 93
{
c74066db Poul Sander 2022-02-16 12:14 94
	std::cout << "Config: " << sago::getConfigHome() << "\n";
c74066db Poul Sander 2022-02-16 12:14 95
	std::cout << "Data: " << sago::getDataHome() << "\n";
c74066db Poul Sander 2022-02-16 12:14 96
	std::cout << "State: " << sago::getStateDir() << "\n";
c74066db Poul Sander 2022-02-16 12:14 97
	std::cout << "Cache: " << sago::getCacheDir() << "\n";
c74066db Poul Sander 2022-02-16 12:14 98
	std::cout << "Documents: " << sago::getDocumentsFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 99
	std::cout << "Desktop: " << sago::getDesktopFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 100
	std::cout << "Pictures: " << sago::getPicturesFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 101
	std::cout << "Music: " << sago::getMusicFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 102
	std::cout << "Video: " << sago::getVideoFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 103
	std::cout << "Download: " << sago::getDownloadFolder() << "\n";
c74066db Poul Sander 2022-02-16 12:14 104
	std::cout << "Save Games 1: " << sago::getSaveGamesFolder1() << "\n";
c74066db Poul Sander 2022-02-16 12:14 105
	std::cout << "Save Games 2: " << sago::getSaveGamesFolder2() << "\n";
c74066db Poul Sander 2022-02-16 12:14 106
	return 0;
c74066db Poul Sander 2022-02-16 12:14 107
}
c74066db Poul Sander 2022-02-16 12:14 108
```
c74066db Poul Sander 2022-02-16 12:14 109
c74066db Poul Sander 2022-02-16 12:14 110
### Example Output
c74066db Poul Sander 2022-02-16 12:14 111
c74066db Poul Sander 2022-02-16 12:14 112
#### On Linux
c74066db Poul Sander 2022-02-16 12:14 113
c74066db Poul Sander 2022-02-16 12:14 114
```
c74066db Poul Sander 2022-02-16 12:14 115
Config: /home/poul/.config
c74066db Poul Sander 2022-02-16 12:14 116
Data: /home/poul/.local/share
c74066db Poul Sander 2022-02-16 12:14 117
State: /home/poul/.local/state
c74066db Poul Sander 2022-02-16 12:14 118
Cache: /home/poul/.cache
c74066db Poul Sander 2022-02-16 12:14 119
Documents: /home/poul/Dokumenter
c74066db Poul Sander 2022-02-16 12:14 120
Desktop: /home/poul/Skrivebord
c74066db Poul Sander 2022-02-16 12:14 121
Pictures: /home/poul/Billeder
c74066db Poul Sander 2022-02-16 12:14 122
Music: /home/poul/Musik
c74066db Poul Sander 2022-02-16 12:14 123
Video: /home/poul/Videoklip
c74066db Poul Sander 2022-02-16 12:14 124
Download: /home/poul/Hentede filer
c74066db Poul Sander 2022-02-16 12:14 125
Save Games 1: /home/poul/.local/share
c74066db Poul Sander 2022-02-16 12:14 126
Save Games 2: /home/poul/.local/share
c74066db Poul Sander 2022-02-16 12:14 127
```
c74066db Poul Sander 2022-02-16 12:14 128
c74066db Poul Sander 2022-02-16 12:14 129
#### On Windows
c74066db Poul Sander 2022-02-16 12:14 130
c74066db Poul Sander 2022-02-16 12:14 131
```
c74066db Poul Sander 2022-02-16 12:14 132
Config: C:\users\poul\Application Data
c74066db Poul Sander 2022-02-16 12:14 133
Data: C:\users\poul\Application Data
c74066db Poul Sander 2022-02-16 12:14 134
State: C:\users\poul\Local Settings\Application Data
c74066db Poul Sander 2022-02-16 12:14 135
Cache: C:\users\poul\Local Settings\Application Data
c74066db Poul Sander 2022-02-16 12:14 136
Documents: C:\users\poul\Mine dokumenter
c74066db Poul Sander 2022-02-16 12:14 137
Desktop: C:\users\poul\Skrivebord
c74066db Poul Sander 2022-02-16 12:14 138
Pictures: C:\users\poul\Mine Billeder
c74066db Poul Sander 2022-02-16 12:14 139
Music: C:\users\poul\Min Musik
c74066db Poul Sander 2022-02-16 12:14 140
Video: C:\users\poul\Mine Film
c74066db Poul Sander 2022-02-16 12:14 141
Download: C:\users\poul\Downloads
c74066db Poul Sander 2022-02-16 12:14 142
Save Games 1: C:\users\poul\Mine dokumenter\My Games
c74066db Poul Sander 2022-02-16 12:14 143
Save Games 2: C:\users\poul\Saved Games
c74066db Poul Sander 2022-02-16 12:14 144
```
c74066db Poul Sander 2022-02-16 12:14 145
c74066db Poul Sander 2022-02-16 12:14 146
#### On macOS
c74066db Poul Sander 2022-02-16 12:14 147
c74066db Poul Sander 2022-02-16 12:14 148
```
c74066db Poul Sander 2022-02-16 12:14 149
Config: /Users/poul/Library/Application Support
c74066db Poul Sander 2022-02-16 12:14 150
Data: /Users/poul/Library/Application Support
c74066db Poul Sander 2022-02-16 12:14 151
State: /Users/poul/Library/Application Support
c74066db Poul Sander 2022-02-16 12:14 152
Cache: /Users/poul/Library/Caches
c74066db Poul Sander 2022-02-16 12:14 153
Documents: /Users/poul/Documents
c74066db Poul Sander 2022-02-16 12:14 154
Desktop: /Users/poul/Desktop
c74066db Poul Sander 2022-02-16 12:14 155
Pictures: /Users/poul/Pictures
c74066db Poul Sander 2022-02-16 12:14 156
Music: /Users/poul/Music
c74066db Poul Sander 2022-02-16 12:14 157
Video: /Users/poul/Movies
c74066db Poul Sander 2022-02-16 12:14 158
Download: /Users/poul/Downloads
c74066db Poul Sander 2022-02-16 12:14 159
Save Games 1: /Users/poul/Library/Application Support
c74066db Poul Sander 2022-02-16 12:14 160
Save Games 2: /Users/poul/Library/Application Support
c74066db Poul Sander 2022-02-16 12:14 161
```
c74066db Poul Sander 2022-02-16 12:14 162
c74066db Poul Sander 2022-02-16 12:14 163
## Compiler Compatibility
c74066db Poul Sander 2022-02-16 12:14 164
c74066db Poul Sander 2022-02-16 12:14 165
Versions up to 3.X.X should compile with any C++98 compiler.\
c74066db Poul Sander 2022-02-16 12:14 166
Versions from 4.0.0 and up require a C++11 compatible compiler.
c74066db Poul Sander 2022-02-16 12:14 167
c74066db Poul Sander 2022-02-16 12:14 168
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.
c74066db Poul Sander 2022-02-16 12:14 169
c74066db Poul Sander 2022-02-16 12:14 170
## Encoding
c74066db Poul Sander 2022-02-16 12:14 171
c74066db Poul Sander 2022-02-16 12:14 172
From version 3.0, Windows always encodes to UTF-8, and this will be the default on almost any other system.
c74066db Poul Sander 2022-02-16 12:14 173
Before version 3.0, Windows was encoded in ANSI.
c74066db Poul Sander 2022-02-16 12:14 174
Although the user may use any characters they want, I recommend that the program should have only ASCII characters in the source code itself.
c74066db Poul Sander 2022-02-16 12:14 175
c74066db Poul Sander 2022-02-16 12:14 176
# Licence
c74066db Poul Sander 2022-02-16 12:14 177
c74066db Poul Sander 2022-02-16 12:14 178
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.
1970-01-01 00:00 179