diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-24 17:13:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-24 17:13:50 +0300 |
commit | 5a1214d380a96fa0a1eeeb07a4bfedeae982051a (patch) | |
tree | 1e03e4038894d780853228e7ca7fa400c85faa4b /src/utils/files.cpp | |
parent | 672dae7a96ae07638a961fb6c8c41117dd8c5c95 (diff) | |
download | manaverse-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.gz manaverse-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.bz2 manaverse-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.tar.xz manaverse-5a1214d380a96fa0a1eeeb07a4bfedeae982051a.zip |
Extract data.zip on SDL2 and Android before use.
Add file untils class. For now used only for Android.
Diffstat (limited to 'src/utils/files.cpp')
-rw-r--r-- | src/utils/files.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
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 |