2 * This file is part of DisOrder
3 * Copyright (C) 2020 Mark Wooding
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @brief Find things in the user's home directory
47 static char *profiledir;
50 /** @brief Return the user's profile directory
51 * @return profile directory
52 * On Unix, this defaults to `$HOME/.disorder/'; on Windows, it's
53 * `%APPDATA%\DisOrder\'. The trailing delimiter is included.
55 const char *profile_directory(void) {
58 if(profiledir) return profiledir;
62 if(SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wpath) != S_OK) {
63 disorder_error(0, "error calling SHGetKnownFolderPath");
68 byte_xasprintf(&profiledir, "%s\\DisOrder", appdata);
71 if(!(t = getenv("HOME"))) {
72 if(!(pw = getpwuid(getuid())))
73 disorder_error(0, "user not found in password database");
76 byte_xasprintf(&profiledir, "%s/.disorder", t);
81 /** @brief Return the name of a file within the user's profile directory
82 * @param file Basename of the file desired
83 * @return Full path name of selected file.
84 * This currently doesn't do anything very useful with directory separators
87 char *profile_filename(const char *file) {
90 if(!(d = profile_directory())) return 0;
91 byte_xasprintf(&t, "%s" DIRSEP "%s", d, file);