Parcourir la source

Common paths for each system

default_compile_flags
vector-of-bool il y a 5 ans
Parent
révision
15ea091f2e
4 fichiers modifiés avec 144 ajouts et 0 suppressions
  1. +16
    -0
      src/dds/util/paths.hpp
  2. +56
    -0
      src/dds/util/paths.linux.cpp
  3. +27
    -0
      src/dds/util/paths.macos.cpp
  4. +45
    -0
      src/dds/util/paths.win.cpp

+ 16
- 0
src/dds/util/paths.hpp Voir le fichier

@@ -0,0 +1,16 @@
#pragma once

#include <dds/util/fs.hpp>

namespace dds {

fs::path user_home_dir();
fs::path user_data_dir();
fs::path user_cache_dir();
fs::path user_config_dir();

inline fs::path dds_data_dir() { return user_data_dir() / "ddslim"; }
inline fs::path dds_cache_dir() { return user_cache_dir() / "ddslim-cache"; }
inline fs::path dds_config_dir() { return user_config_dir() / "ddslim"; }

} // namespace dds

+ 56
- 0
src/dds/util/paths.linux.cpp Voir le fichier

@@ -0,0 +1,56 @@
#ifdef __linux__

#include "./paths.hpp"

#include <spdlog/spdlog.h>

#include <cstdlib>

using namespace dds;

fs::path dds::user_home_dir() {
static auto ret = []() -> fs::path {
auto home_env = std::getenv("HOME");
if (!home_env) {
spdlog::warn("No HOME environment variable set!");
return "/";
}
return fs::absolute(fs::path(home_env));
}();
return ret;
}

fs::path dds::user_data_dir() {
static auto ret = []() -> fs::path {
auto xdg_data_home = std::getenv("XDG_DATA_HOME");
if (xdg_data_home) {
return fs::absolute(fs::path(xdg_data_home));
}
return user_home_dir() / ".local/share";
}();
return ret;
}

fs::path dds::user_cache_dir() {
static auto ret = []() -> fs::path {
auto xdg_cache_home = std::getenv("XDG_CACHE_HOME");
if (xdg_cache_home) {
return fs::absolute(fs::path(xdg_cache_home));
}
return user_home_dir() / ".cache";
}();
return ret;
}

fs::path dds::user_config_dir() {
static auto ret = []() -> fs::path {
auto xdg_config_home = std::getenv("XDG_CONFIG_HOME");
if (xdg_config_home) {
return fs::absolute(fs::path(xdg_config_home));
}
return user_home_dir() / ".config";
}();
return ret;
}

#endif

+ 27
- 0
src/dds/util/paths.macos.cpp Voir le fichier

@@ -0,0 +1,27 @@
#ifdef __APPLE__

#include "./paths.hpp"

#include <spdlog/spdlog.h>

#include <cstdlib>

using namespace dds;

fs::path dds::user_home_dir() {
static auto ret = []() -> fs::path {
auto home_env = std::getenv("HOME");
if (!home_env) {
spdlog::warn("No HOME environment variable set!");
return "/";
}
return fs::absolute(fs::path(home_env));
}();
return ret;
}

fs::path dds::user_data_dir() { return user_home_dir() / "Library/Application Support"; }
fs::path dds::user_cache_dir() { return user_home_dir() / "Library/Caches"; }
fs::path dds::user_config_dir() { return user_home_dir() / "Preferences"; }

#endif

+ 45
- 0
src/dds/util/paths.win.cpp Voir le fichier

@@ -0,0 +1,45 @@
#ifdef _WIN32

#include "./paths.hpp"

#include <spdlog/spdlog.h>

#include <cstdlib>

using namespace dds;

fs::path dds::user_home_dir() {
static auto ret = []() -> fs::path {
auto userprofile_env = std::getenv("USERPROFILE");
if (!userprofile_env) {
spdlog::warn("No USERPROFILE environment variable set!");
return "/";
}
return fs::absolute(fs::path(userprofile_env));
}();
return ret;
}

namespace {

fs::path appdatalocal_dir() {
auto env = std::getenv("LocalAppData");
assert(env);

return fs::absolute(fs::path(env));
}

fs::path appdata_dir() {
auto env = std::getenv("LocalAppData");
assert(env);

return fs::absolute(fs::path(env));
}

} // namespace

fs::path dds::user_data_dir() { return appdata_local_dir(); }
fs::path dds::user_cache_dir() { return appdata_local_dir(); }
fs::path dds::user_config_dir() { return appdata_dir(); }

#endif

Chargement…
Annuler
Enregistrer