Don't hardcode stk data dir on android

This commit is contained in:
Deve 2018-02-03 22:16:06 +01:00
parent 01c2680f73
commit ff884852d7
3 changed files with 38 additions and 17 deletions

View File

@ -162,6 +162,8 @@ LOCAL_CFLAGS := -I../lib/angelscript/include \
-DUSE_GLES2 \
-DHAVE_OGGVORBIS \
-DNDEBUG \
-DANDROID_PACKAGE_NAME=\"$(PACKAGE_NAME)\" \
-DANDROID_APP_DIR_NAME=\"$(APP_DIR_NAME)\" \
-std=gnu++0x
LOCAL_STATIC_LIBRARIES := irrlicht bullet enet freetype ifaddrs angelscript \

View File

@ -40,6 +40,8 @@ export APP_NAME_RELEASE="SuperTuxKart"
export APP_NAME_DEBUG="SuperTuxKart Debug"
export PACKAGE_NAME_RELEASE="org.supertuxkart.stk"
export PACKAGE_NAME_DEBUG="org.supertuxkart.stk_dev"
export APP_DIR_NAME_RELEASE="supertuxkart"
export APP_DIR_NAME_DEBUG="supertuxkart-dbg"
export APP_ICON_RELEASE="$DIRNAME/icon.png"
export APP_ICON_DEBUG="$DIRNAME/icon-dbg.png"
@ -118,6 +120,7 @@ if [ "$BUILD_TYPE" = "debug" ] || [ "$BUILD_TYPE" = "Debug" ]; then
export IS_DEBUG_BUILD=1
export APP_NAME="$APP_NAME_DEBUG"
export PACKAGE_NAME="$PACKAGE_NAME_DEBUG"
export APP_DIR_NAME="$APP_DIR_NAME_DEBUG"
export APP_ICON="$APP_ICON_DEBUG"
elif [ "$BUILD_TYPE" = "release" ] || [ "$BUILD_TYPE" = "Release" ]; then
export ANT_BUILD_TYPE="release"
@ -125,6 +128,7 @@ elif [ "$BUILD_TYPE" = "release" ] || [ "$BUILD_TYPE" = "Release" ]; then
export IS_DEBUG_BUILD=0
export APP_NAME="$APP_NAME_RELEASE"
export PACKAGE_NAME="$PACKAGE_NAME_RELEASE"
export APP_DIR_NAME="$APP_DIR_NAME_RELEASE"
export APP_ICON="$APP_ICON_RELEASE"
else
echo "Unsupported BUILD_TYPE: $BUILD_TYPE. Possible values are: " \

View File

@ -73,22 +73,32 @@ void AssetsAndroid::init()
paths.push_back("/sdcard/");
paths.push_back("/storage/sdcard0/");
paths.push_back("/storage/sdcard1/");
paths.push_back("/data/data/org.supertuxkart.stk/files/");
#if !defined(ANDROID_PACKAGE_NAME) || !defined(ANDROID_APP_DIR_NAME)
#error
#endif
std::string package_name = ANDROID_PACKAGE_NAME;
paths.push_back("/data/data/" + package_name + "/files/");
std::string app_dir_name = ANDROID_APP_DIR_NAME;
// Check if STK data for current version is available somewhere
for (std::string path : paths)
{
Log::info("AssetsAndroid", "Check data files in: %s", path.c_str());
if (m_file_manager->fileExists(path + "/stk/data/" + version))
if (m_file_manager->fileExists(path + "/" + app_dir_name + "/data/" + version))
{
m_stk_dir = path + "/stk";
m_stk_dir = path + "/" + app_dir_name;
break;
}
if (m_file_manager->fileExists(path + "/supertuxkart/data/" + version))
// Stk is an alias of supertuxkart for compatibility with older version.
if (app_dir_name == "supertuxkart" &&
m_file_manager->fileExists(path + "/stk/data/" + version))
{
m_stk_dir = path + "/supertuxkart";
m_stk_dir = path + "/stk";
break;
}
}
@ -103,16 +113,18 @@ void AssetsAndroid::init()
Log::info("AssetsAndroid", "Check data files for different STK "
"version in: %s", path.c_str());
if (m_file_manager->fileExists(path + "/stk/.extracted"))
if (m_file_manager->fileExists(path + "/" + app_dir_name + "/.extracted"))
{
m_stk_dir = path + "/stk";
m_stk_dir = path + "/" + app_dir_name;
needs_extract_data = true;
break;
}
if (m_file_manager->fileExists(path + "/supertuxkart/.extracted"))
// Stk is an alias of supertuxkart for compatibility with older version.
if (app_dir_name == "supertuxkart" &&
m_file_manager->fileExists(path + "/stk/.extracted"))
{
m_stk_dir = path + "/supertuxkart";
m_stk_dir = path + "/stk";
needs_extract_data = true;
break;
}
@ -132,12 +144,12 @@ void AssetsAndroid::init()
if (preferred_path.length() > 0)
{
if (m_file_manager->checkAndCreateDirectoryP(preferred_path +
"/stk/data"))
if (m_file_manager->checkAndCreateDirectoryP(preferred_path + "/" +
app_dir_name + "/data"))
{
Log::info("AssetsAndroid", "Data directory created in: %s",
preferred_path.c_str());
m_stk_dir = preferred_path + "/stk";
m_stk_dir = preferred_path + "/" + app_dir_name;
needs_extract_data = true;
}
}
@ -149,11 +161,12 @@ void AssetsAndroid::init()
{
for (std::string path : paths)
{
if (m_file_manager->checkAndCreateDirectoryP(path + "/stk/data"))
if (m_file_manager->checkAndCreateDirectoryP(path + "/" +
app_dir_name + "/data"))
{
Log::info("AssetsAndroid", "Data directory created in: %s",
path.c_str());
m_stk_dir = path + "/stk";
m_stk_dir = path + "/" + app_dir_name;
needs_extract_data = true;
break;
}
@ -415,10 +428,12 @@ void AssetsAndroid::removeData()
#ifdef ANDROID
if (m_stk_dir.length() == 0)
return;
std::string app_dir_name = ANDROID_APP_DIR_NAME;
// Make sure that we are not accidentally removing wrong directory
if (m_stk_dir.find("/stk") == std::string::npos &&
m_stk_dir.find("/supertuxkart") == std::string::npos)
if (m_stk_dir.find("/" + app_dir_name) == std::string::npos &&
m_stk_dir.find("/stk") == std::string::npos)
{
Log::error("AssetsAndroid", "Invalid data directory: %s",
m_stk_dir.c_str());