25 #if defined(ANDROID) || defined(__native_client__)
33 #if defined(ANDROID) || defined(__native_client__)
49 void Files::extractLocale()
53 const std::string fileName2 =
pathJoin(getenv(
"APPDIR"),
"locale.zip");
56 const std::string localDir = std::string(getenv(
"APPDIR"));
60 const std::string dir =
pathJoin(
"locale", *i);
63 const std::string moFile = dir +
"/LC_MESSAGES/manaplus.mo";
66 const std::string localFile =
pathJoin(localDir, moFile);
67 const std::string localDir2 =
pathJoin(localDir,
71 copyVirtFsFile(moFile, localFile);
81 #if defined(ANDROID) || defined(__native_client__)
89 Files::CopyFileCallbackPtr mCallbackPtr =
nullptr;
92 void Files::setCopyCallBack(Files::CopyFileCallbackPtr callback)
94 mCallbackPtr = callback;
97 void Files::copyVirtFsFile(
const std::string &
restrict inFile,
102 FILE *
const file = fopen(outFile.c_str(),
"w");
103 fwrite(buf, 1,
size, file);
109 mCallbackPtr(mFilesCount);
115 void Files::copyVirtFsDir(
const std::string &
restrict inDir,
122 const std::string file =
pathJoin(inDir, *i);
123 const std::string outDir2 =
pathJoin(outDir, *i);
125 copyVirtFsDir(file, outDir2);
127 copyVirtFsFile(file, outDir2);
135 const std::string &
restrict dstName)
137 #if defined __native_client__
138 FILE *srcFile = fopen(srcName.c_str(),
"rb");
139 if (srcFile ==
nullptr)
141 FILE *dstFile = fopen(dstName.c_str(),
"w+b");
142 if (dstFile ==
nullptr)
148 const int chunkSize = 500000;
149 char *buf =
new char[chunkSize];
151 while ((sz = fread(buf, 1, chunkSize, srcFile)))
153 if (fwrite(buf, 1, sz, dstFile) != sz)
166 if (!::
remove(srcName.c_str()))
172 return ::rename(srcName.c_str(), dstName.c_str());
177 const std::string &
restrict dstName)
179 FILE *srcFile = fopen(srcName.c_str(),
"rb");
180 if (srcFile ==
nullptr)
182 FILE *dstFile = fopen(dstName.c_str(),
"w+b");
183 if (dstFile ==
nullptr)
189 const int chunkSize = 512000;
190 char *buf =
new char[chunkSize];
192 while ((sz = fread(buf, 1, chunkSize, srcFile)) != 0U)
194 if (fwrite(buf, 1, sz, dstFile) != sz)
215 const bool res = (stat(path.c_str(), &statbuf) == 0);
219 S_ISDIR(statbuf.st_mode) == 0)
225 return stat(path.c_str(), &statbuf) == 0;
235 file.open(
fileName.c_str(), std::ios::in);
244 while (file.getline(line, 500))
245 lines.push_back(line);
254 if (
mkdir_r(path.c_str()) == 0)
258 file.open(
fileName.c_str(), std::ios::out);
261 file << text << std::endl;
275 const dirent *next_file =
nullptr;
276 DIR *
const dir = opendir(path.c_str());
280 while ((next_file = readdir(dir)) !=
nullptr)
282 const std::string file = next_file->d_name;
283 if (file !=
"." && file !=
"..")
284 remove((path + file).c_str());
296 DIR *
const dir = opendir(path.c_str());
300 const dirent *next_file =
nullptr;
301 while ((next_file = readdir(dir)) !=
nullptr)
303 const std::string file = next_file->d_name;
304 if (file ==
"." || file ==
"..")
307 if (skipSymlinks ==
true)
310 if (lstat(path.c_str(), &statbuf) == 0 &&
311 S_ISLNK(statbuf.st_mode) != 0)
317 files.push_back(file);
#define reportAlways(...)
const char * dirSeparator
#define FOR_EACH(type, iter, array)
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
bool loadTextFileLocal(const std::string &fileName, StringVect &lines)
int renameFile(const std::string &pFrom, const std::string &pTo)
int copyFile(const std::string &pFrom, const std::string &pTo)
void deleteFilesInDirectory(std::string path)
void enumFiles(StringVect &files, std::string path, const bool skipSymlinks)
bool existsLocal(const std::string &path)
void saveTextFile(const std::string &path, const std::string &name, const std::string &text)
bool remove(const std::string &filename)
void freeList(List *const handle)
bool mountZip(std::string newDir, const Append append)
bool unmountZip(std::string oldDir)
bool isDirectory(std::string name)
const char * loadFile(std::string filename, int &fileSize)
List * enumerateFiles(std::string dirName)
bool exists(std::string name)
bool findLast(const std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
StringVect::const_iterator StringVectCIter
std::vector< std::string > StringVect