Keep searching in $HOME

This commit is contained in:
Guido Cella
2020-05-10 12:48:32 +02:00
parent 3413d847c5
commit 2fd47ba0d0
2 changed files with 17 additions and 6 deletions

View File

@@ -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

View File

@@ -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<std::string> 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));
}