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();
1213f3f3 sago007 2015-09-19 19:24 51
/**
1213f3f3 sago007 2015-09-19 19:24 52
 * Retrives the base folder for storring config files.
1213f3f3 sago007 2015-09-19 19:24 53
 * You must add the program name yourself like this:
1213f3f3 sago007 2015-09-19 19:24 54
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 55
 * string data_home = getConfigHome()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 56
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 57
 * On Windows this defaults to %APPDATA% (Roaming profile)
1213f3f3 sago007 2015-09-19 19:24 58
 * On Linux this defaults to ~/.config but can be configured
1213f3f3 sago007 2015-09-19 19:24 59
 * @return The base folder for storring config data.
1213f3f3 sago007 2015-09-19 19:24 60
 */
1213f3f3 sago007 2015-09-19 19:24 61
std::string getConfigHome();
1213f3f3 sago007 2015-09-19 19:24 62
/**
1213f3f3 sago007 2015-09-19 19:24 63
 * Retrives the base folder for storring cache files.
1213f3f3 sago007 2015-09-19 19:24 64
 * You must add the program name yourself like this:
1213f3f3 sago007 2015-09-19 19:24 65
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 66
 * string data_home = getCacheDir()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 67
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 68
 * On Windows this defaults to %APPDATALOCAL%
1213f3f3 sago007 2015-09-19 19:24 69
 * On Linux this defaults to ~/.cache but can be configured
1213f3f3 sago007 2015-09-19 19:24 70
 * @return The base folder for storring data that do not need to be backed up.
1213f3f3 sago007 2015-09-19 19:24 71
 */
1213f3f3 sago007 2015-09-19 19:24 72
std::string getCacheDir();
1213f3f3 sago007 2015-09-19 19:24 73
/**
1213f3f3 sago007 2015-09-19 19:24 74
 * This will append extra folders that your program should be looking for data files in.
1213f3f3 sago007 2015-09-19 19:24 75
 * This does not normally include the path returned by GetDataHome().
1213f3f3 sago007 2015-09-19 19:24 76
 * If you want all the folders you should do something like:
1213f3f3 sago007 2015-09-19 19:24 77
 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 78
 * vector<string> folders;
1213f3f3 sago007 2015-09-19 19:24 79
 * folders.push_back(getDataHome());
1213f3f3 sago007 2015-09-19 19:24 80
 * appendAdditionalDataDirectories(folders);
1213f3f3 sago007 2015-09-19 19:24 81
 * for (string s& : folders) {
1213f3f3 sago007 2015-09-19 19:24 82
 *     s+="/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 83
 * }
1213f3f3 sago007 2015-09-19 19:24 84
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 85
 * You must apply "/My Program Name/" to all the strings.
1213f3f3 sago007 2015-09-19 19:24 86
 * The string at the lowest index has the highest priority.
1213f3f3 sago007 2015-09-19 19:24 87
 * @param homes A vector that extra folders will be appended to.
1213f3f3 sago007 2015-09-19 19:24 88
 */
1213f3f3 sago007 2015-09-19 19:24 89
void appendAdditionalDataDirectories(std::vector<std::string>& homes);
1213f3f3 sago007 2015-09-19 19:24 90
/**
1213f3f3 sago007 2015-09-19 19:24 91
 * This will append extra folders that your program should be looking for config files in.
1213f3f3 sago007 2015-09-19 19:24 92
 * This does not normally include the path returned by GetConfigHome().
1213f3f3 sago007 2015-09-19 19:24 93
 * If you want all the folders you should do something like:
1213f3f3 sago007 2015-09-19 19:24 94
 * @code{.cpp}
9ad3df57 Poul Sander 2016-09-02 20:14 95
 * std::vector<std::string> folders;
9ad3df57 Poul Sander 2016-09-02 20:14 96
 * folders.push_back(sago::getConfigHome());
9ad3df57 Poul Sander 2016-09-02 20:14 97
 * sago::appendAdditionalConfigDirectories(folders);
9ad3df57 Poul Sander 2016-09-02 20:14 98
 * for (std::string s& : folders) {
1213f3f3 sago007 2015-09-19 19:24 99
 *     s+="/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 100
 * }
1213f3f3 sago007 2015-09-19 19:24 101
 * @endcode
1213f3f3 sago007 2015-09-19 19:24 102
 * You must apply "/My Program Name/" to all the strings.
1213f3f3 sago007 2015-09-19 19:24 103
 * The string at the lowest index has the highest priority.
1213f3f3 sago007 2015-09-19 19:24 104
 * @param homes A vector that extra folders will be appended to.
1213f3f3 sago007 2015-09-19 19:24 105
 */
1213f3f3 sago007 2015-09-19 19:24 106
void appendAdditionalConfigDirectories(std::vector<std::string>& homes);
1213f3f3 sago007 2015-09-19 19:24 107
1213f3f3 sago007 2015-09-19 19:24 108
/**
1213f3f3 sago007 2015-09-19 19:24 109
 * This class contains methods for finding the system depended special folders.
1213f3f3 sago007 2015-09-19 19:24 110
 * For Windows these folders are either by convention or given by CSIDL.
1213f3f3 sago007 2015-09-19 19:24 111
 * For Linux XDG convention is used.
1213f3f3 sago007 2015-09-19 19:24 112
 * The Linux version has very little error checking and assumes that the config is correct
1213f3f3 sago007 2015-09-19 19:24 113
 */
1213f3f3 sago007 2015-09-19 19:24 114
class PlatformFolders {
1213f3f3 sago007 2015-09-19 19:24 115
public:
1213f3f3 sago007 2015-09-19 19:24 116
	PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 117
	~PlatformFolders();
1213f3f3 sago007 2015-09-19 19:24 118
	/**
1213f3f3 sago007 2015-09-19 19:24 119
	 * The folder that represents the desktop.
1213f3f3 sago007 2015-09-19 19:24 120
	 * Normally you should try not to use this folder.
1213f3f3 sago007 2015-09-19 19:24 121
	 * @return Absolute path to the user's desktop
1213f3f3 sago007 2015-09-19 19:24 122
	 */
1213f3f3 sago007 2015-09-19 19:24 123
	std::string getDesktopFolder() const;
1213f3f3 sago007 2015-09-19 19:24 124
	/**
1213f3f3 sago007 2015-09-19 19:24 125
	 * The folder to store user documents to
1213f3f3 sago007 2015-09-19 19:24 126
	 * @return Absolute path to the "Documents" folder
1213f3f3 sago007 2015-09-19 19:24 127
	 */
1213f3f3 sago007 2015-09-19 19:24 128
	std::string getDocumentsFolder() const;
1213f3f3 sago007 2015-09-19 19:24 129
	/**
1213f3f3 sago007 2015-09-19 19:24 130
	 * The folder for storring the user's pictures.
1213f3f3 sago007 2015-09-19 19:24 131
	 * @return Absolute path to the "Picture" folder
1213f3f3 sago007 2015-09-19 19:24 132
	 */
1213f3f3 sago007 2015-09-19 19:24 133
	std::string getPicturesFolder() const;
1213f3f3 sago007 2015-09-19 19:24 134
	/**
1213f3f3 sago007 2015-09-19 19:24 135
	 * The folder where files are downloaded.
1213f3f3 sago007 2015-09-19 19:24 136
	 * @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 137
	 * @return Absolute path to the folder where files are downloaded to.
1213f3f3 sago007 2015-09-19 19:24 138
	 */
1213f3f3 sago007 2015-09-19 19:24 139
	std::string getDownloadFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 140
	/**
1213f3f3 sago007 2015-09-19 19:24 141
	 * The folder where music is stored
1213f3f3 sago007 2015-09-19 19:24 142
	 * @return Absolute path to the music folder
1213f3f3 sago007 2015-09-19 19:24 143
	 */
1213f3f3 sago007 2015-09-19 19:24 144
	std::string getMusicFolder() const;
1213f3f3 sago007 2015-09-19 19:24 145
	/**
1213f3f3 sago007 2015-09-19 19:24 146
	 * The folder where video is stored
1213f3f3 sago007 2015-09-19 19:24 147
	 * @return Absolute path to the video folder
1213f3f3 sago007 2015-09-19 19:24 148
	 */
1213f3f3 sago007 2015-09-19 19:24 149
	std::string getVideoFolder() const;
1213f3f3 sago007 2015-09-19 19:24 150
	/**
1213f3f3 sago007 2015-09-19 19:24 151
	 * The base folder for storring saved games.
1213f3f3 sago007 2015-09-19 19:24 152
	 * You must add the program name to it like this:
1213f3f3 sago007 2015-09-19 19:24 153
	 * @code{.cpp}
1213f3f3 sago007 2015-09-19 19:24 154
	 * PlatformFolders pf;
1213f3f3 sago007 2015-09-19 19:24 155
	 * string saved_games_folder = pf.getSaveGamesFolder1()+"/My Program Name/";
1213f3f3 sago007 2015-09-19 19:24 156
	 * @endcode
1213f3f3 sago007 2015-09-19 19:24 157
	 * @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 158
	 * @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 159
	 * @return The folder base folder for storring save games.
1213f3f3 sago007 2015-09-19 19:24 160
	 */
1213f3f3 sago007 2015-09-19 19:24 161
	std::string getSaveGamesFolder1() const;
1213f3f3 sago007 2015-09-19 19:24 162
private:
1213f3f3 sago007 2015-09-19 19:24 163
	PlatformFolders(const PlatformFolders&);
1213f3f3 sago007 2015-09-19 19:24 164
	PlatformFolders& operator=(const PlatformFolders&);
1ff6644e sago007 2018-02-18 16:28 165
#if defined(_WIN32)
1ff6644e sago007 2018-02-18 16:28 166
#elif defined(__APPLE__)
1ff6644e sago007 2018-02-18 16:28 167
#else
1213f3f3 sago007 2015-09-19 19:24 168
	struct PlatformFoldersData;
411ebafb sago007 2016-09-02 21:22 169
	PlatformFoldersData *data;
1ff6644e sago007 2018-02-18 16:28 170
#endif
1213f3f3 sago007 2015-09-19 19:24 171
};
1213f3f3 sago007 2015-09-19 19:24 172
1213f3f3 sago007 2015-09-19 19:24 173
}  //namespace sago
1213f3f3 sago007 2015-09-19 19:24 174
d2b67cec sago007 2018-03-24 09:52 175
#endif  /* PLATFORM_FOLDERS_H */
1970-01-01 00:00 176