mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 19:45:34 +00:00
commit
f194a95522
3 changed files with 25 additions and 99 deletions
|
@ -2,109 +2,57 @@
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include "androidpath.h"
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
|
static const char *g_path_global; //< Path to global directory root, e.g. /data/data/com.libopenmw.openmw
|
||||||
class Buffer {
|
static const char *g_path_user; //< Path to user root, e.g. /sdcard/Android/data/com.libopenmw.openmw
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \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
|
namespace Files
|
||||||
{
|
{
|
||||||
|
|
||||||
AndroidPath::AndroidPath(const std::string& application_name)
|
AndroidPath::AndroidPath(const std::string& application_name)
|
||||||
: mName(application_name)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /sdcard/Android/data/com.libopenmw.openmw/config
|
||||||
boost::filesystem::path AndroidPath::getUserConfigPath() const
|
boost::filesystem::path AndroidPath::getUserConfigPath() const
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
return boost::filesystem::path(g_path_user) / "config";
|
||||||
buffer = buffer + Buffer::getData() +"/config";
|
|
||||||
return getEnv("XDG_CONFIG_HOME", buffer) / mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /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
|
boost::filesystem::path AndroidPath::getUserDataPath() const
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
return boost::filesystem::path(g_path_user);
|
||||||
buffer = buffer + Buffer::getData() +"/share";
|
|
||||||
return getEnv("XDG_DATA_HOME", buffer) / mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /data/data/com.libopenmw.openmw/cache
|
||||||
|
// (supposed to be "official" android cache location)
|
||||||
boost::filesystem::path AndroidPath::getCachePath() const
|
boost::filesystem::path AndroidPath::getCachePath() const
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
return boost::filesystem::path(g_path_global) / "cache";
|
||||||
buffer = buffer + Buffer::getData() +"/cache";
|
|
||||||
return getEnv("XDG_CACHE_HOME", buffer) / mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /data/data/com.libopenmw.openmw/files/config
|
||||||
|
// (note the addition of "files")
|
||||||
boost::filesystem::path AndroidPath::getGlobalConfigPath() const
|
boost::filesystem::path AndroidPath::getGlobalConfigPath() const
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
return boost::filesystem::path(g_path_global) / "files" / "config";
|
||||||
buffer = buffer + Buffer::getData() +"/";
|
|
||||||
boost::filesystem::path globalPath(buffer);
|
|
||||||
return globalPath / mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path AndroidPath::getLocalPath() const
|
boost::filesystem::path AndroidPath::getLocalPath() const
|
||||||
|
@ -112,12 +60,11 @@ boost::filesystem::path AndroidPath::getLocalPath() const
|
||||||
return boost::filesystem::path("./");
|
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
|
boost::filesystem::path AndroidPath::getGlobalDataPath() const
|
||||||
{
|
{
|
||||||
std::string buffer = "";
|
return boost::filesystem::path(g_path_user);
|
||||||
buffer = buffer + Buffer::getData() +"/data";
|
|
||||||
boost::filesystem::path globalDataPath(buffer);
|
|
||||||
return globalDataPath / mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem::path AndroidPath::getInstallPath() const
|
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 getCachePath() const;
|
||||||
|
|
||||||
boost::filesystem::path getInstallPath() const;
|
boost::filesystem::path getInstallPath() const;
|
||||||
|
|
||||||
std::string mName;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace Files */
|
} /* namespace Files */
|
||||||
|
|
Loading…
Reference in a new issue