Comply with the XDG Base Directory Specification

This commit is contained in:
Guido Cella
2020-05-10 07:01:31 +02:00
parent 780b7dd214
commit 3413d847c5
9 changed files with 21 additions and 26 deletions

View File

@@ -69,7 +69,7 @@ std::string get_hist_file_path()
if (hist_file_str != nullptr)
return std::string(hist_file_str);
else
return std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history";
return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history";
}
class real_readline : public IReadLine

View File

@@ -141,13 +141,9 @@ int main(int argc, char *argv[]) try {
data_dir = get_impl(opt_data_dir);
}
const char *homedir = g_getenv("HOME");
if (!homedir)
homedir = g_get_home_dir();
std::list<std::string> dicts_dir_list;
if (!only_data_dir)
dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic");
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(data_dir);
if (show_list_dicts) {
list_dicts(dicts_dir_list, json_output);
@@ -186,7 +182,7 @@ int main(int argc, char *argv[]) try {
++p;
}
} else {
const std::string odering_cfg_file = std::string(homedir) + G_DIR_SEPARATOR_S ".sdcv_ordering";
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");
if (ordering_file != nullptr) {
std::string line;
@@ -197,7 +193,7 @@ int main(int argc, char *argv[]) try {
}
}
const std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict";
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));
}