From 263f007d5c5246f72ea16805becc188bf1299735 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 5 Jun 2022 12:00:58 +0800 Subject: [PATCH] [gnc-filepath-utils] new: gnc_list_all_paths --- libgnucash/core-utils/gnc-filepath-utils.cpp | 23 ++++++++++++++++++++ libgnucash/core-utils/gnc-filepath-utils.h | 18 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp index 34f482d4ca..e16d908835 100644 --- a/libgnucash/core-utils/gnc-filepath-utils.cpp +++ b/libgnucash/core-utils/gnc-filepath-utils.cpp @@ -69,6 +69,7 @@ extern "C" { #include #include #include +#include /* Below cvt and bfs_locale should be used with boost::filesystem::path (bfs) * objects created alter in this source file. The rationale is as follows: @@ -1306,5 +1307,27 @@ gnc_filepath_locate_doc_file (const gchar *name) return result; } +GList * +gnc_list_all_paths (void) +{ + if (gnc_userdata_home.empty()) + gnc_filepath_init (); + + std::vector paths + { { "GNC_USERDATA_DIR", gnc_userdata_home_str.c_str(), true}, + { "GNC_USERCONFIG_DIR", gnc_userconfig_home_str.c_str(), true }, + { "GNC_BIN", g_getenv ("GNC_BIN"), false }, + { "GNC_LIB", g_getenv ("GNC_LIB"), false }, + { "GNC_CONF", g_getenv ("GNC_CONF"), false }, + { "GNC_DATA", g_getenv ("GNC_DATA"), false }, + }; + auto accum = [](const auto& a, const auto& b) + { + EnvPaths *ep = g_new0 (EnvPaths, 1); + *ep = b; + return g_list_prepend (a, ep); + }; + return std::accumulate (paths.rbegin(), paths.rend(), (GList*) nullptr, accum); +} /* =============================== END OF FILE ========================== */ diff --git a/libgnucash/core-utils/gnc-filepath-utils.h b/libgnucash/core-utils/gnc-filepath-utils.h index f88cd32050..57e1ddf777 100644 --- a/libgnucash/core-utils/gnc-filepath-utils.h +++ b/libgnucash/core-utils/gnc-filepath-utils.h @@ -172,4 +172,22 @@ gchar *gnc_filepath_locate_ui_file (const gchar *name); */ gchar *gnc_filepath_locate_doc_file (const gchar *name); +typedef struct +{ + const gchar *env_name; + const gchar *env_path; + gboolean modifiable; +} EnvPaths; + + +/** Returns a GList* of the environment variables used by GnuCash. + * + * @return a GList* of EnvPaths structs, describing the environment + * variables used by GnuCash. + * + * @note It is the caller's responsibility to free the GList with + * g_list_free_full (paths, g_free) + */ +GList *gnc_list_all_paths (void); + #endif /* GNC_FILEPATH_UTILS_H */