| b8e71adb |
Poul Sander |
2015-09-19 19:15 |
1 |
# PlatformFolders |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
2 |
A self contained C++ abstraction library so that you do not need to have Linux, Windows and Mac OS X 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 |
|
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
15 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
16 |
# Linux support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
17 |
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 |
18 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
19 |
# Mac OS X support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
20 |
Uses the deprecated FSFindFolder (there is no C++ alternative). It requires "-framework CoreServices" during linking. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
21 |
|
| 3984e19e |
sago007 |
2015-09-20 11:12 |
22 |
# Usage |
| 3984e19e |
sago007 |
2015-09-20 11:12 |
23 |
Copy "sago/platform_files.cpp" and "sago/platform_fildes.h" to your program and make sure that the cpp file is compiled and linked. |
| 3984e19e |
sago007 |
2015-09-20 11:12 |
24 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
25 |
# Hello World |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
26 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
27 |
This sample program gets all folders from the system: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
28 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
29 |
#include <iostream> |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
30 |
#include "sago/platform_folders.h" |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
31 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
32 |
using namespace std; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
33 |
using namespace sago; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
34 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
35 |
int main() |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
36 |
{ |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
37 |
cout << "Config: " << getConfigHome() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
38 |
cout << "Data: " << getDataHome() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
39 |
cout << "Cache: " << getCacheDir() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
40 |
PlatformFolders p; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
41 |
cout << "Documents: " << p.getDocumentsFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
42 |
cout << "Desktop: " << p.getDesktopFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
43 |
cout << "Pictures: " << p.getPicturesFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
44 |
cout << "Music: " << p.getMusicFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
45 |
cout << "Video: " << p.getVideoFolder() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
46 |
cout << "Download: " << p.getDownloadFolder1() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
47 |
cout << "Save Games 1: " << p.getSaveGamesFolder1() << endl; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
48 |
return 0; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
49 |
} |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
50 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
51 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
52 |
The output on Linux would look like this: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
53 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
54 |
Config: /home/poul/.config |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
55 |
Data: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
56 |
Cache: /home/poul/.cache |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
57 |
Documents: /home/poul/Dokumenter |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
58 |
Desktop: /home/poul/Skrivebord |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
59 |
Pictures: /home/poul/Billeder |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
60 |
Music: /home/poul/Musik |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
61 |
Video: /home/poul/Videoklip |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
62 |
Download: /home/poul/Hentede filer |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
63 |
Save Games 1: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
64 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
65 |
|
| 63627d7a |
sago007 |
2015-09-20 18:08 |
66 |
On Windows it could be: |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
67 |
``` |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
68 |
Config: C:\users\poul\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
69 |
Data: C:\users\poul\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
70 |
Cache: C:\users\poul\Local Settings\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
71 |
Documents: C:\users\poul\Mine dokumenter |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
72 |
Desktop: C:\users\poul\Skrivebord |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
73 |
Pictures: C:\users\poul\Mine Billeder |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
74 |
Music: C:\users\poul\Min Musik |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
75 |
Video: C:\users\poul\Mine Film |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
76 |
Download: C:\users\poul\Skrivebord |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
77 |
Save Games 1: C:\users\poul\Mine dokumenter\My Games |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
78 |
``` |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
79 |
|
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
80 |
On Mac OS X it could be: |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
81 |
``` |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
82 |
Config: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
83 |
Data: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
84 |
Cache: /Users/poul/Library/Caches |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
85 |
Documents: /Users/poul/Documents |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
86 |
Desktop: /Users/poul/Desktop |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
87 |
Pictures: /Users/poul/Pictures |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
88 |
Music: /Users/poul/Music |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
89 |
Video: /Users/poul/Movies |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
90 |
Download: /Users/poul/Downloads |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
91 |
Save Games 1: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
92 |
``` |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
93 |
|
| 63627d7a |
sago007 |
2015-09-20 18:08 |
94 |
# Encoding |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
95 |
For Windows ANSI encoding is always used. Microsoft's implementation of "Unicode" is simply not compatible with platform independent code. |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
96 |
For all other systems the local encoding is used. For most systems this is UTF-8. |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
97 |
Generally you should only append simple ASCII chars to the paths. |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
98 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
99 |
# Licence |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
100 |
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 |
101 |
|