| 4d95f02e |
Poul Sander |
2017-02-28 17:56 |
1 |
# PlatformFolders [](https://travis-ci.org/sago007/PlatformFolders) [](https://raw.githubusercontent.com/sago007/PlatformFolders/master/LICENSE) [](https://gitter.im/PlatformFolders/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
2 |
A C++ library to look for special directories like "My Documents" and "%APPDATA%" so that you do not need to write Linux, Windows or Mac OS X specific code |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
3 |
|
| 3b191916 |
sago007 |
2016-02-16 17:08 |
4 |
Can be found at: https://github.com/sago007/PlatformFolders |
| 3b191916 |
sago007 |
2016-02-16 17:08 |
5 |
|
| 4f278f37 |
Poul Sander |
2016-09-06 19:10 |
6 |
Releases can be downloaded here: https://github.com/sago007/PlatformFolders/releases |
| 4f278f37 |
Poul Sander |
2016-09-06 19:10 |
7 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
8 |
# Rationale |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
9 |
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 |
10 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
11 |
But folder abstraction seems to be more difficult. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
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. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
13 |
|
| 17b8cd4f |
Poul Sander |
2015-10-26 18:07 |
14 |
I have written a bit more about it here: http://sago007.blogspot.dk/2015/10/abstraction-for-special-folders.html |
| 17b8cd4f |
Poul Sander |
2015-10-26 18:07 |
15 |
|
| 463ec450 |
Poul Sander |
2015-10-27 19:07 |
16 |
There are some alternatives that you might consider instead: |
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
17 |
* QStandardPaths - http://doc.qt.io/qt-5/qstandardpaths.html |
| 463ec450 |
Poul Sander |
2015-10-27 19:07 |
18 |
* glib - https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html |
| 463ec450 |
Poul Sander |
2015-10-27 19:07 |
19 |
|
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
20 |
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. |
| 463ec450 |
Poul Sander |
2015-10-27 19:07 |
21 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
22 |
# Windows support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
23 |
For Windows the folders are fetched using SHGetFolderPath. |
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
24 |
The amount of supported folders differ from Windows version and this library targets XP and newer... and I'll drop XP support very soon. |
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
25 |
Currently "Save Games" and "Downloads" should not be used as they are undefined on XP. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
26 |
|
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
27 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
28 |
# Linux support |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
29 |
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 |
30 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
31 |
# Mac OS X support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
32 |
Uses the deprecated FSFindFolder (there is no C++ alternative). It requires "-framework CoreServices" during linking. |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
33 |
|
| 3984e19e |
sago007 |
2015-09-20 11:12 |
34 |
# Usage |
| 3984e19e |
sago007 |
2015-09-20 11:12 |
35 |
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 |
36 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
37 |
# Hello World |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
38 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
39 |
This sample program gets all folders from the system: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
40 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
41 |
#include <iostream> |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
42 |
#include "sago/platform_folders.h" |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
43 |
|
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
44 |
using std::cout; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
45 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
46 |
int main() |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
47 |
{ |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
48 |
cout << "Config: " << sago::getConfigHome() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
49 |
cout << "Data: " << sago::getDataHome() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
50 |
cout << "Cache: " << sago::getCacheDir() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
51 |
sago::PlatformFolders p; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
52 |
cout << "Documents: " << p.getDocumentsFolder() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
53 |
cout << "Desktop: " << p.getDesktopFolder() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
54 |
cout << "Pictures: " << p.getPicturesFolder() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
55 |
cout << "Music: " << p.getMusicFolder() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
56 |
cout << "Video: " << p.getVideoFolder() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
57 |
cout << "Download: " << p.getDownloadFolder1() << "\n"; |
| 9ad3df57 |
Poul Sander |
2016-09-02 20:14 |
58 |
cout << "Save Games 1: " << p.getSaveGamesFolder1() << "\n"; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
59 |
return 0; |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
60 |
} |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
61 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
62 |
|
| a337b4fd |
sago007 |
2015-09-19 19:47 |
63 |
The output on Linux would look like this: |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
64 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
65 |
Config: /home/poul/.config |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
66 |
Data: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
67 |
Cache: /home/poul/.cache |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
68 |
Documents: /home/poul/Dokumenter |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
69 |
Desktop: /home/poul/Skrivebord |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
70 |
Pictures: /home/poul/Billeder |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
71 |
Music: /home/poul/Musik |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
72 |
Video: /home/poul/Videoklip |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
73 |
Download: /home/poul/Hentede filer |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
74 |
Save Games 1: /home/poul/.local/share |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
75 |
``` |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
76 |
|
| 63627d7a |
sago007 |
2015-09-20 18:08 |
77 |
On Windows it could be: |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
78 |
``` |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
79 |
Config: C:\users\poul\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
80 |
Data: C:\users\poul\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
81 |
Cache: C:\users\poul\Local Settings\Application Data |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
82 |
Documents: C:\users\poul\Mine dokumenter |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
83 |
Desktop: C:\users\poul\Skrivebord |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
84 |
Pictures: C:\users\poul\Mine Billeder |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
85 |
Music: C:\users\poul\Min Musik |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
86 |
Video: C:\users\poul\Mine Film |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
87 |
Download: C:\users\poul\Skrivebord |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
88 |
Save Games 1: C:\users\poul\Mine dokumenter\My Games |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
89 |
``` |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
90 |
|
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
91 |
On Mac OS X it could be: |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
92 |
``` |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
93 |
Config: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
94 |
Data: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
95 |
Cache: /Users/poul/Library/Caches |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
96 |
Documents: /Users/poul/Documents |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
97 |
Desktop: /Users/poul/Desktop |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
98 |
Pictures: /Users/poul/Pictures |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
99 |
Music: /Users/poul/Music |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
100 |
Video: /Users/poul/Movies |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
101 |
Download: /Users/poul/Downloads |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
102 |
Save Games 1: /Users/poul/Library/Application Support |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
103 |
``` |
| f16cdf4f |
sago007 |
2015-10-26 17:37 |
104 |
|
| 63627d7a |
sago007 |
2015-09-20 18:08 |
105 |
# Encoding |
| d6759de0 |
Poul Sander |
2016-10-08 11:46 |
106 |
From version 3.0 UTF-8 is always used on Windows and will also be the default in almost any other system. |
| d6759de0 |
Poul Sander |
2016-10-08 11:46 |
107 |
Before version 3.0 Windows used ANSI encoding. Microsoft's default choice of UTF-16 is not compatible with platform independent code. |
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
108 |
Although the user may use an charectors they want I recommend, that the progran should not have non ASCII charectors in the soruce code itself. |
| 63627d7a |
sago007 |
2015-09-20 18:08 |
109 |
|
| 2b84d0ce |
Poul Sander |
2017-02-11 15:43 |
110 |
# Licence |
| a337b4fd |
sago007 |
2015-09-19 19:47 |
111 |
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 |
112 |
|