Remove/extract new data only if apk has assets

This commit is contained in:
Deve 2019-10-12 00:21:38 +02:00
parent 6d7d580fa3
commit 674cfff070
3 changed files with 41 additions and 7 deletions

View File

@ -664,6 +664,9 @@ find assets/* -type d | sort > assets/directories.txt
sed -i s/'.\/assets\/'// assets/directories.txt sed -i s/'.\/assets\/'// assets/directories.txt
sed -i s/'assets\/'// assets/directories.txt sed -i s/'assets\/'// assets/directories.txt
# A file that can be used to check if apk has assets
echo "has_assets" > assets/has_assets.txt
# It will be probably ignored by ant, but create it anyway... # It will be probably ignored by ant, but create it anyway...
touch assets/.nomedia touch assets/.nomedia

View File

@ -231,17 +231,21 @@ void AssetsAndroid::init()
{ {
m_progress_bar = new ProgressBarAndroid(); m_progress_bar = new ProgressBarAndroid();
m_progress_bar->draw(0.01f); m_progress_bar->draw(0.01f);
if (hasAssets())
{
removeData();
extractData();
removeData(); if (!m_file_manager->fileExists(m_stk_dir + "/.extracted"))
extractData(); {
Log::fatal("AssetsAndroid", "Fatal error: Assets were not "
"extracted properly");
}
}
delete m_progress_bar; delete m_progress_bar;
if (!m_file_manager->fileExists(m_stk_dir + "/.extracted"))
{
Log::fatal("AssetsAndroid", "Fatal error: Assets were not "
"extracted properly");
}
} }
#endif #endif
@ -525,6 +529,32 @@ void AssetsAndroid::removeData()
#endif #endif
} }
//-----------------------------------------------------------------------------
/** A function that checks if assets are included in the package
* \return true if apk has assets
*/
bool AssetsAndroid::hasAssets()
{
#ifdef ANDROID
AAssetManager* amgr = global_android_app->activity->assetManager;
AAsset* asset = AAssetManager_open(amgr, "has_assets.txt",
AASSET_MODE_STREAMING);
if (asset == NULL)
{
Log::info("AssetsAndroid", "Package doesn't have assets");
return false;
}
Log::info("AssetsAndroid", "Package has assets");
AAsset_close(asset);
return true;
#endif
return false;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** A function that creates empty file /** A function that creates empty file
* \param path A path to the file that should be created * \param path A path to the file that should be created

View File

@ -33,6 +33,7 @@ private:
void extractData(); void extractData();
bool extractDir(std::string dir_name); bool extractDir(std::string dir_name);
void removeData(); void removeData();
bool hasAssets();
void touchFile(std::string path); void touchFile(std::string path);
bool isWritable(std::string path); bool isWritable(std::string path);
std::string getPreferredPath(const std::vector<std::string>& paths); std::string getPreferredPath(const std::vector<std::string>& paths);