summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-23 00:18:31 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-23 00:18:31 +0300
commitec273ae2cece76d0bcb7671099c9b6a59ceeadaa (patch)
treee19419a1b0fab2306f1924b3d935ee16f4d4ca98 /src
parent338a906ea4283e7f00ab29753e92fff53c0d0633 (diff)
downloadmv-ec273ae2cece76d0bcb7671099c9b6a59ceeadaa.tar.gz
mv-ec273ae2cece76d0bcb7671099c9b6a59ceeadaa.tar.bz2
mv-ec273ae2cece76d0bcb7671099c9b6a59ceeadaa.tar.xz
mv-ec273ae2cece76d0bcb7671099c9b6a59ceeadaa.zip
add support for gettext files extraction in SDL2 in Android.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp86
-rw-r--r--src/client.h2
2 files changed, 73 insertions, 15 deletions
diff --git a/src/client.cpp b/src/client.cpp
index c4787d9a3..c81bf7dae 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -364,12 +364,6 @@ void Client::gameInit()
#ifdef USE_FUZZER
Fuzzer::init();
#endif
-
-#ifdef ANDROID
-#ifdef USE_SDL2
- extractAssets();
-#endif
-#endif
initConfiguration();
paths.setDefaultValues(getPathsDefaults());
initFeatures();
@@ -380,6 +374,20 @@ void Client::gameInit()
storeSafeParameters();
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ if (!resman->setWriteDir(mLocalDataDir))
+ {
+ logger->error(strprintf("%s couldn't be set as home directory! "
+ "Exiting.", mLocalDataDir.c_str()));
+ }
+
+#ifdef ANDROID
+#ifdef USE_SDL2
+ extractAssets();
+ extractLocale();
+#endif
+#endif
+
#ifdef ENABLE_NLS
std::string lang = config.getStringValue("lang");
#ifdef WIN32
@@ -398,8 +406,13 @@ void Client::gameInit()
setEnv("LANGUAGE", lang.c_str());
}
#ifdef ANDROID
+#ifdef USE_SDL2
+ bindTextDomain("manaplus", (std::string(getenv("APPDIR")).append(
+ "/locale")).c_str());
+#else
bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
.append("/locale")).c_str());
+#endif
#else
#ifdef ENABLE_PORTABLE
bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
@@ -493,13 +506,6 @@ void Client::gameInit()
SMALL_VERSION);
}
- const ResourceManager *const resman = ResourceManager::getInstance();
- if (!resman->setWriteDir(mLocalDataDir))
- {
- logger->error(strprintf("%s couldn't be set as home directory! "
- "Exiting.", mLocalDataDir.c_str()));
- }
-
resman->addToSearchPath(PKG_DATADIR "data/perserver/default", false);
resman->addToSearchPath("data/perserver/default", false);
@@ -3250,8 +3256,9 @@ void Client::extractAssets()
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];
+
+ FILE *const file = fopen(fileName.c_str(), "w");
for (int f = 0; f < 100; f ++)
{
std::string part = strprintf("manaplus-data.zip%u%u",
@@ -3272,8 +3279,57 @@ void Client::extractAssets()
break;
}
}
- delete [] buf;
fclose(file);
+
+ const std::string fileName2 = std::string(getenv(
+ "APPDIR")).append("/locale.zip");
+ FILE *const file2 = fopen(fileName2.c_str(), "w");
+ SDL_RWops *const rw = SDL_RWFromFile("manaplus-locale.zip", "r");
+ if (rw)
+ {
+ const int size = SDL_RWsize(rw);
+ int size2 = SDL_RWread(rw, buf, 1, size);
+ fwrite(buf, 1, size2, file2);
+ SDL_RWclose(rw);
+ }
+ fclose(file2);
+
+ delete [] buf;
+}
+
+void Client::extractLocale()
+{
+ // in future need also remove all locales in local dir
+
+ const std::string fileName2 = std::string(getenv(
+ "APPDIR")).append("/locale.zip");
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ resman->addToSearchPath(fileName2, false);
+
+ const std::string localDir = std::string(getenv("APPDIR")).append("/");
+ char **rootDirs = PhysFs::enumerateFiles("locale");
+ for (char **i = rootDirs; *i; i++)
+ {
+ const std::string dir = std::string("locale/").append(*i);
+ if (PhysFs::isDirectory(dir.c_str()))
+ {
+ const std::string moFile = dir + "/LC_MESSAGES/manaplus.mo";
+ if (PhysFs::exists((moFile).c_str()))
+ {
+ const std::string localFile = localDir + moFile;
+ const std::string localDir2 = localDir + dir + "/LC_MESSAGES";
+ int size = 0;
+ mkdir_r(localDir2.c_str());
+ void *const buf = ResourceManager::loadFile(moFile, size);
+ FILE *const file = fopen(localFile.c_str(), "w");
+ fwrite(buf, 1, size, file);
+ fclose(file);
+ free(buf);
+ }
+ }
+ }
+ PhysFs::freeList(rootDirs);
+ resman->removeFromSearchPath(fileName2);
}
#endif
#endif
diff --git a/src/client.h b/src/client.h
index 957c49fed..c39863cce 100644
--- a/src/client.h
+++ b/src/client.h
@@ -393,6 +393,8 @@ private:
#ifdef ANDROID
#ifdef USE_SDL2
void extractAssets();
+
+ void extractLocale();
#endif
#endif