widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13662
[Merge] lp:~lucki1/widelands/add-xdg-support into lp:widelands
Lucki has proposed merging lp:~lucki1/widelands/add-xdg-support into lp:widelands.
Commit message:
Add basic XDG support.
Use 'XDG_DATA_HOME/widelands' as a replacement for '~/.widelands' if '-DUSE_XDG=ON' is used as an argument for cmake.
'~/.widelands' will be used as a fallback if the folder already exists.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1725703 in widelands: "Follow XDG basedir specification"
https://bugs.launchpad.net/widelands/+bug/1725703
For more details, see:
https://code.launchpad.net/~lucki1/widelands/add-xdg-support/+merge/347652
--
Your team Widelands Developers is requested to review the proposed merge of lp:~lucki1/widelands/add-xdg-support into lp:widelands.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2018-05-16 19:37:59 +0000
+++ CMakeLists.txt 2018-06-07 21:43:45 +0000
@@ -9,6 +9,12 @@
option(OPTION_BUILD_WEBSITE_TOOLS "Build website-related tools" ON)
option(OPTION_BUILD_TRANSLATIONS "Build translations" ON)
+option(USE_XDG "Follow XDG-Basedir specification" OFF) # Disabled by default
+IF(USE_XDG AND NOT APPLE AND NOT WIN32)
+ ADD_DEFINITIONS(-DUSE_XDG)
+ message(STATUS "Building with XDG support.")
+ENDIF(USE_XDG AND NOT APPLE AND NOT WIN32)
+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Build directory and source directory must not be the same.")
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
=== modified file 'src/io/filesystem/filesystem.cc'
--- src/io/filesystem/filesystem.cc 2018-06-06 19:45:06 +0000
+++ src/io/filesystem/filesystem.cc 2018-06-07 21:43:45 +0000
@@ -262,6 +262,51 @@
return homedir;
}
+std::string FileSystem::get_xdgdir() {
+ std::string xdgdir;
+#ifdef HAS_GETENV
+ if (char const* const h = getenv("HOME")) {
+ if (char const* const x = getenv("XDG_DATA_HOME")) {
+ xdgdir = x;
+
+ // Unlike the other function, this function returns the program name
+ // with. This is handled in 'src/wlapplication.cc'.
+ xdgdir = xdgdir + "/widelands";
+ }
+ else {
+ // If XDG_DATA_HOME is not set, the default path is used.
+ xdgdir = h;
+ xdgdir = xdgdir + "/.local/share";
+
+ // Unlike the other function, this function returns the program name
+ // with. This is handled in 'src/wlapplication.cc'.
+ xdgdir = xdgdir + "/widelands";
+ }
+
+ // Use dotfolder for backwards compatibility if it exists.
+ RealFSImpl dot(h);
+ if (dot.is_directory(".widelands")) {
+ xdgdir = h;
+
+ // Unlike the other function, this function returns the program name
+ // with. This is handled in 'src/wlapplication.cc'.
+ xdgdir = xdgdir + "/.widelands";
+ }
+ }
+#endif
+
+ if (xdgdir.empty()) {
+ log("\nWARNING: either we can not detect your XDG or home directory "
+ "or you do not have one! Please contact the developers.\n\n");
+
+ // TODO(unknown): is it really a good idea to set xdgdir to "." then ??
+ log("Instead of your XDG or home directory, '.' will be used.\n\n");
+ xdgdir = "./.widelands";
+ }
+
+ return xdgdir;
+}
+
/**
* Split a string into components separated by a certain character.
*
=== modified file 'src/io/filesystem/filesystem.h'
--- src/io/filesystem/filesystem.h 2018-05-17 05:01:45 +0000
+++ src/io/filesystem/filesystem.h 2018-06-07 21:43:45 +0000
@@ -131,6 +131,7 @@
/// Given a filename, return the name with any path or extension stripped off.
static std::string filename_without_ext(const char* n);
static std::string get_homedir();
+ static std::string get_xdgdir();
virtual unsigned long long disk_space() = 0;
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2018-05-03 18:52:48 +0000
+++ src/wlapplication.cc 2018-06-07 21:43:45 +0000
@@ -287,6 +287,10 @@
should_die_(false),
#ifdef _WIN32
homedir_(FileSystem::get_homedir() + "\\.widelands"),
+#elif USE_XDG
+ // To enable backwards compatibility, the program name is passed with the
+ // path.
+ homedir_(FileSystem::get_xdgdir()),
#else
homedir_(FileSystem::get_homedir() + "/.widelands"),
#endif
Follow ups