From 1c19f418c60b8fb75d98bd8d56583d2d4a6f3331 Mon Sep 17 00:00:00 2001 From: soft as HELL Date: Mon, 15 Apr 2019 19:25:54 +0300 Subject: [PATCH] Respect XDG_DATA_HOME --- dll/local_storage.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 62e0b43..a99af35 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -408,9 +408,17 @@ std::string Local_Storage::get_user_appdata_path() } #else - char *homedir = getenv("HOME"); - if (homedir) { - user_appdata_path = homedir; + /* $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. + If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. */ + char *datadir = getenv("XDG_DATA_HOME"); + if (datadir) { + user_appdata_path = datadir; + } else { + char *homedir = getenv("HOME"); + if (homedir) { + user_appdata_path = homedir; + user_appdata_path.append(PATH_SEPARATOR).append(".local").append(PATH_SEPARATOR).append("share"); + } } #endif return user_appdata_path.append(PATH_SEPARATOR).append(PROGRAM_NAME).append(" Saves");