From 6c9c56b70db43f4100863d312835fce763698008 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Fri, 10 Feb 2017 20:16:03 +0300
Subject: Rename physfstools into virtfs.

---
 src/utils/chatutils_unittest.cc              |   4 +-
 src/utils/files.cpp                          |  42 +++---
 src/utils/files_unittest.cc                  |  14 +-
 src/utils/gettexthelper.cpp                  |   8 +-
 src/utils/paths.cpp                          |  12 +-
 src/utils/physfsrwops.cpp                    |  10 +-
 src/utils/physfsrwops.h                      |   2 +-
 src/utils/physfstools.cpp                    | 184 ------------------------
 src/utils/physfstools.h                      |  60 --------
 src/utils/stringutils_unittest.cc            |   4 +-
 src/utils/translation/poparser.cpp           |   6 +-
 src/utils/translation/poparser_unittest.cc   |   4 +-
 src/utils/translation/translationmanager.cpp |   4 +-
 src/utils/virtfs.cpp                         | 205 +++++++++++++++++++++++++++
 src/utils/virtfs.h                           |  66 +++++++++
 src/utils/xml/libxml.cpp                     |   4 +-
 src/utils/xml/pugixml.cpp                    |   4 +-
 src/utils/xml/pugixmlwriter.cpp              |   2 +-
 src/utils/xml_unittest.cc                    |   4 +-
 src/utils/xmlutils_unittest.cc               |   8 +-
 20 files changed, 337 insertions(+), 310 deletions(-)
 delete mode 100644 src/utils/physfstools.cpp
 delete mode 100644 src/utils/physfstools.h
 create mode 100644 src/utils/virtfs.cpp
 create mode 100644 src/utils/virtfs.h

(limited to 'src/utils')

diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc
index 374bf3125..233d02bf6 100644
--- a/src/utils/chatutils_unittest.cc
+++ b/src/utils/chatutils_unittest.cc
@@ -32,7 +32,7 @@
 
 #include "utils/chatutils.h"
 #include "utils/delete2.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 #include "render/sdlgraphics.h"
 
@@ -240,7 +240,7 @@ TEST_CASE("chatutils replaceVars")
 
     delete2(actorManager);
     delete2(client);
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("chatutils textToMe")
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index fa09f9c7d..e875af770 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -30,7 +30,7 @@
 
 #include "utils/mkdir.h"
 #include "utils/paths.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include <algorithm>
@@ -49,14 +49,14 @@ void Files::extractLocale()
     resourceManager->addToSearchPath(fileName2, Append_false);
 
     const std::string localDir = std::string(getenv("APPDIR")).append("/");
-    char **rootDirs = PhysFs::enumerateFiles("locale");
+    char **rootDirs = VirtFs::enumerateFiles("locale");
     for (char **i = rootDirs; *i; i++)
     {
         const std::string dir = std::string("locale/").append(*i);
-        if (PhysFs::isDirectory(dir.c_str()))
+        if (VirtFs::isDirectory(dir.c_str()))
         {
             const std::string moFile = dir + "/LC_MESSAGES/manaplus.mo";
-            if (PhysFs::exists((moFile).c_str()))
+            if (VirtFs::exists((moFile).c_str()))
             {
                 const std::string localFile = localDir + moFile;
                 const std::string localDir2 = localDir + dir + "/LC_MESSAGES";
@@ -65,7 +65,7 @@ void Files::extractLocale()
             }
         }
     }
-    PhysFs::freeList(rootDirs);
+    VirtFs::freeList(rootDirs);
     resourceManager->removeFromSearchPath(fileName2);
     remove(fileName2.c_str());
 }
@@ -91,7 +91,7 @@ void Files::copyPhysFsFile(const std::string &restrict inFile,
                            const std::string &restrict outFile)
 {
     int size = 0;
-    void *const buf = PhysFs::loadFile(inFile, size);
+    void *const buf = VirtFs::loadFile(inFile, size);
     FILE *const file = fopen(outFile.c_str(), "w");
     fwrite(buf, 1, size, file);
     fclose(file);
@@ -109,17 +109,17 @@ void Files::copyPhysFsDir(const std::string &restrict inDir,
                           const std::string &restrict outDir)
 {
     mkdir_r(outDir.c_str());
-    char **files = PhysFs::enumerateFiles(inDir.c_str());
+    char **files = VirtFs::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()))
+        if (VirtFs::isDirectory(file.c_str()))
             copyPhysFsDir(file, outDir2);
         else
             copyPhysFsFile(file, outDir2);
     }
-    PhysFs::freeList(files);
+    VirtFs::freeList(files);
 }
 
 void Files::extractZip(const std::string &restrict zipName,
@@ -211,35 +211,35 @@ int Files::copyFile(const std::string &restrict srcName,
 
 void Files::getFiles(const std::string &path, StringVect &list)
 {
-    char **const fonts = PhysFs::enumerateFiles(path.c_str());
+    char **const fonts = VirtFs::enumerateFiles(path.c_str());
     for (char *const *i = fonts; *i; i++)
     {
-        if (!PhysFs::isDirectory((path + *i).c_str()))
+        if (!VirtFs::isDirectory((path + *i).c_str()))
             list.push_back(*i);
     }
-    PhysFs::freeList(fonts);
+    VirtFs::freeList(fonts);
 }
 
 void Files::getDirs(const std::string &path, StringVect &list)
 {
-    char **const fonts = PhysFs::enumerateFiles(path.c_str());
+    char **const fonts = VirtFs::enumerateFiles(path.c_str());
     for (char *const *i = fonts; *i; i++)
     {
-        if (PhysFs::isDirectory((path + *i).c_str()))
+        if (VirtFs::isDirectory((path + *i).c_str()))
             list.push_back(*i);
     }
-    PhysFs::freeList(fonts);
+    VirtFs::freeList(fonts);
 }
 
 void Files::getFilesWithDir(const std::string &path, StringVect &list)
 {
-    char **const fonts = PhysFs::enumerateFiles(path.c_str());
+    char **const fonts = VirtFs::enumerateFiles(path.c_str());
     for (char *const *i = fonts; *i; i++)
     {
-        if (!PhysFs::isDirectory((path + *i).c_str()))
+        if (!VirtFs::isDirectory((path + *i).c_str()))
             list.push_back(path + *i);
     }
-    PhysFs::freeList(fonts);
+    VirtFs::freeList(fonts);
 }
 
 bool Files::existsLocal(const std::string &path)
@@ -256,7 +256,7 @@ bool Files::existsLocal(const std::string &path)
 std::string Files::getPath(const std::string &file)
 {
     // get the real path to the file
-    const char *const tmp = PhysFs::getRealDir(file.c_str());
+    const char *const tmp = VirtFs::getRealDir(file.c_str());
     std::string path;
 
     // if the file is not in the search path, then its nullptr
@@ -282,7 +282,7 @@ std::string Files::loadTextFileString(const std::string &fileName)
 {
     int contentsLength;
     char *fileContents = static_cast<char*>(
-        PhysFs::loadFile(fileName, contentsLength));
+        VirtFs::loadFile(fileName, contentsLength));
 
     if (!fileContents)
     {
@@ -299,7 +299,7 @@ bool Files::loadTextFile(const std::string &fileName,
 {
     int contentsLength;
     char *fileContents = static_cast<char*>(
-        PhysFs::loadFile(fileName, contentsLength));
+        VirtFs::loadFile(fileName, contentsLength));
 
     if (!fileContents)
     {
diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc
index d0d4fdb1e..01996bd74 100644
--- a/src/utils/files_unittest.cc
+++ b/src/utils/files_unittest.cc
@@ -23,7 +23,7 @@
 #include "catch.hpp"
 #include "logger.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 #include "resources/resourcemanager/resourcemanager.h"
 
@@ -63,7 +63,7 @@ TEST_CASE("Files renameFile")
     delete [] buf;
     delete [] buf2;
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("Files existsLocal")
@@ -77,7 +77,7 @@ TEST_CASE("Files existsLocal")
     REQUIRE_FALSE(Files::existsLocal(Files::getPath("help/about1.txt")));
     REQUIRE_FALSE(Files::existsLocal(Files::getPath("help1/about.txt")));
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("Files loadTextFileString")
@@ -90,7 +90,7 @@ TEST_CASE("Files loadTextFileString")
     REQUIRE(Files::loadTextFileString("test/simplefile.txt") ==
         "this is test \nfile.");
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("Files loadTextFile")
@@ -107,7 +107,7 @@ TEST_CASE("Files loadTextFile")
     REQUIRE(lines[0] == "this is test ");
     REQUIRE(lines[1] == "file.");
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("Files saveTextFile")
@@ -125,7 +125,7 @@ TEST_CASE("Files saveTextFile")
     ::remove((dir + "/tempfile.txt").c_str());
     REQUIRE(data == "test line\ntext line2\n");
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("Files getFilesInDir")
@@ -154,5 +154,5 @@ TEST_CASE("Files getFilesInDir")
     REQUIRE(list[3] == "perserver/default/features.xml");
     REQUIRE(list[4] == "perserver/default/weapons.xml");
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
diff --git a/src/utils/gettexthelper.cpp b/src/utils/gettexthelper.cpp
index edbc11671..5b1999925 100644
--- a/src/utils/gettexthelper.cpp
+++ b/src/utils/gettexthelper.cpp
@@ -28,7 +28,7 @@
 #include "client.h"
 #include "logger.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 #include <libintl.h>
 
@@ -99,16 +99,16 @@ void GettextHelper::initLang()
     bindTextDomain((std::string(getenv("APPDIR")).append("/locale")).c_str());
 #else  // USE_SDL2
 
-    bindTextDomain((std::string(PhysFs::getBaseDir()).append(
+    bindTextDomain((std::string(VirtFs::getBaseDir()).append(
         "/locale")).c_str());
 #endif  // USE_SDL2
 #else  // ANDROID
 #ifdef ENABLE_PORTABLE
-    bindTextDomain((std::string(PhysFs::getBaseDir()).append(
+    bindTextDomain((std::string(VirtFs::getBaseDir()).append(
         "../locale/")).c_str());
 #else  // ENABLE_PORTABLE
 #ifdef __APPLE__
-    bindTextDomain((std::string(PhysFs::getBaseDir())
+    bindTextDomain((std::string(VirtFs::getBaseDir())
         .append("ManaPlus.app/Contents/Resources/locale/")).c_str());
 #else  // __APPLE__
 
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index a24239e34..be4e31a7f 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -26,7 +26,7 @@
 
 #include "utils/paths.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #ifdef USE_X11
@@ -172,7 +172,7 @@ std::string getPicturesDir()
     std::string file;
     if (!xdg)
     {
-        file = std::string(PhysFs::getUserDir()).append(
+        file = std::string(VirtFs::getUserDir()).append(
             "/.config/user-dirs.dirs");
     }
     else
@@ -190,18 +190,18 @@ std::string getPicturesDir()
             str = str.substr(0, str.size() - 1);
             // use hack to replace $HOME var.
             // if in string other vars, fallback to default path
-            replaceAll(str, "$HOME/", PhysFs::getUserDir());
+            replaceAll(str, "$HOME/", VirtFs::getUserDir());
             str = getRealPath(str);
             if (str.empty())
-                str = std::string(PhysFs::getUserDir()).append("Desktop");
+                str = std::string(VirtFs::getUserDir()).append("Desktop");
             return str;
         }
     }
 
-    return std::string(PhysFs::getUserDir()).append("Desktop");
+    return std::string(VirtFs::getUserDir()).append("Desktop");
 #else  // WIN32
 
-    return std::string(PhysFs::getUserDir()).append("Desktop");
+    return std::string(VirtFs::getUserDir()).append("Desktop");
 #endif  // WIN32
 }
 
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 29a574913..9af838070 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -255,7 +255,7 @@ static bool checkFilePath(const char *const fname)
 {
     if (!fname || !*fname)
         return false;
-    if (!PhysFs::exists(fname) || PhysFs::isDirectory(fname))
+    if (!VirtFs::exists(fname) || VirtFs::isDirectory(fname))
         return false;
     return true;
 }
@@ -273,12 +273,12 @@ SDL_RWops *PHYSFSRWOPS_openRead(const char *const fname)
         return nullptr;
 #endif  // USE_FUZZER
 #ifdef USE_PROFILER
-    SDL_RWops *const ret = create_rwops(PhysFs::openRead(fname));
+    SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname));
     BLOCK_END("PHYSFSRWOPS_openRead")
     return ret;
 #else  // USE_PROFILER
 
-    return create_rwops(PhysFs::openRead(fname));
+    return create_rwops(VirtFs::openRead(fname));
 #endif  // USE_PROFILER
 } /* PHYSFSRWOPS_openRead */
 
@@ -289,7 +289,7 @@ SDL_RWops *PHYSFSRWOPS_openWrite(const char *const fname)
         return nullptr;
 #endif  // __APPLE__
 
-    return create_rwops(PhysFs::openWrite(fname));
+    return create_rwops(VirtFs::openWrite(fname));
 } /* PHYSFSRWOPS_openWrite */
 
 SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname)
@@ -299,7 +299,7 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *const fname)
         return nullptr;
 #endif  // __APPLE__
 
-    return create_rwops(PhysFs::openAppend(fname));
+    return create_rwops(VirtFs::openAppend(fname));
 } /* PHYSFSRWOPS_openAppend */
 
 #ifdef DUMP_LEAKED_RESOURCES
diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h
index 6917afc5d..98608458c 100644
--- a/src/utils/physfsrwops.h
+++ b/src/utils/physfsrwops.h
@@ -29,7 +29,7 @@
 
 #include <SDL_rwops.h>
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 /**
  * Open a platform-independent filename for reading, and make it accessible
diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp
deleted file mode 100644
index cc17c09b3..000000000
--- a/src/utils/physfstools.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- *  The ManaPlus Client
- *  Copyright (C) 2013-2017  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/>.
- */
-
-#include "utils/physfstools.h"
-
-#include "logger.h"
-
-#include <iostream>
-#include <unistd.h>
-
-#ifdef ANDROID
-#include "utils/paths.h"
-#endif  // ANDROID
-
-#include "debug.h"
-
-const char *dirSeparator = nullptr;
-
-namespace PhysFs
-{
-#if defined(__native_client__)
-    void init(const char *const name A_UNUSED)
-    {
-        if (!PHYSFS_init("/fakebinary"))
-#elif defined(ANDROID)
-    void init(const char *const name A_UNUSED)
-    {
-        if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str()))
-#else  // defined(__native_client__)
-
-    void init(const char *const name)
-    {
-        if (!PHYSFS_init(name))
-#endif  // defined(__native_client__)
-        {
-            std::cout << "Error while initializing PhysFS: "
-                << PHYSFS_getLastError() << std::endl;
-            _exit(1);
-        }
-        updateDirSeparator();
-        atexit(reinterpret_cast<void(*)()>(PHYSFS_deinit));
-    }
-
-    void updateDirSeparator()
-    {
-        dirSeparator = PHYSFS_getDirSeparator();
-    }
-
-    const char *getDirSeparator()
-    {
-        return dirSeparator;
-    }
-
-    const char *getBaseDir()
-    {
-        return PHYSFS_getBaseDir();
-    }
-
-    const char *getUserDir()
-    {
-        return PHYSFS_getUserDir();
-    }
-
-    bool exists(const char *const fname)
-    {
-        return PHYSFS_exists(fname);
-    }
-
-    char **enumerateFiles(const char *const dir)
-    {
-        return PHYSFS_enumerateFiles(dir);
-    }
-
-    bool isDirectory(const char *const fname)
-    {
-        return PHYSFS_isDirectory(fname);
-    }
-
-    void freeList(void *const listVar)
-    {
-        PHYSFS_freeList(listVar);
-    }
-
-    PHYSFS_file *openRead(const char *const filename)
-    {
-        return PHYSFS_openRead(filename);
-    }
-
-    PHYSFS_file *openWrite(const char *const filename)
-    {
-        return PHYSFS_openWrite(filename);
-    }
-
-    PHYSFS_file *openAppend(const char *const filename)
-    {
-        return PHYSFS_openAppend(filename);
-    }
-
-    bool setWriteDir(const char *const newDir)
-    {
-        return PHYSFS_setWriteDir(newDir);
-    }
-
-    bool addToSearchPath(const char *const newDir, const int appendToPath)
-    {
-        return PHYSFS_addToSearchPath(newDir, appendToPath);
-    }
-
-    bool removeFromSearchPath(const char *const oldDir)
-    {
-        return PHYSFS_removeFromSearchPath(oldDir);
-    }
-
-    const char *getRealDir(const char *const filename)
-    {
-        return PHYSFS_getRealDir(filename);
-    }
-
-    bool mkdir(const char *const dirname)
-    {
-        return PHYSFS_mkdir(dirname);
-    }
-
-    void *loadFile(const std::string &fileName, int &fileSize)
-    {
-        // Attempt to open the specified file using PhysicsFS
-        PHYSFS_file *const file = PhysFs::openRead(fileName.c_str());
-
-        if (!file)
-        {
-            logger->log("Warning: Failed to load %s: %s",
-                        fileName.c_str(), PHYSFS_getLastError());
-            return nullptr;
-        }
-
-        logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()),
-            fileName.c_str());
-
-        fileSize = CAST_S32(PHYSFS_fileLength(file));
-        // Allocate memory and load the file
-        void *const buffer = calloc(fileSize, 1);
-        PHYSFS_read(file, buffer, 1, fileSize);
-        PHYSFS_close(file);
-
-        return buffer;
-    }
-
-    bool deinit()
-    {
-        if (PHYSFS_deinit() != 0)
-        {
-            logger->log("Physfs deinit error: %s", PHYSFS_getLastError());
-            return false;
-        }
-        return true;
-    }
-
-    void permitLinks(const bool val)
-    {
-        PHYSFS_permitSymbolicLinks(val ? 1 : 0);
-    }
-
-    const char *getLastError()
-    {
-        return PHYSFS_getLastError();
-    }
-}  // namespace PhysFs
diff --git a/src/utils/physfstools.h b/src/utils/physfstools.h
deleted file mode 100644
index 3db197927..000000000
--- a/src/utils/physfstools.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  The ManaPlus Client
- *  Copyright (C) 2013-2017  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_PHYSFSTOOLS_H
-#define UTILS_PHYSFSTOOLS_H
-
-#include "localconsts.h"
-
-PRAGMA45(GCC diagnostic push)
-PRAGMA45(GCC diagnostic ignored "-Wlong-long")
-#include <physfs.h>
-PRAGMA45(GCC diagnostic pop)
-
-#include <string>
-
-namespace PhysFs
-{
-    void init(const char *const name);
-    void updateDirSeparator();
-    const char *getDirSeparator();
-    const char *getBaseDir();
-    const char *getUserDir();
-    bool exists(const char *const fname);
-    char **enumerateFiles(const char *const dir);
-    bool isDirectory(const char *const fname);
-    void freeList(void *const listVar);
-    PHYSFS_file *openRead(const char *const filename);
-    PHYSFS_file *openWrite(const char *const filename);
-    PHYSFS_file *openAppend(const char *const filename);
-    bool setWriteDir(const char *const newDir);
-    bool addToSearchPath(const char *const newDir, const int appendToPath);
-    bool removeFromSearchPath(const char *const oldDir);
-    const char *getRealDir(const char *const filename);
-    bool mkdir(const char *const dirName);
-    void *loadFile(const std::string &fileName, int &fileSize);
-    bool deinit();
-    void permitLinks(const bool val);
-    const char *getLastError();
-}  // namespace PhysFs
-
-extern const char *dirSeparator;
-
-#endif  // UTILS_PHYSFSTOOLS_H
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 2af7b7939..46c1b352c 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -24,7 +24,7 @@
 
 #include "const/utils/utf8.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 #include "resources/iteminfo.h"
 
@@ -1485,5 +1485,5 @@ TEST_CASE("stringuntils replaceItemLinks")
         REQUIRE(str == "[[test name 1 ,test name2[] test name 1]");
     }
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp
index 704ce873d..2f591f2e4 100644
--- a/src/utils/translation/poparser.cpp
+++ b/src/utils/translation/poparser.cpp
@@ -20,7 +20,7 @@
 
 #include "utils/translation/poparser.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include "utils/translation/podict.h"
@@ -45,7 +45,7 @@ PoParser::PoParser() :
 void PoParser::openFile(const std::string &name)
 {
     int size;
-    char *buf = static_cast<char*>(PhysFs::loadFile(getFileName(name), size));
+    char *buf = static_cast<char*>(VirtFs::loadFile(getFileName(name), size));
 
     if (buf)
     {
@@ -261,7 +261,7 @@ PoDict *PoParser::getEmptyDict()
 bool PoParser::checkLang(const std::string &lang)
 {
     // check is po file exists
-    return PhysFs::exists(getFileName(lang).c_str());
+    return VirtFs::exists(getFileName(lang).c_str());
 }
 
 std::string PoParser::getFileName(const std::string &lang)
diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc
index e54d3dc9a..b59b1e098 100644
--- a/src/utils/translation/poparser_unittest.cc
+++ b/src/utils/translation/poparser_unittest.cc
@@ -29,7 +29,7 @@
 
 #include "utils/delete2.h"
 #include "utils/env.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 
 #include "utils/translation/podict.h"
 #include "utils/translation/poparser.h"
@@ -122,5 +122,5 @@ TEST_CASE("PoParser tests", "PoParser")
         delete dict;
     }
     delete2(client);
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp
index d7857a608..24342e8a1 100644
--- a/src/utils/translation/translationmanager.cpp
+++ b/src/utils/translation/translationmanager.cpp
@@ -21,7 +21,7 @@
 #include "utils/translation/translationmanager.h"
 
 #include "utils/delete2.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include "utils/translation/podict.h"
@@ -93,7 +93,7 @@ bool TranslationManager::translateFile(const std::string &fileName,
 
     int contentsLength;
     char *fileContents = static_cast<char*>(
-        PhysFs::loadFile(fileName, contentsLength));
+        VirtFs::loadFile(fileName, contentsLength));
 
     if (!fileContents)
     {
diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp
new file mode 100644
index 000000000..3211d91dd
--- /dev/null
+++ b/src/utils/virtfs.cpp
@@ -0,0 +1,205 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2013-2017  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/>.
+ */
+
+#include "utils/virtfs.h"
+
+#include "logger.h"
+
+#include <iostream>
+#include <unistd.h>
+
+#ifdef ANDROID
+#include "utils/paths.h"
+#endif  // ANDROID
+
+#include "debug.h"
+
+const char *dirSeparator = nullptr;
+
+namespace VirtFs
+{
+#if defined(__native_client__)
+    void init(const char *const name A_UNUSED)
+    {
+        if (!PHYSFS_init("/fakebinary"))
+#elif defined(ANDROID)
+    void init(const char *const name A_UNUSED)
+    {
+        if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str()))
+#else  // defined(__native_client__)
+
+    void init(const char *const name)
+    {
+        if (!PHYSFS_init(name))
+#endif  // defined(__native_client__)
+        {
+            std::cout << "Error while initializing PhysFS: "
+                << VirtFs::getLastError() << std::endl;
+            _exit(1);
+        }
+        updateDirSeparator();
+        atexit(reinterpret_cast<void(*)()>(PHYSFS_deinit));
+    }
+
+    void updateDirSeparator()
+    {
+        dirSeparator = PHYSFS_getDirSeparator();
+    }
+
+    const char *getDirSeparator()
+    {
+        return dirSeparator;
+    }
+
+    const char *getBaseDir()
+    {
+        return PHYSFS_getBaseDir();
+    }
+
+    const char *getUserDir()
+    {
+        return PHYSFS_getUserDir();
+    }
+
+    bool exists(const char *const fname)
+    {
+        return PHYSFS_exists(fname);
+    }
+
+    char **enumerateFiles(const char *const dir)
+    {
+        return PHYSFS_enumerateFiles(dir);
+    }
+
+    bool isDirectory(const char *const fname)
+    {
+        return PHYSFS_isDirectory(fname);
+    }
+
+    void freeList(void *const listVar)
+    {
+        PHYSFS_freeList(listVar);
+    }
+
+    PHYSFS_file *openRead(const char *const filename)
+    {
+        return PHYSFS_openRead(filename);
+    }
+
+    PHYSFS_file *openWrite(const char *const filename)
+    {
+        return PHYSFS_openWrite(filename);
+    }
+
+    PHYSFS_file *openAppend(const char *const filename)
+    {
+        return PHYSFS_openAppend(filename);
+    }
+
+    bool setWriteDir(const char *const newDir)
+    {
+        return PHYSFS_setWriteDir(newDir);
+    }
+
+    bool addToSearchPath(const char *const newDir, const int appendToPath)
+    {
+        return PHYSFS_addToSearchPath(newDir, appendToPath);
+    }
+
+    bool removeFromSearchPath(const char *const oldDir)
+    {
+        return PHYSFS_removeFromSearchPath(oldDir);
+    }
+
+    const char *getRealDir(const char *const filename)
+    {
+        return PHYSFS_getRealDir(filename);
+    }
+
+    bool mkdir(const char *const dirname)
+    {
+        return PHYSFS_mkdir(dirname);
+    }
+
+    void *loadFile(const std::string &fileName, int &fileSize)
+    {
+        // Attempt to open the specified file using PhysicsFS
+        PHYSFS_file *const file = VirtFs::openRead(fileName.c_str());
+
+        if (!file)
+        {
+            logger->log("Warning: Failed to load %s: %s",
+                fileName.c_str(),
+                VirtFs::getLastError());
+            return nullptr;
+        }
+
+        logger->log("Loaded %s/%s",
+            VirtFs::getRealDir(fileName.c_str()),
+            fileName.c_str());
+
+        fileSize = CAST_S32(VirtFs::fileLength(file));
+        // Allocate memory and load the file
+        void *const buffer = calloc(fileSize, 1);
+        VirtFs::read(file, buffer, 1, fileSize);
+        VirtFs::close(file);
+
+        return buffer;
+    }
+
+    bool deinit()
+    {
+        if (PHYSFS_deinit() != 0)
+        {
+            logger->log("Physfs deinit error: %s",
+                VirtFs::getLastError());
+            return false;
+        }
+        return true;
+    }
+
+    void permitLinks(const bool val)
+    {
+        PHYSFS_permitSymbolicLinks(val ? 1 : 0);
+    }
+
+    const char *getLastError()
+    {
+        return PHYSFS_getLastError();
+    }
+
+    void close(PHYSFS_file *const file)
+    {
+        PHYSFS_close(file);
+    }
+
+    int64_t read(PHYSFS_File *const file,
+                 void *const buffer,
+                 const uint32_t objSize,
+                 const uint32_t objCount)
+    {
+        return PHYSFS_read(file, buffer, objSize, objCount);
+    }
+
+    int64_t fileLength(PHYSFS_File *const file)
+    {
+        return PHYSFS_fileLength(file);
+    }
+}  // namespace PhysFs
diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h
new file mode 100644
index 000000000..8cbfe8c51
--- /dev/null
+++ b/src/utils/virtfs.h
@@ -0,0 +1,66 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2013-2017  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_PHYSFSTOOLS_H
+#define UTILS_PHYSFSTOOLS_H
+
+#include "localconsts.h"
+
+PRAGMA45(GCC diagnostic push)
+PRAGMA45(GCC diagnostic ignored "-Wlong-long")
+#include <physfs.h>
+PRAGMA45(GCC diagnostic pop)
+
+#include <string>
+
+namespace VirtFs
+{
+    void init(const char *const name);
+    void updateDirSeparator();
+    const char *getDirSeparator();
+    const char *getBaseDir();
+    const char *getUserDir();
+    bool exists(const char *const fname);
+    char **enumerateFiles(const char *const dir);
+    bool isDirectory(const char *const fname);
+    void freeList(void *const listVar);
+    PHYSFS_file *openRead(const char *const filename);
+    PHYSFS_file *openWrite(const char *const filename);
+    PHYSFS_file *openAppend(const char *const filename);
+    bool setWriteDir(const char *const newDir);
+    bool addToSearchPath(const char *const newDir, const int appendToPath);
+    bool removeFromSearchPath(const char *const oldDir);
+    const char *getRealDir(const char *const filename);
+    bool mkdir(const char *const dirName);
+    void *loadFile(const std::string &fileName, int &fileSize);
+    bool deinit();
+    void permitLinks(const bool val);
+    const char *getLastError();
+    int64_t read(PHYSFS_File *const handle,
+                 void *const buffer,
+                 const uint32_t objSize,
+                 const uint32_t objCount);
+    void close(PHYSFS_file *const file);
+    int64_t fileLength(PHYSFS_File *const file);
+}  // namespace PhysFs
+
+extern const char *dirSeparator;
+
+#endif  // UTILS_PHYSFSTOOLS_H
diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp
index c4764a1f9..dc0e6385a 100644
--- a/src/utils/xml/libxml.cpp
+++ b/src/utils/xml/libxml.cpp
@@ -26,7 +26,7 @@
 
 #include "utils/checkutils.h"
 #include "utils/fuzzer.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include "utils/translation/podict.h"
@@ -97,7 +97,7 @@ namespace XML
         valid = true;
         if (useResman == UseResman_true)
         {
-            data = static_cast<char*>(PhysFs::loadFile(
+            data = static_cast<char*>(VirtFs::loadFile(
                 filename.c_str(), size));
         }
         else
diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp
index 824fa336f..55ca0f60f 100644
--- a/src/utils/xml/pugixml.cpp
+++ b/src/utils/xml/pugixml.cpp
@@ -27,7 +27,7 @@
 #include "utils/checkutils.h"
 #include "utils/delete2.h"
 #include "utils/fuzzer.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include "utils/translation/podict.h"
@@ -75,7 +75,7 @@ namespace XML
         valid = true;
         if (useResman == UseResman_true)
         {
-            data = static_cast<char*>(PhysFs::loadFile(
+            data = static_cast<char*>(VirtFs::loadFile(
                 filename.c_str(), size));
         }
         else
diff --git a/src/utils/xml/pugixmlwriter.cpp b/src/utils/xml/pugixmlwriter.cpp
index 2a39e2325..1681cdfab 100644
--- a/src/utils/xml/pugixmlwriter.cpp
+++ b/src/utils/xml/pugixmlwriter.cpp
@@ -26,7 +26,7 @@
 
 #include "utils/delete2.h"
 #include "utils/fuzzer.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/stringutils.h"
 
 #include "utils/translation/podict.h"
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index b7461b617..575c61a5c 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -29,7 +29,7 @@
 
 #include "utils/delete2.h"
 #include "utils/env.h"
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #ifdef ENABLE_PUGIXML
 #include "utils/xmlwriter.h"
 #endif  // ENABLE_PUGIXML
@@ -358,5 +358,5 @@ TEST_CASE("xml doc")
     }
     delete2(theme);
     delete2(client);
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc
index ebd964262..ab70b7ec1 100644
--- a/src/utils/xmlutils_unittest.cc
+++ b/src/utils/xmlutils_unittest.cc
@@ -24,7 +24,7 @@
 #include "client.h"
 #include "logger.h"
 
-#include "utils/physfstools.h"
+#include "utils/virtfs.h"
 #include "utils/xml.h"
 
 #include "resources/resourcemanager/resourcemanager.h"
@@ -58,7 +58,7 @@ TEST_CASE("xmlutils readXmlIntVector 1")
     REQUIRE(1 == arr[3]);
     REQUIRE(1 == arr[4]);
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("xmlutils readXmlStringMap 1")
@@ -87,7 +87,7 @@ TEST_CASE("xmlutils readXmlStringMap 1")
     REQUIRE(arr["xD"] == "1");
     REQUIRE(arr["Metal"] == "26");
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
 
 TEST_CASE("xmlutils readXmlIntMap 1")
@@ -116,5 +116,5 @@ TEST_CASE("xmlutils readXmlIntMap 1")
     REQUIRE(arr[10] == 20);
     REQUIRE(arr[3] == 0);
     ResourceManager::deleteInstance();
-//    PhysFs::deinit();
+//    VirtFs::deinit();
 }
-- 
cgit v1.2.3-70-g09d2