diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-11-09 17:59:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-11-09 17:59:14 +0300 |
commit | db1e60556c72b1b87ff2a384c556ccca724c46d6 (patch) | |
tree | 22a5f4e9c4f436ef8e746e0a2d688de80c1597a6 /src/utils/files.cpp | |
parent | c2bb49be52a92deccec7428b6859242688fc8987 (diff) | |
parent | 1716861f0ee2f7a3714c5b44bb0f017c3d8d3b2c (diff) | |
download | plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.gz plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.bz2 plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.xz plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.zip |
Merge branch 'master' into stable
Diffstat (limited to 'src/utils/files.cpp')
-rw-r--r-- | src/utils/files.cpp | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/src/utils/files.cpp b/src/utils/files.cpp index f4c93e6e6..2d7994f8a 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -18,18 +18,18 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifdef ANDROID #include "utils/files.h" -#include "logger.h" - +#if defined(ANDROID) || defined(__native_client__) #include "resources/resourcemanager.h" +#include "utils/physfstools.h" +#endif #include "utils/mkdir.h" -#include "utils/physfstools.h" #include "localconsts.h" +#ifdef ANDROID void Files::extractLocale() { // in future need also remove all locales in local dir @@ -60,6 +60,20 @@ void Files::extractLocale() resman->removeFromSearchPath(fileName2); remove(fileName2.c_str()); } +#endif // ANDROID + +#if defined(ANDROID) || defined(__native_client__) + +namespace +{ + int mFilesCount = 0; + Files::CopyFileCallbackPtr mCallbackPtr = nullptr; +} // namespace + +void Files::setCopyCallBack(Files::CopyFileCallbackPtr callback) +{ + mCallbackPtr = callback; +} void Files::copyPhysFsFile(const std::string &inFile, const std::string &outFile) @@ -70,6 +84,13 @@ void Files::copyPhysFsFile(const std::string &inFile, fwrite(buf, 1, size, file); fclose(file); free(buf); +#ifdef ANDROID + if (mCallbackPtr) + { + mCallbackPtr(mFilesCount); + mFilesCount ++; + } +#endif } void Files::copyPhysFsDir(const std::string &inDir, const std::string &outDir) @@ -98,4 +119,40 @@ void Files::extractZip(const std::string &zipName, const std::string &inDir, remove(zipName.c_str()); } -#endif // ANDROID +#endif // ANDROID __native_client__ + +int Files::renameFile(const std::string &srcName, const std::string &dstName) +{ + FILE *srcFile = fopen(srcName.c_str(), "rb"); + if (srcFile == nullptr) + return -1; + FILE *dstFile = fopen(dstName.c_str(), "w+b"); + if (dstFile == nullptr) + { + fclose(srcFile); + return -1; + } + + const int chunkSize = 500000; + char *buf = new char[chunkSize]; + size_t sz = 0; + while ((sz = fread(buf, 1, chunkSize, srcFile))) + { + if (fwrite(buf, 1, sz, dstFile) != sz) + { + delete [] buf; + fclose(srcFile); + fclose(dstFile); + ::remove(dstName.c_str()); + return -1; + } + } + + delete [] buf; + fclose(srcFile); + fclose(dstFile); + if (!::remove(srcName.c_str())) + return 0; + + return -1; +} |