folders.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <planet/folders.hpp>


namespace {
    char const *safe_getenv(char const *env) {
        char const *value = std::getenv(env);
        if (value) {
            return value;
        } else {
            return "";
        }
    }
}


std::filesystem::path planet::base_storage_folder() {
    std::filesystem::path home;
#ifdef _WIN32
    home = safe_getenv("APPDATA");
#else
    home = safe_getenv("HOME");
#endif
    if (home.empty()) {
        home = std::filesystem::current_path();
    } else {
#ifndef _WIN32
        home /= ".local/share";
#endif
    }
    return home;
}