From fed4cb63a771200770c736e8ed637c687f244c0e Mon Sep 17 00:00:00 2001 From: chris-hawley Date: Mon, 11 Mar 2019 15:28:37 -0400 Subject: [PATCH] implement linux filesystem support --- src/xenia/app/xenia_main.cc | 2 +- src/xenia/base/filesystem_posix.cc | 41 +++++++++++++++++++++++++----- src/xenia/base/string.cc | 5 ++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/xenia/app/xenia_main.cc b/src/xenia/app/xenia_main.cc index 2597fc02f..090b6e9ed 100644 --- a/src/xenia/app/xenia_main.cc +++ b/src/xenia/app/xenia_main.cc @@ -154,7 +154,7 @@ int xenia_main(const std::vector& args) { #if defined(XE_PLATFORM_WIN32) content_root = xe::join_paths(content_root, L"Xenia"); #elif defined(XE_PLATFORM_LINUX) - content_root = xe::join_paths(content_root, L".xenia"); + content_root = xe::join_paths(content_root, L"Xenia"); #else #warning Unhandled platform for content root. content_root = xe::join_paths(content_root, L"Xenia"); diff --git a/src/xenia/base/filesystem_posix.cc b/src/xenia/base/filesystem_posix.cc index 2e81f5089..caf8219ad 100644 --- a/src/xenia/base/filesystem_posix.cc +++ b/src/xenia/base/filesystem_posix.cc @@ -12,29 +12,58 @@ #include "xenia/base/logging.h" #include "xenia/base/string.h" +#include #include #include #include +#include +#include +#include +#include #include #include #include +#include namespace xe { namespace filesystem { std::wstring GetExecutablePath() { - assert_always(); // IMPLEMENT ME. - return std::wstring(); + char buff[FILENAME_MAX] = ""; + readlink("/proc/self/exe", buff, FILENAME_MAX); + std::string s(buff); + return to_wstring(s); } std::wstring GetExecutableFolder() { - assert_always(); // IMPLEMENT ME. - return std::wstring(); + auto path = GetExecutablePath(); + return xe::find_base_path(path); } std::wstring GetUserFolder() { - assert_always(); // IMPLEMENT ME. - return std::wstring(); + // get preferred data home + char* dataHome = std::getenv("XDG_DATA_HOME"); + + // if XDG_DATA_HOME not set, fallback to HOME directory + if (dataHome == NULL) { + dataHome = std::getenv("HOME"); + } else { + std::string home(dataHome); + return to_wstring(home); + } + + // if HOME not set, fall back to this + if (dataHome == NULL) { + struct passwd pw1; + struct passwd* pw; + char buf[4096]; // could potentionally lower this + getpwuid_r(getuid(), &pw1, buf, sizeof(buf), &pw); + assert(&pw1 == pw); // sanity check + dataHome = pw->pw_dir; + } + + std::string home(dataHome); + return to_wstring(home + "/.local/share"); } bool PathExists(const std::wstring& path) { diff --git a/src/xenia/base/string.cc b/src/xenia/base/string.cc index 2e19ac856..54a8d7ebf 100644 --- a/src/xenia/base/string.cc +++ b/src/xenia/base/string.cc @@ -26,9 +26,8 @@ #else #include #endif -#elif defined( \ - _MSC_VER) // since the windows 10 sdk is required, this shouldn't be an -// issue +// since the windows 10 sdk is required, this shouldn't be an issue +#elif defined(_MSC_VER) #include #endif