git repos / PlatformFolders

blame: sago/platform_folders.h

normal view · raw

1213f3f3 sago007 2015-09-19 19:24 1
/*
d2b67cec sago007 2018-03-24 09:52 2
Its is under the MIT license, to encourage reuse by cut-and-paste.
1213f3f3 sago007 2015-09-19 19:24 3
d2b67cec sago007 2018-03-24 09:52 4
The original files are hosted here: https://github.com/sago007/PlatformFolders
1ff6644e sago007 2018-02-18 16:28 5
d2b67cec sago007 2018-03-24 09:52 6
Copyright (c) 2015 Poul Sander
1213f3f3 sago007 2015-09-19 19:24 7
d2b67cec sago007 2018-03-24 09:52 8
Permission is hereby granted, free of charge, to any person
d2b67cec sago007 2018-03-24 09:52 9
obtaining a copy of this software and associated documentation files
d2b67cec sago007 2018-03-24 09:52 10
(the "Software"), to deal in the Software without restriction,
d2b67cec sago007 2018-03-24 09:52 11
including without limitation the rights to use, copy, modify, merge,
d2b67cec sago007 2018-03-24 09:52 12
publish, distribute, sublicense, and/or sell copies of the Software,
d2b67cec sago007 2018-03-24 09:52 13
and to permit persons to whom the Software is furnished to do so,
d2b67cec sago007 2018-03-24 09:52 14
subject to the following conditions:
1213f3f3 sago007 2015-09-19 19:24 15
d2b67cec sago007 2018-03-24 09:52 16
The above copyright notice and this permission notice shall be
d2b67cec sago007 2018-03-24 09:52 17
included in all copies or substantial portions of the Software.
1213f3f3 sago007 2015-09-19 19:24 18
d2b67cec sago007 2018-03-24 09:52 19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
d2b67cec sago007 2018-03-24 09:52 20
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
d2b67cec sago007 2018-03-24 09:52 21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
d2b67cec sago007 2018-03-24 09:52 22
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
d2b67cec sago007 2018-03-24 09:52 23
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
d2b67cec sago007 2018-03-24 09:52 24
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
d2b67cec sago007 2018-03-24 09:52 25
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
d2b67cec sago007 2018-03-24 09:52 26
SOFTWARE.
1213f3f3 sago007 2015-09-19 19:24 27
*/
1213f3f3 sago007 2015-09-19 19:24 28
1213f3f3 sago007 2015-09-19 19:24 29
#ifndef SAGO_PLATFORM_FOLDERS_H
d2b67cec sago007 2018-03-24 09:52 30
#define SAGO_PLATFORM_FOLDERS_H
1213f3f3 sago007 2015-09-19 19:24 31
1213f3f3 sago007 2015-09-19 19:24 32
#include <vector>
1213f3f3 sago007 2015-09-19 19:24 33
#include <string>
1213f3f3 sago007 2015-09-19 19:24 34
1213f3f3 sago007 2015-09-19 19:24 35
/**
1213f3f3 sago007 2015-09-19 19:24 36
 * The namespace I use for common function. Nothing special about it.
1213f3f3 sago007 2015-09-19 19:24 37
 */
1213f3f3 sago007 2015-09-19 19:24 38
namespace sago {
1213f3f3 sago007 2015-09-19 19:24 39
1213f3f3 sago007 2015-09-19 19:24 40
/**
6b50949e sago007 2018-06-24 14:45 41
 * Retrives the base folder for storing data files.
1213f3f3 sago007 2015-09-19 19:24 42
 * You must add the program name yourself like this:
1213f3f3 sago007 2015-09-19 19:24 43
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 44
 * string data_home = getDataHome()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 45
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 46
 * On Windows this defaults to %APPDATA% (Roaming profile)
1213f3f3 sago007 2015-09-19 19:24 47
 * On Linux this defaults to ~/.local/share but can be configured
6b50949e sago007 2018-06-24 14:45 48
 * @return The base folder for storing program data.
1213f3f3 sago007 2015-09-19 19:24 49
 */
1213f3f3 sago007 2015-09-19 19:24 50
std::string getDataHome();
0fd23ef9 sago007 2018-05-22 17:49 51
1213f3f3 sago007 2015-09-19 19:24 52
/**
6b50949e sago007 2018-06-24 14:45 53
 * Retrives the base folder for storing config files.
1213f3f3 sago007 2015-09-19 19:24 54
 * You must add the program name yourself like this:
1213f3f3 sago007 2015-09-19 19:24 55
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 56
 * string data_home = getConfigHome()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 57
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 58
 * On Windows this defaults to %APPDATA% (Roaming profile)
1213f3f3 sago007 2015-09-19 19:24 59
 * On Linux this defaults to ~/.config but can be configured
6b50949e sago007 2018-06-24 14:45 60
 * @return The base folder for storing config data.
1213f3f3 sago007 2015-09-19 19:24 61
 */
1213f3f3 sago007 2015-09-19 19:24 62
std::string getConfigHome();
0fd23ef9 sago007 2018-05-22 17:49 63
1213f3f3 sago007 2015-09-19 19:24 64
/**
6b50949e sago007 2018-06-24 14:45 65
 * Retrives the base folder for storing cache files.
1213f3f3 sago007 2015-09-19 19:24 66
 * You must add the program name yourself like this:
1213f3f3 sago007 2015-09-19 19:24 67
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 68
 * string data_home = getCacheDir()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 69
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 70
 * On Windows this defaults to %APPDATALOCAL%
1213f3f3 sago007 2015-09-19 19:24 71
 * On Linux this defaults to ~/.cache but can be configured
6b50949e sago007 2018-06-24 14:45 72
 * @return The base folder for storing data that do not need to be backed up.
1213f3f3 sago007 2015-09-19 19:24 73
 */
1213f3f3 sago007 2015-09-19 19:24 74
std::string getCacheDir();
0fd23ef9 sago007 2018-05-22 17:49 75
1213f3f3 sago007 2015-09-19 19:24 76
/**
1213f3f3 sago007 2015-09-19 19:24 77
 * This will append extra folders that your program should be looking for data files in.
1213f3f3 sago007 2015-09-19 19:24 78
 * This does not normally include the path returned by GetDataHome().
1213f3f3 sago007 2015-09-19 19:24 79
 * If you want all the folders you should do something like:
1213f3f3 sago007 2015-09-19 19:24 80
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 81
 * vector<string> folders;
1213f3f3 sago007 2015-09-19 19:24 82
 * folders.push_back(getDataHome());
1213f3f3 sago007 2015-09-19 19:24 83
 * appendAdditionalDataDirectories(folders);
1213f3f3 sago007 2015-09-19 19:24 84
 * for (string s& : folders) {
1213f3f3 sago007 2015-09-19 19:24 85
 *     s+="/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 86
 * }
1213f3f3 sago007 2015-09-19 19:24 87
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 88
 * You must apply "/My Program Name/" to all the strings.
1213f3f3 sago007 2015-09-19 19:24 89
 * The string at the lowest index has the highest priority.
1213f3f3 sago007 2015-09-19 19:24 90
 * @param homes A vector that extra folders will be appended to.
1213f3f3 sago007 2015-09-19 19:24 91
 */
1213f3f3 sago007 2015-09-19 19:24 92
void appendAdditionalDataDirectories(std::vector<std::string>& homes);
0fd23ef9 sago007 2018-05-22 17:49 93
1213f3f3 sago007 2015-09-19 19:24 94
/**
1213f3f3 sago007 2015-09-19 19:24 95
 * This will append extra folders that your program should be looking for config files in.
1213f3f3 sago007 2015-09-19 19:24 96
 * This does not normally include the path returned by GetConfigHome().
1213f3f3 sago007 2015-09-19 19:24 97
 * If you want all the folders you should do something like:
1213f3f3 sago007 2015-09-19 19:24 98
 * @code{.cpp}
9ad3df57 Poul Sander 2016-09-02 20:14 99
 * std::vector<std::string> folders;
9ad3df57 Poul Sander 2016-09-02 20:14 100
 * folders.push_back(sago::getConfigHome());
9ad3df57 Poul Sander 2016-09-02 20:14 101
 * sago::appendAdditionalConfigDirectories(folders);
9ad3df57 Poul Sander 2016-09-02 20:14 102
 * for (std::string s& : folders) {
1213f3f3 sago007 2015-09-19 19:24 103
 *     s+="/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 104
 * }
1213f3f3 sago007 2015-09-19 19:24 105
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 106
 * You must apply "/My Program Name/" to all the strings.
1213f3f3 sago007 2015-09-19 19:24 107
 * The string at the lowest index has the highest priority.
1213f3f3 sago007 2015-09-19 19:24 108
 * @param homes A vector that extra folders will be appended to.
1213f3f3 sago007 2015-09-19 19:24 109
 */
1213f3f3 sago007 2015-09-19 19:24 110
void appendAdditionalConfigDirectories(std::vector<std::string>& homes);
1213f3f3 sago007 2015-09-19 19:24 111
1213f3f3 sago007 2015-09-19 19:24 112
/**
0fd23ef9 sago007 2018-05-22 17:49 113
 * The folder that represents the desktop.
0fd23ef9 sago007 2018-05-22 17:49 114
 * Normally you should try not to use this folder.
0fd23ef9 sago007 2018-05-22 17:49 115
 * @return Absolute path to the user's desktop
0fd23ef9 sago007 2018-05-22 17:49 116
 */
0fd23ef9 sago007 2018-05-22 17:49 117
std::string getDesktopFolder();
0fd23ef9 sago007 2018-05-22 17:49 118
0fd23ef9 sago007 2018-05-22 17:49 119
/**
0fd23ef9 sago007 2018-05-22 17:49 120
 * The folder to store user documents to
0fd23ef9 sago007 2018-05-22 17:49 121
 * @return Absolute path to the "Documents" folder
0fd23ef9 sago007 2018-05-22 17:49 122
 */
0fd23ef9 sago007 2018-05-22 17:49 123
std::string getDocumentsFolder();
0fd23ef9 sago007 2018-05-22 17:49 124
0fd23ef9 sago007 2018-05-22 17:49 125
/**
0fd23ef9 sago007 2018-05-22 17:49 126
 * The folder where files are downloaded.
513c0ebf Poul Sander 2018-06-06 17:05 127
 * @return Absolute path to the folder where files are downloaded to.
513c0ebf Poul Sander 2018-06-06 17:05 128
 */
513c0ebf Poul Sander 2018-06-06 17:05 129
std::string getDownloadFolder();
513c0ebf Poul Sander 2018-06-06 17:05 130
513c0ebf Poul Sander 2018-06-06 17:05 131
/**
513c0ebf Poul Sander 2018-06-06 17:05 132
 * The folder where files are downloaded.
513c0ebf Poul Sander 2018-06-06 17:05 133
 * @note This is provided for backward compatibility. Use getDownloadFolder instead.
0fd23ef9 sago007 2018-05-22 17:49 134
 * @return Absolute path to the folder where files are downloaded to.
0fd23ef9 sago007 2018-05-22 17:49 135
 */
0fd23ef9 sago007 2018-05-22 17:49 136
std::string getDownloadFolder1();
0fd23ef9 sago007 2018-05-22 17:49 137
0fd23ef9 sago007 2018-05-22 17:49 138
/**
6b50949e sago007 2018-06-24 14:45 139
 * The folder for storing the user's pictures.
0fd23ef9 sago007 2018-05-22 17:49 140
 * @return Absolute path to the "Picture" folder
0fd23ef9 sago007 2018-05-22 17:49 141
 */
0fd23ef9 sago007 2018-05-22 17:49 142
std::string getPicturesFolder();
0fd23ef9 sago007 2018-05-22 17:49 143
0fd23ef9 sago007 2018-05-22 17:49 144
/**
5612f69b sago007 2018-06-16 11:22 145
 * This returns the folder that can be used for sharing files with other users on the same system.
5612f69b sago007 2018-06-16 11:22 146
 * @return Absolute path to the "Public" folder
5612f69b sago007 2018-06-16 11:22 147
 */
5612f69b sago007 2018-06-16 11:22 148
std::string getPublicFolder();
5612f69b sago007 2018-06-16 11:22 149
5612f69b sago007 2018-06-16 11:22 150
/**
0fd23ef9 sago007 2018-05-22 17:49 151
 * The folder where music is stored
0fd23ef9 sago007 2018-05-22 17:49 152
 * @return Absolute path to the music folder
0fd23ef9 sago007 2018-05-22 17:49 153
 */
0fd23ef9 sago007 2018-05-22 17:49 154
std::string getMusicFolder();
0fd23ef9 sago007 2018-05-22 17:49 155
0fd23ef9 sago007 2018-05-22 17:49 156
/**
0fd23ef9 sago007 2018-05-22 17:49 157
 * The folder where video is stored
0fd23ef9 sago007 2018-05-22 17:49 158
 * @return Absolute path to the video folder
0fd23ef9 sago007 2018-05-22 17:49 159
 */
0fd23ef9 sago007 2018-05-22 17:49 160
std::string getVideoFolder();
0fd23ef9 sago007 2018-05-22 17:49 161
0fd23ef9 sago007 2018-05-22 17:49 162
/**
6b50949e sago007 2018-06-24 14:45 163
 * A base folder for storing saved games.
0fd23ef9 sago007 2018-05-22 17:49 164
 * You must add the program name to it like this:
0fd23ef9 sago007 2018-05-22 17:49 165
 * @code{.cpp}
be6a67eb sago007 2018-05-27 13:12 166
 * string saved_games_folder = sago::getSaveGamesFolder1()+"/My Program Name/";
0fd23ef9 sago007 2018-05-22 17:49 167
 * @endcode
0fd23ef9 sago007 2018-05-22 17:49 168
 * @note Windows: This is an XP compatible version and returns the path to "My Games" in Documents. Vista and later has an official folder.
0fd23ef9 sago007 2018-05-22 17:49 169
 * @note Linux: XDF does not define a folder for saved games. This will just return the same as GetDataHome()
6b50949e sago007 2018-06-24 14:45 170
 * @return The folder base folder for storing save games.
0fd23ef9 sago007 2018-05-22 17:49 171
 */
0fd23ef9 sago007 2018-05-22 17:49 172
std::string getSaveGamesFolder1();
0fd23ef9 sago007 2018-05-22 17:49 173
513c0ebf Poul Sander 2018-06-06 17:05 174
/**
6b50949e sago007 2018-06-24 14:45 175
 * A base folder for storing saved games.
513c0ebf Poul Sander 2018-06-06 17:05 176
 * You must add the program name to it like this:
513c0ebf Poul Sander 2018-06-06 17:05 177
 * @code{.cpp}
513c0ebf Poul Sander 2018-06-06 17:05 178
 * string saved_games_folder = sago::getSaveGamesFolder2()+"/My Program Name/";
513c0ebf Poul Sander 2018-06-06 17:05 179
 * @endcode
513c0ebf Poul Sander 2018-06-06 17:05 180
 * @note PlatformFolders provide different folders to for saved games as not all operating systems has support for Saved Games yet.
513c0ebf Poul Sander 2018-06-06 17:05 181
 * It is recommended to pick the highest number (currently getSaveGamesFolder2) at the time your product enters production and stick with it
513c0ebf Poul Sander 2018-06-06 17:05 182
 * @note Windows: This returns the "Saved Games" folder. This folder exist in Vista and later
513c0ebf Poul Sander 2018-06-06 17:05 183
 * @note Linux: XDF does not define a folder for saved games. This will just return the same as GetDataHome()
6b50949e sago007 2018-06-24 14:45 184
 * @return The folder base folder for storing save games.
513c0ebf Poul Sander 2018-06-06 17:05 185
 */
513c0ebf Poul Sander 2018-06-06 17:05 186
std::string getSaveGamesFolder2();
513c0ebf Poul Sander 2018-06-06 17:05 187
0fd23ef9 sago007 2018-05-22 17:49 188
#ifndef DOXYGEN_SHOULD_SKIP_THIS
0fd23ef9 sago007 2018-05-22 17:49 189
0fd23ef9 sago007 2018-05-22 17:49 190
/**
1213f3f3 sago007 2015-09-19 19:24 191
 * This class contains methods for finding the system depended special folders.
1213f3f3 sago007 2015-09-19 19:24 192
 * For Windows these folders are either by convention or given by CSIDL.
1213f3f3 sago007 2015-09-19 19:24 193
 * For Linux XDG convention is used.
1213f3f3 sago007 2015-09-19 19:24 194
 * The Linux version has very little error checking and assumes that the config is correct
1213f3f3 sago007 2015-09-19 19:24 195
 */
1213f3f3 sago007 2015-09-19 19:24 196
class PlatformFolders {
1213f3f3 sago007 2015-09-19 19:24 197
public:
1213f3f3 sago007 2015-09-19 19:24 198
	PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 199
	~PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 200
	/**
1213f3f3 sago007 2015-09-19 19:24 201
	 * The folder that represents the desktop.
1213f3f3 sago007 2015-09-19 19:24 202
	 * Normally you should try not to use this folder.
1213f3f3 sago007 2015-09-19 19:24 203
	 * @return Absolute path to the user's desktop
1213f3f3 sago007 2015-09-19 19:24 204
	 */
1213f3f3 sago007 2015-09-19 19:24 205
	std::string getDesktopFolder() const;
1213f3f3 sago007 2015-09-19 19:24 206
	/**
1213f3f3 sago007 2015-09-19 19:24 207
	 * The folder to store user documents to
1213f3f3 sago007 2015-09-19 19:24 208
	 * @return Absolute path to the "Documents" folder
1213f3f3 sago007 2015-09-19 19:24 209
	 */
1213f3f3 sago007 2015-09-19 19:24 210
	std::string getDocumentsFolder() const;
1213f3f3 sago007 2015-09-19 19:24 211
	/**
6b50949e sago007 2018-06-24 14:45 212
	 * The folder for storing the user's pictures.
1213f3f3 sago007 2015-09-19 19:24 213
	 * @return Absolute path to the "Picture" folder
1213f3f3 sago007 2015-09-19 19:24 214
	 */
1213f3f3 sago007 2015-09-19 19:24 215
	std::string getPicturesFolder() const;
1213f3f3 sago007 2015-09-19 19:24 216
	/**
5612f69b sago007 2018-06-16 11:22 217
	 * Use sago::getPublicFolder() instead! 
5612f69b sago007 2018-06-16 11:22 218
	 */
5612f69b sago007 2018-06-16 11:22 219
	std::string getPublicFolder() const;
5612f69b sago007 2018-06-16 11:22 220
	/**
1213f3f3 sago007 2015-09-19 19:24 221
	 * The folder where files are downloaded.
1213f3f3 sago007 2015-09-19 19:24 222
	 * @note Windows: This version is XP compatible and returns the Desktop. Vista and later has a dedicated folder.
1213f3f3 sago007 2015-09-19 19:24 223
	 * @return Absolute path to the folder where files are downloaded to.
1213f3f3 sago007 2015-09-19 19:24 224
	 */
1213f3f3 sago007 2015-09-19 19:24 225
	std::string getDownloadFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 226
	/**
1213f3f3 sago007 2015-09-19 19:24 227
	 * The folder where music is stored
1213f3f3 sago007 2015-09-19 19:24 228
	 * @return Absolute path to the music folder
1213f3f3 sago007 2015-09-19 19:24 229
	 */
1213f3f3 sago007 2015-09-19 19:24 230
	std::string getMusicFolder() const;
1213f3f3 sago007 2015-09-19 19:24 231
	/**
1213f3f3 sago007 2015-09-19 19:24 232
	 * The folder where video is stored
1213f3f3 sago007 2015-09-19 19:24 233
	 * @return Absolute path to the video folder
1213f3f3 sago007 2015-09-19 19:24 234
	 */
1213f3f3 sago007 2015-09-19 19:24 235
	std::string getVideoFolder() const;
1213f3f3 sago007 2015-09-19 19:24 236
	/**
6b50949e sago007 2018-06-24 14:45 237
	 * The base folder for storing saved games.
1213f3f3 sago007 2015-09-19 19:24 238
	 * You must add the program name to it like this:
1213f3f3 sago007 2015-09-19 19:24 239
	 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 240
	 * PlatformFolders pf;
1213f3f3 sago007 2015-09-19 19:24 241
	 * string saved_games_folder = pf.getSaveGamesFolder1()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 242
	 * @endcode
1213f3f3 sago007 2015-09-19 19:24 243
	 * @note Windows: This is an XP compatible version and returns the path to "My Games" in Documents. Vista and later has an official folder.
1213f3f3 sago007 2015-09-19 19:24 244
	 * @note Linux: XDF does not define a folder for saved games. This will just return the same as GetDataHome()
6b50949e sago007 2018-06-24 14:45 245
	 * @return The folder base folder for storing save games.
1213f3f3 sago007 2015-09-19 19:24 246
	 */
1213f3f3 sago007 2015-09-19 19:24 247
	std::string getSaveGamesFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 248
private:
1213f3f3 sago007 2015-09-19 19:24 249
	PlatformFolders(const PlatformFolders&);
1213f3f3 sago007 2015-09-19 19:24 250
	PlatformFolders& operator=(const PlatformFolders&);
b3e5a881 sum01 2018-04-21 22:53 251
#if !defined(_WIN32) && !defined(__APPLE__)
1213f3f3 sago007 2015-09-19 19:24 252
	struct PlatformFoldersData;
0fd23ef9 sago007 2018-05-22 17:49 253
	PlatformFoldersData* data;
1ff6644e sago007 2018-02-18 16:28 254
#endif
1213f3f3 sago007 2015-09-19 19:24 255
};
1213f3f3 sago007 2015-09-19 19:24 256
0fd23ef9 sago007 2018-05-22 17:49 257
#endif // skip doxygen
0fd23ef9 sago007 2018-05-22 17:49 258
0fd23ef9 sago007 2018-05-22 17:49 259
1213f3f3 sago007 2015-09-19 19:24 260
}  //namespace sago
1213f3f3 sago007 2015-09-19 19:24 261
d2b67cec sago007 2018-03-24 09:52 262
#endif  /* PLATFORM_FOLDERS_H */
1970-01-01 00:00 263