git repos / PlatformFolders

blame: README.md

normal view · raw

5ce952c2 Poul Sander 2015-10-26 17:50 1
# PlatformFolders [![Build Status](https://travis-ci.org/sago007/PlatformFolders.svg?branch=master)](https://travis-ci.org/sago007/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
17b8cd4f Poul Sander 2015-10-26 18:07 10
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 11
a337b4fd sago007 2015-09-19 19:47 12
# Windows support
a337b4fd sago007 2015-09-19 19:47 13
For Windows the folders are fetched using SHGetFolderPath.
a337b4fd sago007 2015-09-19 19:47 14
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 15
Currently "Save Games" and "Downloads" should not be used as they are undefined on XP. 
a337b4fd sago007 2015-09-19 19:47 16
f16cdf4f sago007 2015-10-26 17:37 17
a337b4fd sago007 2015-09-19 19:47 18
# Linux support
a337b4fd sago007 2015-09-19 19:47 19
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 20
a337b4fd sago007 2015-09-19 19:47 21
# Mac OS X support
f16cdf4f sago007 2015-10-26 17:37 22
Uses the deprecated FSFindFolder (there is no C++ alternative). It requires "-framework CoreServices" during linking.
a337b4fd sago007 2015-09-19 19:47 23
3984e19e sago007 2015-09-20 11:12 24
# Usage
3984e19e sago007 2015-09-20 11:12 25
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 26
a337b4fd sago007 2015-09-19 19:47 27
# Hello World
a337b4fd sago007 2015-09-19 19:47 28
a337b4fd sago007 2015-09-19 19:47 29
This sample program gets all folders from the system:
a337b4fd sago007 2015-09-19 19:47 30
```
a337b4fd sago007 2015-09-19 19:47 31
#include <iostream>
a337b4fd sago007 2015-09-19 19:47 32
#include "sago/platform_folders.h"
a337b4fd sago007 2015-09-19 19:47 33
a337b4fd sago007 2015-09-19 19:47 34
using namespace std;
a337b4fd sago007 2015-09-19 19:47 35
using namespace sago;
a337b4fd sago007 2015-09-19 19:47 36
a337b4fd sago007 2015-09-19 19:47 37
int main()
a337b4fd sago007 2015-09-19 19:47 38
{
a337b4fd sago007 2015-09-19 19:47 39
	cout << "Config: " << getConfigHome() << endl;
a337b4fd sago007 2015-09-19 19:47 40
	cout << "Data: " << getDataHome() << endl;
a337b4fd sago007 2015-09-19 19:47 41
	cout << "Cache: " << getCacheDir() << endl;
a337b4fd sago007 2015-09-19 19:47 42
	PlatformFolders p;
a337b4fd sago007 2015-09-19 19:47 43
	cout << "Documents: " << p.getDocumentsFolder() << endl;
a337b4fd sago007 2015-09-19 19:47 44
	cout << "Desktop: " << p.getDesktopFolder() << endl;
a337b4fd sago007 2015-09-19 19:47 45
	cout << "Pictures: " << p.getPicturesFolder() << endl;
a337b4fd sago007 2015-09-19 19:47 46
	cout << "Music: " << p.getMusicFolder() << endl;
a337b4fd sago007 2015-09-19 19:47 47
	cout << "Video: " << p.getVideoFolder() << endl;
a337b4fd sago007 2015-09-19 19:47 48
	cout << "Download: " << p.getDownloadFolder1() << endl;
a337b4fd sago007 2015-09-19 19:47 49
	cout << "Save Games 1: " << p.getSaveGamesFolder1() << endl;
a337b4fd sago007 2015-09-19 19:47 50
	return 0;
a337b4fd sago007 2015-09-19 19:47 51
}
a337b4fd sago007 2015-09-19 19:47 52
```
a337b4fd sago007 2015-09-19 19:47 53
a337b4fd sago007 2015-09-19 19:47 54
The output on Linux would look like this:
a337b4fd sago007 2015-09-19 19:47 55
```
a337b4fd sago007 2015-09-19 19:47 56
Config: /home/poul/.config
a337b4fd sago007 2015-09-19 19:47 57
Data: /home/poul/.local/share
a337b4fd sago007 2015-09-19 19:47 58
Cache: /home/poul/.cache
a337b4fd sago007 2015-09-19 19:47 59
Documents: /home/poul/Dokumenter
a337b4fd sago007 2015-09-19 19:47 60
Desktop: /home/poul/Skrivebord
a337b4fd sago007 2015-09-19 19:47 61
Pictures: /home/poul/Billeder
a337b4fd sago007 2015-09-19 19:47 62
Music: /home/poul/Musik
a337b4fd sago007 2015-09-19 19:47 63
Video: /home/poul/Videoklip
a337b4fd sago007 2015-09-19 19:47 64
Download: /home/poul/Hentede filer
a337b4fd sago007 2015-09-19 19:47 65
Save Games 1: /home/poul/.local/share
a337b4fd sago007 2015-09-19 19:47 66
```
a337b4fd sago007 2015-09-19 19:47 67
63627d7a sago007 2015-09-20 18:08 68
On Windows it could be:
63627d7a sago007 2015-09-20 18:08 69
```
63627d7a sago007 2015-09-20 18:08 70
Config: C:\users\poul\Application Data
63627d7a sago007 2015-09-20 18:08 71
Data: C:\users\poul\Application Data
63627d7a sago007 2015-09-20 18:08 72
Cache: C:\users\poul\Local Settings\Application Data
63627d7a sago007 2015-09-20 18:08 73
Documents: C:\users\poul\Mine dokumenter
63627d7a sago007 2015-09-20 18:08 74
Desktop: C:\users\poul\Skrivebord
63627d7a sago007 2015-09-20 18:08 75
Pictures: C:\users\poul\Mine Billeder
63627d7a sago007 2015-09-20 18:08 76
Music: C:\users\poul\Min Musik
63627d7a sago007 2015-09-20 18:08 77
Video: C:\users\poul\Mine Film
63627d7a sago007 2015-09-20 18:08 78
Download: C:\users\poul\Skrivebord
63627d7a sago007 2015-09-20 18:08 79
Save Games 1: C:\users\poul\Mine dokumenter\My Games
63627d7a sago007 2015-09-20 18:08 80
```
63627d7a sago007 2015-09-20 18:08 81
f16cdf4f sago007 2015-10-26 17:37 82
On Mac OS X it could be:
f16cdf4f sago007 2015-10-26 17:37 83
```
f16cdf4f sago007 2015-10-26 17:37 84
Config: /Users/poul/Library/Application Support
f16cdf4f sago007 2015-10-26 17:37 85
Data: /Users/poul/Library/Application Support
f16cdf4f sago007 2015-10-26 17:37 86
Cache: /Users/poul/Library/Caches
f16cdf4f sago007 2015-10-26 17:37 87
Documents: /Users/poul/Documents
f16cdf4f sago007 2015-10-26 17:37 88
Desktop: /Users/poul/Desktop
f16cdf4f sago007 2015-10-26 17:37 89
Pictures: /Users/poul/Pictures
f16cdf4f sago007 2015-10-26 17:37 90
Music: /Users/poul/Music
f16cdf4f sago007 2015-10-26 17:37 91
Video: /Users/poul/Movies
f16cdf4f sago007 2015-10-26 17:37 92
Download: /Users/poul/Downloads
f16cdf4f sago007 2015-10-26 17:37 93
Save Games 1: /Users/poul/Library/Application Support
f16cdf4f sago007 2015-10-26 17:37 94
```
f16cdf4f sago007 2015-10-26 17:37 95
63627d7a sago007 2015-09-20 18:08 96
# Encoding
63627d7a sago007 2015-09-20 18:08 97
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 98
For all other systems the local encoding is used. For most systems this is UTF-8.
63627d7a sago007 2015-09-20 18:08 99
Generally you should only append simple ASCII chars to the paths. 
63627d7a sago007 2015-09-20 18:08 100
a337b4fd sago007 2015-09-19 19:47 101
# Licence 
a337b4fd sago007 2015-09-19 19:47 102
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 103