From fbad53d1a8cc89d07227165042cd55e7ed9c5dd2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 22 Sep 2013 15:56:01 +0300 Subject: add support in ADNROID+SDL2 for loading data from assets. --- src/client.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/client.cpp') 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(f / 10), + static_cast(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 -- cgit v1.2.3-60-g2f50