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