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