mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
commit
f194a95522
3 changed files with 25 additions and 99 deletions
|
@ -1,110 +1,58 @@
|
|||
#include "androidpath.hpp"
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#if defined(__ANDROID__)
|
||||
|
||||
#include <jni.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <pwd.h>
|
||||
#include "androidpath.h"
|
||||
#include <unistd.h>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
|
||||
class Buffer {
|
||||
public:
|
||||
static void setData(char const *data);
|
||||
static char const * getData();
|
||||
};
|
||||
static char const *path;
|
||||
|
||||
void Buffer::setData(char const *data)
|
||||
{
|
||||
path=data;
|
||||
}
|
||||
char const * Buffer::getData()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_ui_activity_GameActivity_getPathToJni(JNIEnv *env, jobject obj, jstring prompt)
|
||||
{
|
||||
jboolean iscopy;
|
||||
Buffer::setData((env)->GetStringUTFChars(prompt, &iscopy));
|
||||
(env)->DeleteLocalRef(prompt);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
boost::filesystem::path getUserHome()
|
||||
{
|
||||
const char* dir = getenv("HOME");
|
||||
if (dir == nullptr)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
if (pwd != nullptr)
|
||||
{
|
||||
dir = pwd->pw_dir;
|
||||
}
|
||||
}
|
||||
if (dir == nullptr)
|
||||
return boost::filesystem::path();
|
||||
else
|
||||
return boost::filesystem::path(dir);
|
||||
}
|
||||
|
||||
boost::filesystem::path getEnv(const std::string& envVariable, const boost::filesystem::path& fallback)
|
||||
{
|
||||
const char* result = getenv(envVariable.c_str());
|
||||
if (!result)
|
||||
return fallback;
|
||||
boost::filesystem::path dir(result);
|
||||
if (dir.empty())
|
||||
return fallback;
|
||||
else
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
static const char *g_path_global; //< Path to global directory root, e.g. /data/data/com.libopenmw.openmw
|
||||
static const char *g_path_user; //< Path to user root, e.g. /sdcard/Android/data/com.libopenmw.openmw
|
||||
|
||||
/**
|
||||
* \namespace Files
|
||||
* \brief Called by java code to set up directory paths
|
||||
*/
|
||||
extern "C" JNIEXPORT void JNICALL Java_ui_activity_GameActivity_getPathToJni(JNIEnv *env, jobject obj, jstring global, jstring user)
|
||||
{
|
||||
g_path_global = env->GetStringUTFChars(global, nullptr);
|
||||
g_path_user = env->GetStringUTFChars(user, nullptr);
|
||||
}
|
||||
|
||||
namespace Files
|
||||
{
|
||||
|
||||
AndroidPath::AndroidPath(const std::string& application_name)
|
||||
: mName(application_name)
|
||||
{
|
||||
}
|
||||
|
||||
// /sdcard/Android/data/com.libopenmw.openmw/config
|
||||
boost::filesystem::path AndroidPath::getUserConfigPath() const
|
||||
{
|
||||
std::string buffer = "";
|
||||
buffer = buffer + Buffer::getData() +"/config";
|
||||
return getEnv("XDG_CONFIG_HOME", buffer) / mName;
|
||||
return boost::filesystem::path(g_path_user) / "config";
|
||||
}
|
||||
|
||||
// /sdcard/Android/data/com.libopenmw.openmw/
|
||||
// (so that saves are placed at /sdcard/Android/data/com.libopenmw.openmw/saves)
|
||||
boost::filesystem::path AndroidPath::getUserDataPath() const
|
||||
{
|
||||
std::string buffer = "";
|
||||
buffer = buffer + Buffer::getData() +"/share";
|
||||
return getEnv("XDG_DATA_HOME", buffer) / mName;
|
||||
return boost::filesystem::path(g_path_user);
|
||||
}
|
||||
|
||||
// /data/data/com.libopenmw.openmw/cache
|
||||
// (supposed to be "official" android cache location)
|
||||
boost::filesystem::path AndroidPath::getCachePath() const
|
||||
{
|
||||
std::string buffer = "";
|
||||
buffer = buffer + Buffer::getData() +"/cache";
|
||||
return getEnv("XDG_CACHE_HOME", buffer) / mName;
|
||||
return boost::filesystem::path(g_path_global) / "cache";
|
||||
}
|
||||
|
||||
// /data/data/com.libopenmw.openmw/files/config
|
||||
// (note the addition of "files")
|
||||
boost::filesystem::path AndroidPath::getGlobalConfigPath() const
|
||||
{
|
||||
std::string buffer = "";
|
||||
buffer = buffer + Buffer::getData() +"/";
|
||||
boost::filesystem::path globalPath(buffer);
|
||||
return globalPath / mName;
|
||||
return boost::filesystem::path(g_path_global) / "files" / "config";
|
||||
}
|
||||
|
||||
boost::filesystem::path AndroidPath::getLocalPath() const
|
||||
|
@ -112,12 +60,11 @@ boost::filesystem::path AndroidPath::getLocalPath() const
|
|||
return boost::filesystem::path("./");
|
||||
}
|
||||
|
||||
// /sdcard/Android/data/com.libopenmw.openmw
|
||||
// (so that the data is at /sdcard/Android/data/com.libopenmw.openmw/data)
|
||||
boost::filesystem::path AndroidPath::getGlobalDataPath() const
|
||||
{
|
||||
std::string buffer = "";
|
||||
buffer = buffer + Buffer::getData() +"/data";
|
||||
boost::filesystem::path globalDataPath(buffer);
|
||||
return globalDataPath / mName;
|
||||
return boost::filesystem::path(g_path_user);
|
||||
}
|
||||
|
||||
boost::filesystem::path AndroidPath::getInstallPath() const
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
|
||||
#ifndef _Included_ui_activity_GameActivity_getPathToJni
|
||||
#define _Included_ui_activity_GameActivity_getPathToJni
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: Java_org_libsdl_app_SDLActivity_getPathToJni
|
||||
* Method: getPathToJni
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_ui_activity_GameActivity_getPathToJni(JNIEnv *env, jobject obj, jstring prompt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -46,8 +46,6 @@ struct AndroidPath
|
|||
boost::filesystem::path getCachePath() const;
|
||||
|
||||
boost::filesystem::path getInstallPath() const;
|
||||
|
||||
std::string mName;
|
||||
};
|
||||
|
||||
} /* namespace Files */
|
||||
|
|
Loading…
Reference in a new issue