| d0a145ba |
sago007 |
2018-04-18 18:32 |
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) [](https://www.codacy.com/app/github_43/PlatformFolders?utm_source=github.com&utm_medium=referral&utm_content=sago007/PlatformFolders&utm_campaign=Badge_Grade) |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
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 |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
3 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
4 |
Can be found at: https://github.com/sago007/PlatformFolders |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
5 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
6 |
Releases can be downloaded here: https://github.com/sago007/PlatformFolders/releases |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
7 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
8 |
# Rationale |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
9 |
There are a lot of platform abstraction libraries available. You can get graphics abstraction libraries, GUI abstraction libraries and file abstraction libraries. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
10 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
11 |
But folder abstraction seems to be more difficult. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
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. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
13 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
14 |
I have written a bit more about it here: http://sago007.blogspot.dk/2015/10/abstraction-for-special-folders.html |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
15 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
16 |
There are some alternatives that you might consider instead: |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
17 |
* QStandardPaths - http://doc.qt.io/qt-5/qstandardpaths.html |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
18 |
* glib - https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
19 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
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. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
21 |
|
| 23c151bc |
sago007 |
2018-04-18 19:03 |
22 |
# Documentation |
| 23c151bc |
sago007 |
2018-04-18 19:03 |
23 |
|
| 23c151bc |
sago007 |
2018-04-18 19:03 |
24 |
Aside from this page there are also Doxygen available: |
| 23c151bc |
sago007 |
2018-04-18 19:03 |
25 |
|
| 23c151bc |
sago007 |
2018-04-18 19:03 |
26 |
* 3.0: http://sago007.github.io/PlatformFolders/html/doxygen/3.0/ |
| 23c151bc |
sago007 |
2018-04-18 19:03 |
27 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
28 |
# Windows support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
29 |
For Windows the folders are fetched using SHGetFolderPath. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
30 |
The amount of supported folders differ from Windows version and this library targets XP and newer... and I'll drop XP support very soon. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
31 |
Currently "Save Games" and "Downloads" should not be used as they are undefined on XP. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
32 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
33 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
34 |
# Linux support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
35 |
In Linux a lot of these folders are not official defined. However this library uses XDG user dirs. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
36 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
37 |
# Mac OS X support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
38 |
Uses the deprecated FSFindFolder (there is no C++ alternative). It requires "-framework CoreServices" during linking. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
39 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
40 |
# Usage |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
41 |
Copy "sago/platform_files.cpp" and "sago/platform_fildes.h" to your program and make sure that the cpp file is compiled and linked. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
42 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
43 |
# Hello World |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
44 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
45 |
This sample program gets all folders from the system: |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
46 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
47 |
#include <iostream> |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
48 |
#include "sago/platform_folders.h" |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
49 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
50 |
using std::cout; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
51 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
52 |
int main() |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
53 |
{ |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
54 |
cout << "Config: " << sago::getConfigHome() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
55 |
cout << "Data: " << sago::getDataHome() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
56 |
cout << "Cache: " << sago::getCacheDir() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
57 |
sago::PlatformFolders p; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
58 |
cout << "Documents: " << p.getDocumentsFolder() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
59 |
cout << "Desktop: " << p.getDesktopFolder() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
60 |
cout << "Pictures: " << p.getPicturesFolder() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
61 |
cout << "Music: " << p.getMusicFolder() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
62 |
cout << "Video: " << p.getVideoFolder() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
63 |
cout << "Download: " << p.getDownloadFolder1() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
64 |
cout << "Save Games 1: " << p.getSaveGamesFolder1() << "\n"; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
65 |
return 0; |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
66 |
} |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
67 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
68 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
69 |
The output on Linux would look like this: |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
70 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
71 |
Config: /home/poul/.config |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
72 |
Data: /home/poul/.local/share |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
73 |
Cache: /home/poul/.cache |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
74 |
Documents: /home/poul/Dokumenter |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
75 |
Desktop: /home/poul/Skrivebord |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
76 |
Pictures: /home/poul/Billeder |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
77 |
Music: /home/poul/Musik |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
78 |
Video: /home/poul/Videoklip |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
79 |
Download: /home/poul/Hentede filer |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
80 |
Save Games 1: /home/poul/.local/share |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
81 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
82 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
83 |
On Windows it could be: |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
84 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
85 |
Config: C:\users\poul\Application Data |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
86 |
Data: C:\users\poul\Application Data |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
87 |
Cache: C:\users\poul\Local Settings\Application Data |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
88 |
Documents: C:\users\poul\Mine dokumenter |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
89 |
Desktop: C:\users\poul\Skrivebord |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
90 |
Pictures: C:\users\poul\Mine Billeder |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
91 |
Music: C:\users\poul\Min Musik |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
92 |
Video: C:\users\poul\Mine Film |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
93 |
Download: C:\users\poul\Skrivebord |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
94 |
Save Games 1: C:\users\poul\Mine dokumenter\My Games |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
95 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
96 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
97 |
On Mac OS X it could be: |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
98 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
99 |
Config: /Users/poul/Library/Application Support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
100 |
Data: /Users/poul/Library/Application Support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
101 |
Cache: /Users/poul/Library/Caches |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
102 |
Documents: /Users/poul/Documents |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
103 |
Desktop: /Users/poul/Desktop |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
104 |
Pictures: /Users/poul/Pictures |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
105 |
Music: /Users/poul/Music |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
106 |
Video: /Users/poul/Movies |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
107 |
Download: /Users/poul/Downloads |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
108 |
Save Games 1: /Users/poul/Library/Application Support |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
109 |
``` |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
110 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
111 |
# Encoding |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
112 |
From version 3.0 UTF-8 is always used on Windows and will also be the default in almost any other system. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
113 |
Before version 3.0 Windows used ANSI encoding. Microsoft's default choice of UTF-16 is not compatible with platform independent code. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
114 |
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. |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
115 |
|
| d0a145ba |
sago007 |
2018-04-18 18:32 |
116 |
# Licence |
| d0a145ba |
sago007 |
2018-04-18 18:32 |
117 |
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 |
118 |
|