aboutsummaryrefslogtreecommitdiff
path: root/include/Utils.hpp
blob: 8ca38b58c26bdd7579f98bf469d53b277503c636 (plain)
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
32
33
34
35
36
37
#pragma once

#include <functional>
#include <string_view>
#include <map>
#include <string>
#include <optional>

namespace gsr {
    struct KeyValue {
        std::string_view key;
        std::string_view value;
    };

    using StringSplitCallback = std::function<bool(std::string_view line)>;

    void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func);

    std::string get_home_dir();
    std::string get_config_dir();

    // Whoever designed xdg-user-dirs is retarded. Why are some XDG variables environment variables
    // while others are in this pseudo shell config file ~/.config/user-dirs.dirs
    std::map<std::string, std::string> get_xdg_variables();

    std::string get_videos_dir();
    // Returns 0 on success
    int create_directory_recursive(char *path);
    bool file_get_content(const char *filepath, std::string &file_content);
    bool file_overwrite(const char *filepath, const std::string &data);

    // Returns the path to the parent directory (ignoring trailing /)
    // of "." if there is no parent directory and the directory path is relative
    std::string get_parent_directory(std::string_view directory);

    std::optional<std::string> get_gsr_runtime_dir();
}