From 2fd47ba0d04a44c58442413feffd74eca4df4972 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 10 May 2020 12:48:32 +0200 Subject: [PATCH] Keep searching in $HOME --- src/readline.cpp | 8 ++++++-- src/sdcv.cpp | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/readline.cpp b/src/readline.cpp index b7c3461..2204c17 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -68,8 +68,12 @@ std::string get_hist_file_path() if (hist_file_str != nullptr) return std::string(hist_file_str); - else - return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history"; + + const std::string hist_file_path = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; + if (g_file_test(hist_file_path.c_str(), G_FILE_TEST_IS_REGULAR)) + return hist_file_path; + + return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history"; } class real_readline : public IReadLine diff --git a/src/sdcv.cpp b/src/sdcv.cpp index 6b08b91..16466ad 100644 --- a/src/sdcv.cpp +++ b/src/sdcv.cpp @@ -141,9 +141,13 @@ int main(int argc, char *argv[]) try { data_dir = get_impl(opt_data_dir); } + std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict"; + if (!g_file_test(conf_dir.c_str(), G_FILE_TEST_IS_DIR)) + conf_dir = std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict"; + std::list dicts_dir_list; if (!only_data_dir) - dicts_dir_list.push_back(std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict" + G_DIR_SEPARATOR + "dic"); + dicts_dir_list.push_back(conf_dir + G_DIR_SEPARATOR + "dic"); dicts_dir_list.push_back(data_dir); if (show_list_dicts) { list_dicts(dicts_dir_list, json_output); @@ -182,8 +186,12 @@ int main(int argc, char *argv[]) try { ++p; } } else { - const std::string odering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering"; - FILE *ordering_file = fopen(odering_cfg_file.c_str(), "r"); + std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering"; + FILE *ordering_file = fopen(ordering_cfg_file.c_str(), "r"); + if (ordering_file == nullptr) { + ordering_cfg_file = std::string(g_get_home_dir()) + G_DIR_SEPARATOR_S ".sdcv_ordering"; + ordering_file = fopen(ordering_cfg_file.c_str(), "r"); + } if (ordering_file != nullptr) { std::string line; while (stdio_getline(ordering_file, line)) { @@ -193,7 +201,6 @@ int main(int argc, char *argv[]) try { } } - const std::string conf_dir = std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict"; if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) { fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); }