MCPcopy Create free account
hub / github.com/ddnet/ddnet / fs_storage_path

Function fs_storage_path

src/base/fs.cpp:286–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286int fs_storage_path(const char *appname, char *path, int max)
287{
288#if defined(CONF_FAMILY_WINDOWS)
289 WCHAR *wide_home = nullptr;
290 if(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, /* current user */ nullptr, &wide_home) != S_OK)
291 {
292 log_error("filesystem", "ERROR: could not determine location of Roaming/AppData folder");
293 CoTaskMemFree(wide_home);
294 path[0] = '\0';
295 return -1;
296 }
297 const std::optional<std::string> home = windows_wide_to_utf8(wide_home);
298 CoTaskMemFree(wide_home);
299 if(!home.has_value())
300 {
301 log_error("filesystem", "ERROR: path of Roaming/AppData folder contains invalid UTF-16");
302 path[0] = '\0';
303 return -1;
304 }
305 str_copy(path, home.value().c_str(), max);
306 fs_normalize_path(path);
307 str_append(path, "/", max);
308 str_append(path, appname, max);
309 return 0;
310#else
311 char *home = getenv("HOME");
312 if(!home)
313 {
314 path[0] = '\0';
315 return -1;
316 }
317
318 if(!str_utf8_check(home))
319 {
320 log_error("filesystem", "ERROR: the HOME environment variable contains invalid UTF-8");
321 path[0] = '\0';
322 return -1;
323 }
324
325#if defined(CONF_PLATFORM_HAIKU)
326 str_format(path, max, "%s/config/settings/%s", home, appname);
327#elif defined(CONF_PLATFORM_MACOS)
328 str_format(path, max, "%s/Library/Application Support/%s", home, appname);
329#else
330 if(str_comp(appname, "Teeworlds") == 0)
331 {
332 // fallback for old directory for Teeworlds compatibility
333 str_format(path, max, "%s/.%s", home, appname);
334 }
335 else
336 {
337 char *data_home = getenv("XDG_DATA_HOME");
338 if(data_home)
339 {
340 if(!str_utf8_check(data_home))
341 {
342 log_error("filesystem", "ERROR: the XDG_DATA_HOME environment variable contains invalid UTF-8");
343 path[0] = '\0';

Callers 2

FindUserDirectoryMethod · 0.85
TESTFunction · 0.85

Calls 8

windows_wide_to_utf8Function · 0.85
fs_normalize_pathFunction · 0.85
str_utf8_checkFunction · 0.85
str_formatFunction · 0.85
str_compFunction · 0.85
str_lengthFunction · 0.85
str_copyFunction · 0.70
str_appendFunction · 0.70

Tested by 1

TESTFunction · 0.68