summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-24 17:13:50 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-24 17:13:50 +0300
commit5a1214d380a96fa0a1eeeb07a4bfedeae982051a (patch)
tree1e03e4038894d780853228e7ca7fa400c85faa4b
parent672dae7a96ae07638a961fb6c8c41117dd8c5c95 (diff)
downloadplus-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.gz
plus-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.bz2
plus-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.xz
plus-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.zip
Extract data.zip on SDL2 and Android before use.
Add file untils class. For now used only for Android.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp47
-rw-r--r--src/client.h2
-rw-r--r--src/utils/files.cpp101
-rw-r--r--src/utils/files.h40
6 files changed, 154 insertions, 40 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6524d0e0c..2c33d96c0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -524,6 +524,8 @@ SET(SRCS
utils/cpu.cpp
utils/cpu.h
utils/dtor.h
+ utils/files.cpp
+ utils/files.h
utils/fuzzer.cpp
utils/fuzzer.h
utils/gettext.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 08b3c2796..710031fa1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -535,6 +535,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
utils/cpu.cpp \
utils/cpu.h \
utils/dtor.h \
+ utils/files.cpp \
+ utils/files.h \
utils/fuzzer.cpp \
utils/fuzzer.h \
utils/gettext.h \
diff --git a/src/client.cpp b/src/client.cpp
index e96fd370b..7717d1e4b 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -102,6 +102,7 @@
#include "resources/resourcemanager.h"
#include "utils/cpu.h"
+#include "utils/files.h"
#include "utils/fuzzer.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
@@ -384,7 +385,13 @@ void Client::gameInit()
#ifdef ANDROID
#ifdef USE_SDL2
extractAssets();
- extractLocale();
+
+ const std::string zipName = std::string(getenv(
+ "APPDIR")).append("/data.zip");
+ const std::string dirName = std::string(getenv(
+ "APPDIR")).append("/data");
+ Files::extractZip(zipName, "data", dirName);
+ Files::extractLocale();
#endif
#endif
@@ -534,7 +541,7 @@ void Client::gameInit()
if (getenv("APPDIR"))
{
resman->addToSearchPath(std::string(getenv("APPDIR"))
- + "/data.zip", false);
+ + "/data", false);
}
#endif
#endif
@@ -3296,41 +3303,5 @@ void Client::extractAssets()
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);
- remove(fileName2.c_str());
-}
#endif
#endif
diff --git a/src/client.h b/src/client.h
index c39863cce..957c49fed 100644
--- a/src/client.h
+++ b/src/client.h
@@ -393,8 +393,6 @@ private:
#ifdef ANDROID
#ifdef USE_SDL2
void extractAssets();
-
- void extractLocale();
#endif
#endif
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
new file mode 100644
index 000000000..f4c93e6e6
--- /dev/null
+++ b/src/utils/files.cpp
@@ -0,0 +1,101 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef ANDROID
+#include "utils/files.h"
+
+#include "logger.h"
+
+#include "resources/resourcemanager.h"
+
+#include "utils/mkdir.h"
+#include "utils/physfstools.h"
+
+#include "localconsts.h"
+
+void Files::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";
+ mkdir_r(localDir2.c_str());
+ copyPhysFsFile(moFile, localFile);
+ }
+ }
+ }
+ PhysFs::freeList(rootDirs);
+ resman->removeFromSearchPath(fileName2);
+ remove(fileName2.c_str());
+}
+
+void Files::copyPhysFsFile(const std::string &inFile,
+ const std::string &outFile)
+{
+ int size = 0;
+ void *const buf = ResourceManager::loadFile(inFile, size);
+ FILE *const file = fopen(outFile.c_str(), "w");
+ fwrite(buf, 1, size, file);
+ fclose(file);
+ free(buf);
+}
+
+void Files::copyPhysFsDir(const std::string &inDir, const std::string &outDir)
+{
+ mkdir_r(outDir.c_str());
+ char **files = PhysFs::enumerateFiles(inDir.c_str());
+ for (char **i = files; *i; i++)
+ {
+ const std::string file = std::string(inDir).append("/").append(*i);
+ const std::string outDir2 = std::string(outDir).append("/").append(*i);
+ if (PhysFs::isDirectory(file.c_str()))
+ copyPhysFsDir(file, outDir2);
+ else
+ copyPhysFsFile(file, outDir2);
+ }
+ PhysFs::freeList(files);
+}
+
+void Files::extractZip(const std::string &zipName, const std::string &inDir,
+ const std::string &outDir)
+{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ resman->addToSearchPath(zipName, false);
+ copyPhysFsDir(inDir, outDir);
+ resman->removeFromSearchPath(zipName);
+ remove(zipName.c_str());
+}
+
+#endif // ANDROID
diff --git a/src/utils/files.h b/src/utils/files.h
new file mode 100644
index 000000000..bb9a6a11f
--- /dev/null
+++ b/src/utils/files.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_FILES_H
+#define UTILS_FILES_H
+
+#ifdef ANDROID
+#include <string>
+
+namespace Files
+{
+ void extractLocale();
+
+ void copyPhysFsFile(const std::string &inFile, const std::string &outFile);
+
+ void copyPhysFsDir(const std::string &inDir, const std::string &outDir);
+
+ void extractZip(const std::string &zipName, const std::string &inDir,
+ const std::string &outDir);
+} // namespace Files
+
+#endif // ANDROID
+#endif // UTILS_FILES_H