git repos / blockattack-game

blame: source/code/sago/platform_folders.h

normal view · raw

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