git repos / PlatformFolders

blame: sago/platform_folders.cpp

normal view · raw

1213f3f3 sago007 2015-09-19 19:24 1
/*
1213f3f3 sago007 2015-09-19 19:24 2
  Its is under the MIT license, to encourage reuse by cut-and-paste.
1213f3f3 sago007 2015-09-19 19:24 3
1213f3f3 sago007 2015-09-19 19:24 4
  Copyright (c) 2015 Poul Sander
1213f3f3 sago007 2015-09-19 19:24 5
1213f3f3 sago007 2015-09-19 19:24 6
  Permission is hereby granted, free of charge, to any person
1213f3f3 sago007 2015-09-19 19:24 7
  obtaining a copy of this software and associated documentation files
1213f3f3 sago007 2015-09-19 19:24 8
  (the "Software"), to deal in the Software without restriction,
1213f3f3 sago007 2015-09-19 19:24 9
  including without limitation the rights to use, copy, modify, merge,
1213f3f3 sago007 2015-09-19 19:24 10
  publish, distribute, sublicense, and/or sell copies of the Software,
1213f3f3 sago007 2015-09-19 19:24 11
  and to permit persons to whom the Software is furnished to do so,
1213f3f3 sago007 2015-09-19 19:24 12
  subject to the following conditions:
1213f3f3 sago007 2015-09-19 19:24 13
1213f3f3 sago007 2015-09-19 19:24 14
  The above copyright notice and this permission notice shall be
1213f3f3 sago007 2015-09-19 19:24 15
  included in all copies or substantial portions of the Software.
1213f3f3 sago007 2015-09-19 19:24 16
1213f3f3 sago007 2015-09-19 19:24 17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1213f3f3 sago007 2015-09-19 19:24 18
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1213f3f3 sago007 2015-09-19 19:24 19
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1213f3f3 sago007 2015-09-19 19:24 20
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1213f3f3 sago007 2015-09-19 19:24 21
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1213f3f3 sago007 2015-09-19 19:24 22
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1213f3f3 sago007 2015-09-19 19:24 23
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1213f3f3 sago007 2015-09-19 19:24 24
  SOFTWARE.
1213f3f3 sago007 2015-09-19 19:24 25
*/
1213f3f3 sago007 2015-09-19 19:24 26
1213f3f3 sago007 2015-09-19 19:24 27
#include "platform_folders.h"
1213f3f3 sago007 2015-09-19 19:24 28
#include <iostream>
1213f3f3 sago007 2015-09-19 19:24 29
#include <stdexcept>
1213f3f3 sago007 2015-09-19 19:24 30
#include <string.h>
1213f3f3 sago007 2015-09-19 19:24 31
#include <stdio.h>
1213f3f3 sago007 2015-09-19 19:24 32
#include <cstdlib>
1213f3f3 sago007 2015-09-19 19:24 33
1213f3f3 sago007 2015-09-19 19:24 34
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 35
#include <windows.h>
1213f3f3 sago007 2015-09-19 19:24 36
#include <shlobj.h>
1213f3f3 sago007 2015-09-19 19:24 37
1213f3f3 sago007 2015-09-19 19:24 38
#define strtok_r strtok_s
1213f3f3 sago007 2015-09-19 19:24 39
1213f3f3 sago007 2015-09-19 19:24 40
static std::string GetWindowsFolder(int folderId, const char* errorMsg) {
1213f3f3 sago007 2015-09-19 19:24 41
	char szPath[MAX_PATH];
1213f3f3 sago007 2015-09-19 19:24 42
	szPath[0] = 0;
63627d7a sago007 2015-09-20 18:08 43
	if ( !SUCCEEDED( SHGetFolderPathA( NULL, folderId, NULL, 0, szPath ) ) )
1213f3f3 sago007 2015-09-19 19:24 44
	{
1213f3f3 sago007 2015-09-19 19:24 45
		throw std::runtime_error(errorMsg);
1213f3f3 sago007 2015-09-19 19:24 46
	}
1213f3f3 sago007 2015-09-19 19:24 47
	return szPath;
1213f3f3 sago007 2015-09-19 19:24 48
}
1213f3f3 sago007 2015-09-19 19:24 49
1213f3f3 sago007 2015-09-19 19:24 50
static std::string GetAppData() {
1213f3f3 sago007 2015-09-19 19:24 51
	return GetWindowsFolder(CSIDL_APPDATA, "RoamingAppData could not be found");
1213f3f3 sago007 2015-09-19 19:24 52
}
1213f3f3 sago007 2015-09-19 19:24 53
1213f3f3 sago007 2015-09-19 19:24 54
static std::string GetAppDataCommon() {
1213f3f3 sago007 2015-09-19 19:24 55
	return GetWindowsFolder(CSIDL_COMMON_APPDATA, "Common appdata could not be found");
1213f3f3 sago007 2015-09-19 19:24 56
}
1213f3f3 sago007 2015-09-19 19:24 57
1213f3f3 sago007 2015-09-19 19:24 58
static std::string GetAppDataLocal() {
1213f3f3 sago007 2015-09-19 19:24 59
	return GetWindowsFolder(CSIDL_LOCAL_APPDATA, "LocalAppData could not be found");
1213f3f3 sago007 2015-09-19 19:24 60
}
1213f3f3 sago007 2015-09-19 19:24 61
#else
1213f3f3 sago007 2015-09-19 19:24 62
#include <map>
1213f3f3 sago007 2015-09-19 19:24 63
#include <fstream>
dcb0fec2 sago007 2015-09-21 17:50 64
#include <pwd.h>
dcb0fec2 sago007 2015-09-21 17:50 65
#include <unistd.h>
dcb0fec2 sago007 2015-09-21 17:50 66
#include <sys/types.h>
1213f3f3 sago007 2015-09-19 19:24 67
//Typically Linux. For easy reading the comments will just say Linux but should work with most *nixes
1213f3f3 sago007 2015-09-19 19:24 68
1213f3f3 sago007 2015-09-19 19:24 69
static void throwOnRelative(const char* envName, const char* envValue) {
1213f3f3 sago007 2015-09-19 19:24 70
	if (envValue[0] != '/') {
1213f3f3 sago007 2015-09-19 19:24 71
		char buffer[200];
1213f3f3 sago007 2015-09-19 19:24 72
		snprintf(buffer, sizeof(buffer), "Environment \"%s\" does not start with an '/'. XDG specifies that the value must be absolute. The current value is: \"%s\"", envName, envValue);
1213f3f3 sago007 2015-09-19 19:24 73
		throw std::runtime_error(buffer);
1213f3f3 sago007 2015-09-19 19:24 74
	}
1213f3f3 sago007 2015-09-19 19:24 75
}
1213f3f3 sago007 2015-09-19 19:24 76
dcb0fec2 sago007 2015-09-21 17:50 77
/**
dcb0fec2 sago007 2015-09-21 17:50 78
 * Retrives the effective user's home dir. 
dcb0fec2 sago007 2015-09-21 17:50 79
 * If the user is running as root we ignore the HOME environment. It works badly with sudo. 
dcb0fec2 sago007 2015-09-21 17:50 80
 * Writing to $HOME as root implies security concerns that a multiplatform program cannot be assumed to handle.
dcb0fec2 sago007 2015-09-21 17:50 81
 * @return The home directory. HOME environment is respected for non-root users if it exists. 
dcb0fec2 sago007 2015-09-21 17:50 82
 */
1213f3f3 sago007 2015-09-19 19:24 83
static std::string getHome() {
1213f3f3 sago007 2015-09-19 19:24 84
	std::string res;
dcb0fec2 sago007 2015-09-21 17:50 85
	int uid = getuid();
dcb0fec2 sago007 2015-09-21 17:50 86
	const char* homeEnv = getenv("HOME");
dcb0fec2 sago007 2015-09-21 17:50 87
	if ( uid != 0 && homeEnv) {
dcb0fec2 sago007 2015-09-21 17:50 88
		//We only acknowlegde HOME if not root.
dcb0fec2 sago007 2015-09-21 17:50 89
		res = homeEnv;
dcb0fec2 sago007 2015-09-21 17:50 90
		return res;
dcb0fec2 sago007 2015-09-21 17:50 91
	}
dcb0fec2 sago007 2015-09-21 17:50 92
	struct passwd *pw = getpwuid(uid);
dcb0fec2 sago007 2015-09-21 17:50 93
	if (!pw) {
dcb0fec2 sago007 2015-09-21 17:50 94
		throw std::runtime_error("Unable to get passwd struct.");
dcb0fec2 sago007 2015-09-21 17:50 95
	}
dcb0fec2 sago007 2015-09-21 17:50 96
	const char* tempRes = pw->pw_dir;
1213f3f3 sago007 2015-09-19 19:24 97
	if (!tempRes) {
dcb0fec2 sago007 2015-09-21 17:50 98
		throw std::runtime_error("User has no home directory");
1213f3f3 sago007 2015-09-19 19:24 99
	}
1213f3f3 sago007 2015-09-19 19:24 100
	res = tempRes;
1213f3f3 sago007 2015-09-19 19:24 101
	return res;
1213f3f3 sago007 2015-09-19 19:24 102
}
1213f3f3 sago007 2015-09-19 19:24 103
1213f3f3 sago007 2015-09-19 19:24 104
static std::string getLinuxFolderDefault(const char* envName, const char* defaultRelativePath) {
1213f3f3 sago007 2015-09-19 19:24 105
	std::string res;
1213f3f3 sago007 2015-09-19 19:24 106
	const char* tempRes = getenv(envName);
1213f3f3 sago007 2015-09-19 19:24 107
	if (tempRes) {
1213f3f3 sago007 2015-09-19 19:24 108
		throwOnRelative(envName, tempRes);
1213f3f3 sago007 2015-09-19 19:24 109
		res = tempRes;
1213f3f3 sago007 2015-09-19 19:24 110
		return res;
1213f3f3 sago007 2015-09-19 19:24 111
	}
1213f3f3 sago007 2015-09-19 19:24 112
	res = getHome() + "/" + defaultRelativePath;
1213f3f3 sago007 2015-09-19 19:24 113
	return res;
1213f3f3 sago007 2015-09-19 19:24 114
}
1213f3f3 sago007 2015-09-19 19:24 115
1213f3f3 sago007 2015-09-19 19:24 116
static void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector<std::string>& folders) {
1213f3f3 sago007 2015-09-19 19:24 117
	char buffer[strlen(envValue)+1];
1213f3f3 sago007 2015-09-19 19:24 118
	strcpy(buffer, envValue);
1213f3f3 sago007 2015-09-19 19:24 119
	char *saveptr;
1213f3f3 sago007 2015-09-19 19:24 120
	const char* p = strtok_r (buffer, ":", &saveptr);
1213f3f3 sago007 2015-09-19 19:24 121
	while (p != NULL) {
1213f3f3 sago007 2015-09-19 19:24 122
		if (p[0] == '/') {
1213f3f3 sago007 2015-09-19 19:24 123
			folders.push_back(p);
1213f3f3 sago007 2015-09-19 19:24 124
		}
1213f3f3 sago007 2015-09-19 19:24 125
		else {
1213f3f3 sago007 2015-09-19 19:24 126
			//Unless the system is wrongly configured this should never happen... But of course some systems will be incorectly configured.
1213f3f3 sago007 2015-09-19 19:24 127
			//The XDG documentation indicates that the folder should be ignored but that the program should continue.
1213f3f3 sago007 2015-09-19 19:24 128
			std::cerr << "Skipping path \"" << p << "\" in \"" << envName << "\" because it does not start with a \"/\"" << std::endl;
1213f3f3 sago007 2015-09-19 19:24 129
		}
1213f3f3 sago007 2015-09-19 19:24 130
		p = strtok_r (NULL, ":", &saveptr);
1213f3f3 sago007 2015-09-19 19:24 131
	}
1213f3f3 sago007 2015-09-19 19:24 132
}
1213f3f3 sago007 2015-09-19 19:24 133
1213f3f3 sago007 2015-09-19 19:24 134
static void appendExtraFolders(const char* envName, const char* defaultValue, std::vector<std::string>& folders) {
1213f3f3 sago007 2015-09-19 19:24 135
	const char* envValue = getenv(envName);
1213f3f3 sago007 2015-09-19 19:24 136
	if (!envValue) {
1213f3f3 sago007 2015-09-19 19:24 137
		envValue = defaultValue;
1213f3f3 sago007 2015-09-19 19:24 138
	}
1213f3f3 sago007 2015-09-19 19:24 139
	appendExtraFoldersTokenizer(envName, envValue, folders);
1213f3f3 sago007 2015-09-19 19:24 140
}
1213f3f3 sago007 2015-09-19 19:24 141
1213f3f3 sago007 2015-09-19 19:24 142
#endif
1213f3f3 sago007 2015-09-19 19:24 143
1213f3f3 sago007 2015-09-19 19:24 144
1213f3f3 sago007 2015-09-19 19:24 145
namespace sago {
1213f3f3 sago007 2015-09-19 19:24 146
1213f3f3 sago007 2015-09-19 19:24 147
std::string getDataHome() {
1213f3f3 sago007 2015-09-19 19:24 148
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 149
	return GetAppData();
1213f3f3 sago007 2015-09-19 19:24 150
#else
1213f3f3 sago007 2015-09-19 19:24 151
	return getLinuxFolderDefault("XDG_DATA_HOME", ".local/share");
1213f3f3 sago007 2015-09-19 19:24 152
#endif
1213f3f3 sago007 2015-09-19 19:24 153
}
1213f3f3 sago007 2015-09-19 19:24 154
1213f3f3 sago007 2015-09-19 19:24 155
std::string getConfigHome() {
1213f3f3 sago007 2015-09-19 19:24 156
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 157
	return GetAppData();
1213f3f3 sago007 2015-09-19 19:24 158
#else
1213f3f3 sago007 2015-09-19 19:24 159
	return getLinuxFolderDefault("XDG_CONFIG_HOME", ".config");
1213f3f3 sago007 2015-09-19 19:24 160
#endif
1213f3f3 sago007 2015-09-19 19:24 161
}
1213f3f3 sago007 2015-09-19 19:24 162
1213f3f3 sago007 2015-09-19 19:24 163
std::string getCacheDir() {
1213f3f3 sago007 2015-09-19 19:24 164
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 165
	return GetAppDataLocal();
1213f3f3 sago007 2015-09-19 19:24 166
#else
1213f3f3 sago007 2015-09-19 19:24 167
	return getLinuxFolderDefault("XDG_CONFIG_HOME", ".cache");
1213f3f3 sago007 2015-09-19 19:24 168
#endif
1213f3f3 sago007 2015-09-19 19:24 169
}
1213f3f3 sago007 2015-09-19 19:24 170
1213f3f3 sago007 2015-09-19 19:24 171
void appendAdditionalDataDirectories(std::vector<std::string>& homes) {
1213f3f3 sago007 2015-09-19 19:24 172
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 173
	homes.push_back(GetAppDataCommon());
1213f3f3 sago007 2015-09-19 19:24 174
#else
1213f3f3 sago007 2015-09-19 19:24 175
	appendExtraFolders("XDG_DATA_DIRS", "/usr/local/share/:/usr/share/", homes);
1213f3f3 sago007 2015-09-19 19:24 176
#endif
1213f3f3 sago007 2015-09-19 19:24 177
}
1213f3f3 sago007 2015-09-19 19:24 178
1213f3f3 sago007 2015-09-19 19:24 179
void appendAdditionalConfigDirectories(std::vector<std::string>& homes) {
1213f3f3 sago007 2015-09-19 19:24 180
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 181
	homes.push_back(GetAppDataCommon());
1213f3f3 sago007 2015-09-19 19:24 182
#else
1213f3f3 sago007 2015-09-19 19:24 183
	appendExtraFolders("XDG_CONFIG_DIRS", "/etc/xdg", homes);
1213f3f3 sago007 2015-09-19 19:24 184
#endif
1213f3f3 sago007 2015-09-19 19:24 185
}
1213f3f3 sago007 2015-09-19 19:24 186
1213f3f3 sago007 2015-09-19 19:24 187
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 188
#else
1213f3f3 sago007 2015-09-19 19:24 189
struct PlatformFolders::PlatformFoldersData {
1213f3f3 sago007 2015-09-19 19:24 190
	std::map<std::string, std::string> folders;
1213f3f3 sago007 2015-09-19 19:24 191
};
1213f3f3 sago007 2015-09-19 19:24 192
1213f3f3 sago007 2015-09-19 19:24 193
static void PlatformFoldersAddFromFile(const std::string& filename, std::map<std::string, std::string>& folders) {
1213f3f3 sago007 2015-09-19 19:24 194
	std::ifstream infile(filename.c_str());
1213f3f3 sago007 2015-09-19 19:24 195
	std::string line;
1213f3f3 sago007 2015-09-19 19:24 196
	while (std::getline(infile, line)) {
1213f3f3 sago007 2015-09-19 19:24 197
		if (line.length() == 0 || line.at(0) == '#') {
1213f3f3 sago007 2015-09-19 19:24 198
			continue;
1213f3f3 sago007 2015-09-19 19:24 199
		}
1213f3f3 sago007 2015-09-19 19:24 200
		std::size_t splitPos = line.find("=");
1213f3f3 sago007 2015-09-19 19:24 201
		std::string key = line.substr(0, splitPos);
1213f3f3 sago007 2015-09-19 19:24 202
		std::string value = line.substr(splitPos+2, line.length()-splitPos-3);
1213f3f3 sago007 2015-09-19 19:24 203
		folders[key] = value;
1213f3f3 sago007 2015-09-19 19:24 204
		//std::cout << key << " : " << value << std::endl;
1213f3f3 sago007 2015-09-19 19:24 205
	}
1213f3f3 sago007 2015-09-19 19:24 206
}
1213f3f3 sago007 2015-09-19 19:24 207
1213f3f3 sago007 2015-09-19 19:24 208
static void PlatformFoldersFillData(std::map<std::string, std::string>& folders) {
1213f3f3 sago007 2015-09-19 19:24 209
	folders["XDG_DOCUMENTS_DIR"] = "$HOME/Documents";
1213f3f3 sago007 2015-09-19 19:24 210
	folders["XDG_DESKTOP_DIR"] = "$HOME/Desktop";
1213f3f3 sago007 2015-09-19 19:24 211
	folders["XDG_DOWNLOAD_DIR"] = "$HOME/Downloads";
1213f3f3 sago007 2015-09-19 19:24 212
	folders["XDG_MUSIC_DIR"] = "$HOME/Music";
1213f3f3 sago007 2015-09-19 19:24 213
	folders["XDG_PICTURES_DIR"] = "$HOME/Pictures";
1213f3f3 sago007 2015-09-19 19:24 214
	folders["XDG_PUBLICSHARE_DIR"] = "$HOME/Public";
1213f3f3 sago007 2015-09-19 19:24 215
	folders["XDG_TEMPLATES_DIR"] = "$HOME/.Templates";
1213f3f3 sago007 2015-09-19 19:24 216
	folders["XDG_VIDEOS_DIR"] = "$HOME/Videos";
1213f3f3 sago007 2015-09-19 19:24 217
	PlatformFoldersAddFromFile( getConfigHome()+"/user-dirs.dirs", folders);
1213f3f3 sago007 2015-09-19 19:24 218
	for (std::map<std::string, std::string>::iterator itr = folders.begin() ; itr != folders.end() ; itr ++ ) {
1213f3f3 sago007 2015-09-19 19:24 219
		std::string& value = itr->second;
1213f3f3 sago007 2015-09-19 19:24 220
		if (value.compare(0, 5, "$HOME") == 0) {
1213f3f3 sago007 2015-09-19 19:24 221
			value = getHome() + value.substr(5, std::string::npos);
1213f3f3 sago007 2015-09-19 19:24 222
		}
1213f3f3 sago007 2015-09-19 19:24 223
	}
1213f3f3 sago007 2015-09-19 19:24 224
}
1213f3f3 sago007 2015-09-19 19:24 225
#endif
1213f3f3 sago007 2015-09-19 19:24 226
1213f3f3 sago007 2015-09-19 19:24 227
PlatformFolders::PlatformFolders() {
1213f3f3 sago007 2015-09-19 19:24 228
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 229
#else
1213f3f3 sago007 2015-09-19 19:24 230
	this->data = new PlatformFolders::PlatformFoldersData();
1213f3f3 sago007 2015-09-19 19:24 231
	try {
1213f3f3 sago007 2015-09-19 19:24 232
		PlatformFoldersFillData(data->folders);
1213f3f3 sago007 2015-09-19 19:24 233
	} catch (...) {
1213f3f3 sago007 2015-09-19 19:24 234
		delete this->data;
1213f3f3 sago007 2015-09-19 19:24 235
		throw;
1213f3f3 sago007 2015-09-19 19:24 236
	}
1213f3f3 sago007 2015-09-19 19:24 237
#endif
1213f3f3 sago007 2015-09-19 19:24 238
}
1213f3f3 sago007 2015-09-19 19:24 239
1213f3f3 sago007 2015-09-19 19:24 240
PlatformFolders::~PlatformFolders() {
1213f3f3 sago007 2015-09-19 19:24 241
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 242
#else
1213f3f3 sago007 2015-09-19 19:24 243
	delete this->data;
1213f3f3 sago007 2015-09-19 19:24 244
#endif
1213f3f3 sago007 2015-09-19 19:24 245
}
1213f3f3 sago007 2015-09-19 19:24 246
1213f3f3 sago007 2015-09-19 19:24 247
std::string PlatformFolders::getDocumentsFolder() const {
1213f3f3 sago007 2015-09-19 19:24 248
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 249
	return GetWindowsFolder(CSIDL_PERSONAL, "Failed to find My Documents folder");
1213f3f3 sago007 2015-09-19 19:24 250
#else
1213f3f3 sago007 2015-09-19 19:24 251
	return data->folders["XDG_DOCUMENTS_DIR"];
1213f3f3 sago007 2015-09-19 19:24 252
#endif
1213f3f3 sago007 2015-09-19 19:24 253
}
1213f3f3 sago007 2015-09-19 19:24 254
1213f3f3 sago007 2015-09-19 19:24 255
std::string PlatformFolders::getDesktopFolder() const {
1213f3f3 sago007 2015-09-19 19:24 256
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 257
	return GetWindowsFolder(CSIDL_DESKTOP, "Failed to find Desktop folder");
1213f3f3 sago007 2015-09-19 19:24 258
#else
1213f3f3 sago007 2015-09-19 19:24 259
	return data->folders["XDG_DESKTOP_DIR"];
1213f3f3 sago007 2015-09-19 19:24 260
#endif
1213f3f3 sago007 2015-09-19 19:24 261
}
1213f3f3 sago007 2015-09-19 19:24 262
1213f3f3 sago007 2015-09-19 19:24 263
std::string PlatformFolders::getPicturesFolder() const {
1213f3f3 sago007 2015-09-19 19:24 264
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 265
	return GetWindowsFolder(CSIDL_MYPICTURES, "Failed to find My Pictures folder");
1213f3f3 sago007 2015-09-19 19:24 266
#else
1213f3f3 sago007 2015-09-19 19:24 267
	return data->folders["XDG_PICTURES_DIR"];
1213f3f3 sago007 2015-09-19 19:24 268
#endif
1213f3f3 sago007 2015-09-19 19:24 269
}
1213f3f3 sago007 2015-09-19 19:24 270
1213f3f3 sago007 2015-09-19 19:24 271
std::string PlatformFolders::getDownloadFolder1() const {
1213f3f3 sago007 2015-09-19 19:24 272
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 273
	//Pre Vista. Files was downloaded to the desktop
1213f3f3 sago007 2015-09-19 19:24 274
	return GetWindowsFolder(CSIDL_DESKTOP, "Failed to find My Downloads (Desktop) folder");
1213f3f3 sago007 2015-09-19 19:24 275
#else
1213f3f3 sago007 2015-09-19 19:24 276
	return data->folders["XDG_DOWNLOAD_DIR"];
1213f3f3 sago007 2015-09-19 19:24 277
#endif
1213f3f3 sago007 2015-09-19 19:24 278
}
1213f3f3 sago007 2015-09-19 19:24 279
1213f3f3 sago007 2015-09-19 19:24 280
std::string PlatformFolders::getMusicFolder() const {
1213f3f3 sago007 2015-09-19 19:24 281
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 282
	return GetWindowsFolder(CSIDL_MYMUSIC, "Failed to find My Music folder");
1213f3f3 sago007 2015-09-19 19:24 283
#else
1213f3f3 sago007 2015-09-19 19:24 284
	return data->folders["XDG_MUSIC_DIR"];
1213f3f3 sago007 2015-09-19 19:24 285
#endif
1213f3f3 sago007 2015-09-19 19:24 286
}
1213f3f3 sago007 2015-09-19 19:24 287
1213f3f3 sago007 2015-09-19 19:24 288
std::string PlatformFolders::getVideoFolder() const {
1213f3f3 sago007 2015-09-19 19:24 289
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 290
	return GetWindowsFolder(CSIDL_MYVIDEO, "Failed to find My Video folder");
1213f3f3 sago007 2015-09-19 19:24 291
#else
1213f3f3 sago007 2015-09-19 19:24 292
	return data->folders["XDG_VIDEOS_DIR"];
1213f3f3 sago007 2015-09-19 19:24 293
#endif
1213f3f3 sago007 2015-09-19 19:24 294
}
1213f3f3 sago007 2015-09-19 19:24 295
1213f3f3 sago007 2015-09-19 19:24 296
std::string PlatformFolders::getSaveGamesFolder1() const {
1213f3f3 sago007 2015-09-19 19:24 297
#if defined(_WIN32)
1213f3f3 sago007 2015-09-19 19:24 298
	//A dedicated Save Games folder was not introduced until Vista. For XP and older save games are most often saved in a normal folder named "My Games".
1213f3f3 sago007 2015-09-19 19:24 299
	//Data that should not be user accessible should be placed under GetDataHome() instead
3984e19e sago007 2015-09-20 11:12 300
	return GetWindowsFolder(CSIDL_PERSONAL, "Failed to find My Documents folder")+"\\My Games";
1213f3f3 sago007 2015-09-19 19:24 301
#else
1213f3f3 sago007 2015-09-19 19:24 302
	return getDataHome();
1213f3f3 sago007 2015-09-19 19:24 303
#endif
1213f3f3 sago007 2015-09-19 19:24 304
}
1213f3f3 sago007 2015-09-19 19:24 305
1213f3f3 sago007 2015-09-19 19:24 306
1213f3f3 sago007 2015-09-19 19:24 307
1213f3f3 sago007 2015-09-19 19:24 308
}  //namespace sago
1970-01-01 00:00 309