summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-22 15:56:01 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-22 16:28:10 +0300
commitfbad53d1a8cc89d07227165042cd55e7ed9c5dd2 (patch)
tree07a0105853e97088f1a091caecc3bb2fb4968c13 /src/client.cpp
parent87b21ba61d7a8c322d658bd6b8d9f75b9e711263 (diff)
downloadmanaplus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.gz
manaplus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.bz2
manaplus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.xz
manaplus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.zip
add support in ADNROID+SDL2 for loading data from assets.
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp
index cc2a06f77..3a5a3f943 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -365,6 +365,11 @@ void Client::gameInit()
Fuzzer::init();
#endif
+#ifdef ANDROID
+#ifdef USE_SDL2
+ extractAssets();
+#endif
+#endif
initConfiguration();
paths.setDefaultValues(getPathsDefaults());
initFeatures();
@@ -518,6 +523,15 @@ void Client::gameInit()
mPackageDir = PKG_DATADIR "data";
resman->addToSearchPath("data", false);
+#ifdef ANDROID
+#ifdef USE_SDL2
+ if (getenv("APPDIR"))
+ {
+ resman->addToSearchPath(std::string(getenv("APPDIR"))
+ + "/data.zip", false);
+ }
+#endif
+#endif
// Add branding/data to PhysFS search path
if (!mOptions.brandingPath.empty())
{
@@ -3175,3 +3189,43 @@ void Client::handleActive(const SDL_Event &event)
setMouseFocused(event.active.gain);
}
#endif
+
+#ifdef ANDROID
+#ifdef USE_SDL2
+void Client::extractAssets()
+{
+ if (!getenv("APPDIR"))
+ {
+ logger->log("error: APPDIR is not set!");
+ return;
+ }
+ const std::string fileName = std::string(getenv(
+ "APPDIR")).append("/data.zip");
+ logger->log("Extracting asset into: " + fileName);
+ FILE *const file = fopen(fileName.c_str(), "w");
+ uint8_t *buf = new uint8_t[1000000];
+ for (int f = 0; f < 100; f ++)
+ {
+ std::string part = strprintf("manaplus-data.zip%u%u",
+ static_cast<unsigned int>(f / 10),
+ static_cast<unsigned int>(f % 10));
+ logger->log("testing asset: " + part);
+ SDL_RWops *const rw = SDL_RWFromFile(part.c_str(), "r");
+ if (rw)
+ {
+ const int size = SDL_RWsize(rw);
+ int size2 = SDL_RWread(rw, buf, 1, size);
+ logger->log("asset size: %d", size2);
+ fwrite(buf, 1, size2, file);
+ SDL_RWclose(rw);
+ }
+ else
+ {
+ break;
+ }
+ }
+ delete [] buf;
+ fclose(file);
+}
+#endif
+#endif