Merge pull request #1316 from chris-hawley/master

[Base] Remove hacky fix for missing codecvt on linux.
This commit is contained in:
Rick Gibbed 2019-05-04 11:40:33 -05:00 committed by GitHub
commit 00e061c4e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 10 deletions

View File

@ -154,7 +154,7 @@ int xenia_main(const std::vector<std::wstring>& args) {
#if defined(XE_PLATFORM_WIN32) #if defined(XE_PLATFORM_WIN32)
content_root = xe::join_paths(content_root, L"Xenia"); content_root = xe::join_paths(content_root, L"Xenia");
#elif defined(XE_PLATFORM_LINUX) #elif defined(XE_PLATFORM_LINUX)
content_root = xe::join_paths(content_root, L".xenia"); content_root = xe::join_paths(content_root, L"Xenia");
#else #else
#warning Unhandled platform for content root. #warning Unhandled platform for content root.
content_root = xe::join_paths(content_root, L"Xenia"); content_root = xe::join_paths(content_root, L"Xenia");

View File

@ -12,29 +12,58 @@
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include <assert.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#include <ftw.h> #include <ftw.h>
#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <iostream>
namespace xe { namespace xe {
namespace filesystem { namespace filesystem {
std::wstring GetExecutablePath() { std::wstring GetExecutablePath() {
assert_always(); // IMPLEMENT ME. char buff[FILENAME_MAX] = "";
return std::wstring(); readlink("/proc/self/exe", buff, FILENAME_MAX);
std::string s(buff);
return to_wstring(s);
} }
std::wstring GetExecutableFolder() { std::wstring GetExecutableFolder() {
assert_always(); // IMPLEMENT ME. auto path = GetExecutablePath();
return std::wstring(); return xe::find_base_path(path);
} }
std::wstring GetUserFolder() { std::wstring GetUserFolder() {
assert_always(); // IMPLEMENT ME. // get preferred data home
return std::wstring(); 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) { bool PathExists(const std::wstring& path) {

View File

@ -9,12 +9,27 @@
#include "xenia/base/string.h" #include "xenia/base/string.h"
// TODO(benvanik): when GCC finally gets codecvt, use that. // codecvt existence check
#if XE_PLATFORM_LINUX #ifdef __clang__
// using clang
#if (__clang_major__ < 4) // 3.3 has it but I think we need at least 4 anyway
// insufficient clang version
#define NO_CODECVT 1 #define NO_CODECVT 1
#else #else
#include <codecvt> #include <codecvt>
#endif // XE_PLATFORM_LINUX #endif
#elif defined(__GNUC__) || defined(__GNUG__)
// using gcc
#if (__GNUC__ < 5)
// insufficient clang version
#define NO_CODECVT 1
#else
#include <codecvt>
#endif
// since the windows 10 sdk is required, this shouldn't be an issue
#elif defined(_MSC_VER)
#include <codecvt>
#endif
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>