| b8e71adb |
Poul Sander |
2015-09-19 19:15 |
1 |
# PlatformFolders |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
2 |
A abstraction self contained C++ library so that you do not need to have Windows and Linux specific code to look for special directories |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
3 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
4 |
# Rationale |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
5 |
There are a lot of platform abstraction libraries available. You can get graphics abstraction libraries, GUI abstraction libraries and file abstraction libraries. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
6 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
7 |
But folder abstraction seems to be more difficult. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
8 |
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. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
9 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
10 |
# Windows support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
11 |
For Windows the folders are fetched using SHGetFolderPath. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
12 |
The amount of supported folders differ from Windows version and this library targets XP and newer... and I'll drop XP support very soon. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
13 |
Currently "Save Games" and "Downloads" should not be used as they are undefined on XP. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
14 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
15 |
# Linux support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
16 |
In Linux a lot of these folders are not official defined. However this library uses XDG user dirs. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
17 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
18 |
# Mac OS X support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
19 |
Currently not supported. The Mac OS X C++ documentation is very slim and I could not get FSFindFolder to work (I need to link against something). As a result you will simply get the XDG defined folders if you try to use compile it on Mac. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
20 |
If someone could tell me what I need to link to get "_FSFindFolder" I'll add support for Mac as well. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
21 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
22 |
# Hello World |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
23 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
24 |
This sample program gets all folders from the system: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
25 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
26 |
#include <iostream> |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
27 |
#include "sago/platform_folders.h" |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
28 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
29 |
using namespace std; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
30 |
using namespace sago; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
31 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
32 |
int main() |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
33 |
{ |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
34 |
cout << "Config: " << getConfigHome() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
35 |
cout << "Data: " << getDataHome() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
36 |
cout << "Cache: " << getCacheDir() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
37 |
PlatformFolders p; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
38 |
cout << "Documents: " << p.getDocumentsFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
39 |
cout << "Desktop: " << p.getDesktopFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
40 |
cout << "Pictures: " << p.getPicturesFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
41 |
cout << "Music: " << p.getMusicFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
42 |
cout << "Video: " << p.getVideoFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
43 |
cout << "Download: " << p.getDownloadFolder1() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
44 |
cout << "Save Games 1: " << p.getSaveGamesFolder1() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
45 |
return 0; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
46 |
} |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
47 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
48 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
49 |
The output on Linux would look like this: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
50 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
51 |
Config: /home/poul/.config |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
52 |
Data: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
53 |
Cache: /home/poul/.cache |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
54 |
Documents: /home/poul/Dokumenter |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
55 |
Desktop: /home/poul/Skrivebord |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
56 |
Pictures: /home/poul/Billeder |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
57 |
Music: /home/poul/Musik |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
58 |
Video: /home/poul/Videoklip |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
59 |
Download: /home/poul/Hentede filer |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
60 |
Save Games 1: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
61 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
62 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
63 |
# Licence |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
64 |
Provided under the MIT license for the same reason XDG is licenced under it. So that you can quickly copy-paste the methods you need or just include the "sago"-folder. |
|
|
1970-01-01 00:00 |
65 |
|