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
/**
1213f3f3 sago007 2015-09-19 19:24 41
 * Retrives the base folder for storring 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
1213f3f3 sago007 2015-09-19 19:24 48
 * @return The base folder for storring 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
/**
1213f3f3 sago007 2015-09-19 19:24 53
 * Retrives the base folder for storring 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
1213f3f3 sago007 2015-09-19 19:24 60
 * @return The base folder for storring 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
/**
1213f3f3 sago007 2015-09-19 19:24 65
 * Retrives the base folder for storring 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
1213f3f3 sago007 2015-09-19 19:24 72
 * @return The base folder for storring 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.
0fd23ef9 sago007 2018-05-22 17:49 127
 * @note Windows: This version is XP compatible and returns the Desktop. Vista and later has a dedicated folder.
0fd23ef9 sago007 2018-05-22 17:49 128
 * @return Absolute path to the folder where files are downloaded to.
0fd23ef9 sago007 2018-05-22 17:49 129
 */
0fd23ef9 sago007 2018-05-22 17:49 130
std::string getDownloadFolder1();
0fd23ef9 sago007 2018-05-22 17:49 131
0fd23ef9 sago007 2018-05-22 17:49 132
/**
0fd23ef9 sago007 2018-05-22 17:49 133
 * The folder for storring the user's pictures.
0fd23ef9 sago007 2018-05-22 17:49 134
 * @return Absolute path to the "Picture" folder
0fd23ef9 sago007 2018-05-22 17:49 135
 */
0fd23ef9 sago007 2018-05-22 17:49 136
std::string getPicturesFolder();
0fd23ef9 sago007 2018-05-22 17:49 137
0fd23ef9 sago007 2018-05-22 17:49 138
/**
0fd23ef9 sago007 2018-05-22 17:49 139
 * The folder where music is stored
0fd23ef9 sago007 2018-05-22 17:49 140
 * @return Absolute path to the music folder
0fd23ef9 sago007 2018-05-22 17:49 141
 */
0fd23ef9 sago007 2018-05-22 17:49 142
std::string getMusicFolder();
0fd23ef9 sago007 2018-05-22 17:49 143
0fd23ef9 sago007 2018-05-22 17:49 144
/**
0fd23ef9 sago007 2018-05-22 17:49 145
 * The folder where video is stored
0fd23ef9 sago007 2018-05-22 17:49 146
 * @return Absolute path to the video folder
0fd23ef9 sago007 2018-05-22 17:49 147
 */
0fd23ef9 sago007 2018-05-22 17:49 148
std::string getVideoFolder();
0fd23ef9 sago007 2018-05-22 17:49 149
0fd23ef9 sago007 2018-05-22 17:49 150
/**
0fd23ef9 sago007 2018-05-22 17:49 151
 * The base folder for storring saved games.
0fd23ef9 sago007 2018-05-22 17:49 152
 * You must add the program name to it like this:
0fd23ef9 sago007 2018-05-22 17:49 153
 * @code{.cpp}
be6a67eb sago007 2018-05-27 13:12 154
 * string saved_games_folder = sago::getSaveGamesFolder1()+"/My Program Name/";
0fd23ef9 sago007 2018-05-22 17:49 155
 * @endcode
0fd23ef9 sago007 2018-05-22 17:49 156
 * @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 157
 * @note Linux: XDF does not define a folder for saved games. This will just return the same as GetDataHome()
0fd23ef9 sago007 2018-05-22 17:49 158
 * @return The folder base folder for storring save games.
0fd23ef9 sago007 2018-05-22 17:49 159
 */
0fd23ef9 sago007 2018-05-22 17:49 160
std::string getSaveGamesFolder1();
0fd23ef9 sago007 2018-05-22 17:49 161
0fd23ef9 sago007 2018-05-22 17:49 162
#ifndef DOXYGEN_SHOULD_SKIP_THIS
0fd23ef9 sago007 2018-05-22 17:49 163
0fd23ef9 sago007 2018-05-22 17:49 164
/**
1213f3f3 sago007 2015-09-19 19:24 165
 * This class contains methods for finding the system depended special folders.
1213f3f3 sago007 2015-09-19 19:24 166
 * For Windows these folders are either by convention or given by CSIDL.
1213f3f3 sago007 2015-09-19 19:24 167
 * For Linux XDG convention is used.
1213f3f3 sago007 2015-09-19 19:24 168
 * The Linux version has very little error checking and assumes that the config is correct
1213f3f3 sago007 2015-09-19 19:24 169
 */
1213f3f3 sago007 2015-09-19 19:24 170
class PlatformFolders {
1213f3f3 sago007 2015-09-19 19:24 171
public:
1213f3f3 sago007 2015-09-19 19:24 172
	PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 173
	~PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 174
	/**
1213f3f3 sago007 2015-09-19 19:24 175
	 * The folder that represents the desktop.
1213f3f3 sago007 2015-09-19 19:24 176
	 * Normally you should try not to use this folder.
1213f3f3 sago007 2015-09-19 19:24 177
	 * @return Absolute path to the user's desktop
1213f3f3 sago007 2015-09-19 19:24 178
	 */
1213f3f3 sago007 2015-09-19 19:24 179
	std::string getDesktopFolder() const;
1213f3f3 sago007 2015-09-19 19:24 180
	/**
1213f3f3 sago007 2015-09-19 19:24 181
	 * The folder to store user documents to
1213f3f3 sago007 2015-09-19 19:24 182
	 * @return Absolute path to the "Documents" folder
1213f3f3 sago007 2015-09-19 19:24 183
	 */
1213f3f3 sago007 2015-09-19 19:24 184
	std::string getDocumentsFolder() const;
1213f3f3 sago007 2015-09-19 19:24 185
	/**
1213f3f3 sago007 2015-09-19 19:24 186
	 * The folder for storring the user's pictures.
1213f3f3 sago007 2015-09-19 19:24 187
	 * @return Absolute path to the "Picture" folder
1213f3f3 sago007 2015-09-19 19:24 188
	 */
1213f3f3 sago007 2015-09-19 19:24 189
	std::string getPicturesFolder() const;
1213f3f3 sago007 2015-09-19 19:24 190
	/**
1213f3f3 sago007 2015-09-19 19:24 191
	 * The folder where files are downloaded.
1213f3f3 sago007 2015-09-19 19:24 192
	 * @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 193
	 * @return Absolute path to the folder where files are downloaded to.
1213f3f3 sago007 2015-09-19 19:24 194
	 */
1213f3f3 sago007 2015-09-19 19:24 195
	std::string getDownloadFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 196
	/**
1213f3f3 sago007 2015-09-19 19:24 197
	 * The folder where music is stored
1213f3f3 sago007 2015-09-19 19:24 198
	 * @return Absolute path to the music folder
1213f3f3 sago007 2015-09-19 19:24 199
	 */
1213f3f3 sago007 2015-09-19 19:24 200
	std::string getMusicFolder() const;
1213f3f3 sago007 2015-09-19 19:24 201
	/**
1213f3f3 sago007 2015-09-19 19:24 202
	 * The folder where video is stored
1213f3f3 sago007 2015-09-19 19:24 203
	 * @return Absolute path to the video folder
1213f3f3 sago007 2015-09-19 19:24 204
	 */
1213f3f3 sago007 2015-09-19 19:24 205
	std::string getVideoFolder() const;
1213f3f3 sago007 2015-09-19 19:24 206
	/**
1213f3f3 sago007 2015-09-19 19:24 207
	 * The base folder for storring saved games.
1213f3f3 sago007 2015-09-19 19:24 208
	 * You must add the program name to it like this:
1213f3f3 sago007 2015-09-19 19:24 209
	 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 210
	 * PlatformFolders pf;
1213f3f3 sago007 2015-09-19 19:24 211
	 * string saved_games_folder = pf.getSaveGamesFolder1()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 212
	 * @endcode
1213f3f3 sago007 2015-09-19 19:24 213
	 * @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 214
	 * @note Linux: XDF does not define a folder for saved games. This will just return the same as GetDataHome()
1213f3f3 sago007 2015-09-19 19:24 215
	 * @return The folder base folder for storring save games.
1213f3f3 sago007 2015-09-19 19:24 216
	 */
1213f3f3 sago007 2015-09-19 19:24 217
	std::string getSaveGamesFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 218
private:
1213f3f3 sago007 2015-09-19 19:24 219
	PlatformFolders(const PlatformFolders&);
1213f3f3 sago007 2015-09-19 19:24 220
	PlatformFolders& operator=(const PlatformFolders&);
b3e5a881 sum01 2018-04-21 22:53 221
#if !defined(_WIN32) && !defined(__APPLE__)
1213f3f3 sago007 2015-09-19 19:24 222
	struct PlatformFoldersData;
0fd23ef9 sago007 2018-05-22 17:49 223
	PlatformFoldersData* data;
1ff6644e sago007 2018-02-18 16:28 224
#endif
1213f3f3 sago007 2015-09-19 19:24 225
};
1213f3f3 sago007 2015-09-19 19:24 226
0fd23ef9 sago007 2018-05-22 17:49 227
#endif // skip doxygen
0fd23ef9 sago007 2018-05-22 17:49 228
0fd23ef9 sago007 2018-05-22 17:49 229
1213f3f3 sago007 2015-09-19 19:24 230
}  //namespace sago
1213f3f3 sago007 2015-09-19 19:24 231
d2b67cec sago007 2018-03-24 09:52 232
#endif  /* PLATFORM_FOLDERS_H */
1970-01-01 00:00 233