diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-08-16 22:16:35 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-08-16 22:18:24 +0200 |
commit | f68aaa4e778c6cb1ea86f4daae0f8fae95ca3414 (patch) | |
tree | 825ad936fb0a25bab58c62ebd7022ea3c21d38e0 | |
parent | 5cc735b22570f1667d62958e59ce4910b529f5af (diff) |
Use xdg env
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 5 | ||||
-rw-r--r-- | src/Storage.cpp | 27 |
3 files changed, 32 insertions, 4 deletions
@@ -1,8 +1,8 @@ # QuickMedia A dmenu-inspired native client for web services. Currently supported web services: `youtube`, `soundcloud`, `nyaa.si`, `manganelo`, `manganelos`, `mangatown`, `mangakatana`, `mangadex`, `readm`, `onimanga`, `4chan`, `matrix`, `saucenao`, `hotexamples`, `mal` and _others_.\ -Config data, including manga progress is stored under `$HOME/.config/quickmedia`.\ -Cache is stored under `$HOME/.cache/quickmedia`. +Config data, including manga progress is stored under `$XDG_CONFIG_HOME/quickmedia` or `$HOME/.config/quickmedia`.\ +Cache is stored under `$XDG_CACHE_HOME/quickmedia` or `$HOME/.cache/quickmedia`. ## Usage ``` usage: quickmedia [plugin] [--use-system-mpv-config] [--dir <directory>] [-e <window>] [youtube-url] diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 9b982a1..e6c642d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -734,6 +734,11 @@ namespace QuickMedia { abort(); } + if(create_directory_recursive(get_storage_dir()) != 0) { + show_notification("QuickMedia", "Failed to create storage directory", Urgency::CRITICAL); + abort(); + } + //if(create_directory_recursive(get_storage_dir().join("file-manager")) != 0) { // show_notification("QuickMedia", "Failed to create file-manager directory", Urgency::CRITICAL); // abort(); diff --git a/src/Storage.cpp b/src/Storage.cpp index 375be57..4baca49 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -82,12 +82,35 @@ namespace QuickMedia { return homeDir; } + static Path xdg_config_home; + static Path xdg_cache_home; + Path get_storage_dir() { - return get_home_dir().join(".config").join("quickmedia"); + if(xdg_config_home.data.empty()) { + const char *xdg_config_home_p = getenv("XDG_CONFIG_HOME"); + if(xdg_config_home_p) + xdg_config_home = xdg_config_home_p; + else + xdg_config_home = get_home_dir().join(".config"); + } + + Path storage_dir = xdg_config_home; + storage_dir.join("quickmedia"); + return storage_dir; } Path get_cache_dir() { - return get_home_dir().join(".cache").join("quickmedia"); + if(xdg_cache_home.data.empty()) { + const char *xdg_cache_home_p = getenv("XDG_CACHE_HOME"); + if(xdg_cache_home_p) + xdg_cache_home = xdg_cache_home_p; + else + xdg_cache_home = get_home_dir().join(".cache"); + } + + Path cache_dir = xdg_cache_home; + cache_dir.join("quickmedia"); + return cache_dir; } int get_cookies_filepath(Path &path, const std::string &plugin_name) { |