diff options
Diffstat (limited to 'src')
47 files changed, 198 insertions, 171 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89d6f2595..1e14b48de 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -891,8 +891,8 @@ SET(SRCS utils/physfsmemoryobject.h utils/physfsrwops.cpp utils/physfsrwops.h - utils/physfstools.cpp - utils/physfstools.h + utils/virtfs.cpp + utils/virtfs.h utils/process.cpp utils/process.h utils/sdl2helper.cpp @@ -1769,8 +1769,8 @@ SET(DYE_CMD_SRCS utils/perfomance.h utils/physfsrwops.cpp utils/physfsrwops.h - utils/physfstools.cpp - utils/physfstools.h + utils/virtfs.cpp + utils/virtfs.h utils/sdl2helper.cpp utils/sdl2helper.h utils/sdlcheckutils.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 92b08af58..35f331b12 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -551,8 +551,8 @@ BASE_SRC += events/actionevent.h \ utils/physfsmemoryobject.h \ utils/physfsrwops.cpp \ utils/physfsrwops.h \ - utils/physfstools.cpp \ - utils/physfstools.h \ + utils/virtfs.cpp \ + utils/virtfs.h \ utils/process.cpp \ utils/process.h \ utils/sdl2helper.cpp \ diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 27189daea..b047c62cd 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -34,7 +34,7 @@ #include "configuration.h" #include "utils/mkdir.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "debug.h" diff --git a/src/client.cpp b/src/client.cpp index d45353c7b..1b7f1a1da 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -143,7 +143,7 @@ #ifdef ANDROID #include "utils/paths.h" #endif // ANDROID -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" diff --git a/src/configmanager.cpp b/src/configmanager.cpp index d248ac4dc..6a2f9f708 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -33,7 +33,7 @@ #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "render/renderers.h" diff --git a/src/dirs.cpp b/src/dirs.cpp index b00d49001..f27bc76f9 100644 --- a/src/dirs.cpp +++ b/src/dirs.cpp @@ -36,7 +36,7 @@ #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "resources/resourcemanager/resourcemanager.h" @@ -260,7 +260,7 @@ void Dirs::mountDataDir() void Dirs::initRootDir() { - settings.rootDir = PhysFs::getBaseDir(); + settings.rootDir = VirtFs::getBaseDir(); const std::string portableName = settings.rootDir + "portable.xml"; struct stat statbuf; @@ -332,16 +332,16 @@ void Dirs::initLocalDataDir() { #ifdef __APPLE__ // Use Application Directory instead of .mana - settings.localDataDir = std::string(PhysFs::getUserDir()) + + settings.localDataDir = std::string(VirtFs::getUserDir()) + "/Library/Application Support/" + branding.getValue("appName", "ManaPlus"); #elif defined __HAIKU__ - settings.localDataDir = std::string(PhysFs::getUserDir()) + + settings.localDataDir = std::string(VirtFs::getUserDir()) + "/config/data/Mana"; #elif defined WIN32 settings.localDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA); if (settings.localDataDir.empty()) - settings.localDataDir = std::string(PhysFs::getUserDir()); + settings.localDataDir = std::string(VirtFs::getUserDir()); settings.localDataDir.append("/Mana"); #elif defined __ANDROID__ settings.localDataDir = getSdStoragePath() + branding.getValue( @@ -350,7 +350,7 @@ void Dirs::initLocalDataDir() settings.localDataDir = _nacl_dir.append("/local"); #else // __APPLE__ - settings.localDataDir = std::string(PhysFs::getUserDir()) + + settings.localDataDir = std::string(VirtFs::getUserDir()) + ".local/share/mana"; #endif // __APPLE__ } @@ -389,7 +389,7 @@ void Dirs::initConfigDir() settings.configDir = settings.localDataDir + dirSeparator + branding.getValue("appShort", "mana"); #elif defined __HAIKU__ - settings.configDir = std::string(PhysFs::getUserDir()) + + settings.configDir = std::string(VirtFs::getUserDir()) + "/config/settings/Mana" + branding.getValue("appName", "ManaPlus"); #elif defined WIN32 @@ -410,7 +410,7 @@ void Dirs::initConfigDir() settings.configDir = _nacl_dir.append("/config"); #else // __APPLE__ - settings.configDir = std::string(PhysFs::getUserDir()).append( + settings.configDir = std::string(VirtFs::getUserDir()).append( "/.config/mana/").append(branding.getValue("appShort", "mana")); #endif // __APPLE__ @@ -490,9 +490,9 @@ void Dirs::initUpdatesDir() const std::string updateDir("/" + settings.updatesDir); // Verify that the updates directory exists. Create if necessary. - if (!PhysFs::isDirectory(updateDir.c_str())) + if (!VirtFs::isDirectory(updateDir.c_str())) { - if (!PhysFs::mkdir(updateDir.c_str())) + if (!VirtFs::mkdir(updateDir.c_str())) { #if defined WIN32 std::string newDir = settings.localDataDir + @@ -527,10 +527,10 @@ void Dirs::initUpdatesDir() } const std::string updateLocal = updateDir + "/local"; const std::string updateFix = updateDir + "/fix"; - if (!PhysFs::isDirectory(updateLocal.c_str())) - PhysFs::mkdir(updateLocal.c_str()); - if (!PhysFs::isDirectory(updateFix.c_str())) - PhysFs::mkdir(updateFix.c_str()); + if (!VirtFs::isDirectory(updateLocal.c_str())) + VirtFs::mkdir(updateLocal.c_str()); + if (!VirtFs::isDirectory(updateFix.c_str())) + VirtFs::mkdir(updateFix.c_str()); } void Dirs::initScreenshotDir() diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index 415c9779a..d32a08493 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -63,7 +63,7 @@ #include "utils/paths.h" #endif // ANDROID -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" diff --git a/src/dyetool/dyemain.cpp b/src/dyetool/dyemain.cpp index 0c728155b..7e0ed94a4 100644 --- a/src/dyetool/dyemain.cpp +++ b/src/dyetool/dyemain.cpp @@ -37,7 +37,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/gettext.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include <iostream> @@ -74,7 +74,7 @@ int main(int argc, char **argv) logger = new Logger; logger->setLogToStandardOut(false); - PhysFs::init(argv[0]); + VirtFs::init(argv[0]); SDL_Init(SDL_INIT_VIDEO); graphicsManager.createWindow(10, 10, 0, SDL_ANYFORMAT); diff --git a/src/game.cpp b/src/game.cpp index aca47029a..69bf2fd9c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -121,7 +121,7 @@ #include "utils/delete2.h" #include "utils/gettext.h" #include "utils/mkdir.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" @@ -531,7 +531,7 @@ bool Game::saveScreenshot(SDL_Surface *const screenshot) logger->log("Directory %s doesn't exist and can't be created! " "Setting screenshot directory to home.", screenshotDirectory.c_str()); - screenshotDirectory = std::string(PhysFs::getUserDir()); + screenshotDirectory = std::string(VirtFs::getUserDir()); } // Search for an unused screenshot name @@ -1055,7 +1055,7 @@ void Game::changeMap(const std::string &mapPath) std::string realFullMap = paths.getValue("maps", "maps/").append( MapDB::getMapName(mMapName)).append(".tmx"); - if (!PhysFs::exists(realFullMap.c_str())) + if (!VirtFs::exists(realFullMap.c_str())) realFullMap.append(".gz"); // Attempt to load the new map diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 76a5d0a94..a60b01e99 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -46,7 +46,7 @@ #include "utils/dtor.h" #include "utils/files.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "debug.h" @@ -64,7 +64,7 @@ static void initDefaultThemePath() defaultThemePath = branding.getStringValue("guiThemePath"); logger->log("defaultThemePath: " + defaultThemePath); - if (!defaultThemePath.empty() && PhysFs::isDirectory( + if (!defaultThemePath.empty() && VirtFs::isDirectory( defaultThemePath.c_str())) { return; @@ -397,7 +397,7 @@ Skin *Theme::readSkin(const std::string &filename, const bool full) return nullptr; const std::string path = resolveThemePath(filename); - if (!PhysFs::exists(path.c_str())) + if (!VirtFs::exists(path.c_str())) return nullptr; XML::Document *const doc = Loader::getXml(path, UseResman_true, @@ -550,7 +550,7 @@ bool Theme::tryThemePath(const std::string &themeName) if (!themeName.empty()) { const std::string path = defaultThemePath + themeName; - if (PhysFs::exists(path.c_str())) + if (VirtFs::exists(path.c_str())) { mThemePath = path; mThemeName = themeName; @@ -570,19 +570,19 @@ void Theme::fillSkinsList(StringVect &list) void Theme::fillFontsList(StringVect &list) { - PhysFs::permitLinks(true); + VirtFs::permitLinks(true); Files::getFiles(branding.getStringValue("fontsPath"), list); - PhysFs::permitLinks(false); + VirtFs::permitLinks(false); } void Theme::fillSoundsList(StringVect &list) { - char **skins = PhysFs::enumerateFiles( + char **skins = VirtFs::enumerateFiles( branding.getStringValue("systemsounds").c_str()); for (char **i = skins; *i; i++) { - if (!PhysFs::isDirectory(( + if (!VirtFs::isDirectory(( branding.getStringValue("systemsounds") + *i).c_str())) { std::string str = *i; @@ -591,7 +591,7 @@ void Theme::fillSoundsList(StringVect &list) } } - PhysFs::freeList(skins); + VirtFs::freeList(skins); } void Theme::selectSkin() @@ -637,14 +637,14 @@ std::string Theme::resolveThemePath(const std::string &path) if (file.find('/') != std::string::npos) { // Might be a valid path already - if (PhysFs::exists(file.c_str())) + if (VirtFs::exists(file.c_str())) return path; } // Try the theme file = getThemePath().append("/").append(file); - if (PhysFs::exists(file.c_str())) + if (VirtFs::exists(file.c_str())) return getThemePath().append("/").append(path); // Backup diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index b31758cbd..dfa9757b5 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -171,5 +171,5 @@ TEST_CASE("BrowserBox tests", "browserbox") delete box; delete client; client = nullptr; -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc index c3c62724c..d3dc57b3e 100644 --- a/src/gui/windowmanager_unittest.cc +++ b/src/gui/windowmanager_unittest.cc @@ -117,7 +117,7 @@ #include "utils/delete2.h" #include "utils/env.h" #include "utils/gettext.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/translation/translationmanager.h" @@ -296,7 +296,7 @@ TEST_CASE("Windows tests", "windowmanager") SECTION("EditServerDialog") { ServerInfo mCurrentServer; - settings.configDir = PhysFs::getRealDir("test/serverlistplus.xml"); + settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml"); ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog, &mCurrentServer, settings.configDir); @@ -505,7 +505,7 @@ TEST_CASE("Windows tests", "windowmanager") SECTION("serversDialog") { ServerInfo mCurrentServer; - settings.configDir = PhysFs::getRealDir("test/serverlistplus.xml"); + settings.configDir = VirtFs::getRealDir("test/serverlistplus.xml"); ServerDialog *serverDialog = CREATEWIDGETR(ServerDialog, &mCurrentServer, settings.configDir); @@ -681,5 +681,5 @@ TEST_CASE("Windows tests", "windowmanager") delete2(client); delete2(serverFeatures); delete2(inventoryHandler); -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index d5947d934..ce316b1eb 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -50,7 +50,7 @@ #include "resources/loaders/imageloader.h" #include "utils/gettext.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "debug.h" @@ -180,14 +180,14 @@ void Minimap::setMap(const Map *const map) std::string minimapName = map->getProperty("minimap"); - if (minimapName.empty() && PhysFs::exists(tempname.c_str())) + if (minimapName.empty() && VirtFs::exists(tempname.c_str())) minimapName = tempname; if (minimapName.empty()) { tempname = std::string("graphics/minimaps/").append( map->getFilename()).append(".png"); - if (PhysFs::exists(tempname.c_str())) + if (VirtFs::exists(tempname.c_str())) minimapName = tempname; } diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index 3bf1d0e7b..645ec0e84 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -47,7 +47,7 @@ #include "utils/delete2.h" #include "utils/files.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" @@ -1066,7 +1066,7 @@ unsigned long UpdaterWindow::getFileHash(const std::string &filePath) { int size = 0; const char *const buf = static_cast<const char*>( - PhysFs::loadFile(filePath, size)); + VirtFs::loadFile(filePath, size)); if (!buf) return 0; return Net::Download::adlerBuffer(buf, size); diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc index e3e2a29cb..86317dc40 100644 --- a/src/integrity_unittest.cc +++ b/src/integrity_unittest.cc @@ -79,7 +79,7 @@ static bool compareBuffers(const unsigned char *const buf2) bool isCorrect(true); int sz = 0; unsigned char *buf1 = static_cast<unsigned char*>( - PhysFs::loadFile("hide.png", sz)); + VirtFs::loadFile("hide.png", sz)); REQUIRE(buf1 != nullptr); REQUIRE(sz == 368); for (int f = 0; f < sz; f ++) @@ -242,7 +242,7 @@ TEST_CASE("integrity tests", "integrity") SDL_RWops *const rw = PHYSFSRWOPS_openRead(name1); if (!rw) - logger->log("Physfs error: %s", PhysFs::getLastError()); + logger->log("Physfs error: %s", VirtFs::getLastError()); resourceManager->removeFromSearchPath("data/test/test.zip"); resourceManager->removeFromSearchPath("../data/test/test.zip"); REQUIRE(rw != nullptr); @@ -405,7 +405,7 @@ TEST_CASE("integrity tests", "integrity") SDL_RWops *const rw = PHYSFSRWOPS_openRead(name1); if (!rw) - logger->log("Physfs error: %s", PhysFs::getLastError()); + logger->log("Physfs error: %s", VirtFs::getLastError()); REQUIRE(rw != nullptr); int64_t seek = SDL_RWseek(rw, 0, RW_SEEK_END); if (seek == -1) @@ -440,7 +440,7 @@ TEST_CASE("integrity tests", "integrity") SDL_RWops *const rw = PHYSFSRWOPS_openRead(name1); if (!rw) - logger->log("Physfs error: %s", PhysFs::getLastError()); + logger->log("Physfs error: %s", VirtFs::getLastError()); REQUIRE(rw != nullptr); if (IMG_isPNG(rw) == false) { @@ -462,7 +462,7 @@ TEST_CASE("integrity tests", "integrity") SDL_RWops *const rw = PHYSFSRWOPS_openRead(name1); if (!rw) - logger->log("Physfs error: %s", PhysFs::getLastError()); + logger->log("Physfs error: %s", VirtFs::getLastError()); REQUIRE(rw != nullptr); Resource *const res = imageHelper->load(rw); resourceManager->removeFromSearchPath("data/test/test.zip"); @@ -487,5 +487,5 @@ TEST_CASE("integrity tests", "integrity") delete client; client = nullptr; -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/maingui.cpp b/src/maingui.cpp index df28856fe..6f8de4083 100644 --- a/src/maingui.cpp +++ b/src/maingui.cpp @@ -96,7 +96,7 @@ int mainGui(int argc, char *argv[]) mkdir_r(getSdStoragePath().c_str()); #endif // ANDROID - PhysFs::init(argv[0]); + VirtFs::init(argv[0]); XML::initXML(); #if SDL_IMAGE_VERSION_ATLEAST(1, 2, 11) IMG_Init(IMG_INIT_PNG); @@ -106,7 +106,7 @@ int mainGui(int argc, char *argv[]) #endif // SDL_MIXER_VERSION_ATLEAST(1, 2, 11) #ifdef WIN32 - SetCurrentDirectory(PhysFs::getBaseDir()); + SetCurrentDirectory(VirtFs::getBaseDir()); #endif // WIN32 setPriority(true); @@ -144,7 +144,7 @@ int mainGui(int argc, char *argv[]) int main(int argc, char *argv[]) { - PhysFs::init(argv[0]); + VirtFs::init(argv[0]); return Catch::Session().run(argc, argv); } diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp index 90b72b4d6..7299e76d3 100644 --- a/src/resources/atlas/atlasmanager.cpp +++ b/src/resources/atlas/atlasmanager.cpp @@ -168,7 +168,7 @@ void AtlasManager::loadImages(const StringVect &files, } else { - reportAlways("Physfs error: %s", PhysFs::getLastError()); + reportAlways("Physfs error: %s", VirtFs::getLastError()); } delete d; } diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc index 370800675..f3d4fe3ba 100644 --- a/src/resources/dye/dye_unittest.cc +++ b/src/resources/dye/dye_unittest.cc @@ -42,7 +42,7 @@ #include "utils/delete2.h" #include "utils/env.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #ifndef USE_SDL2 #include <SDL.h> @@ -2391,5 +2391,5 @@ TEST_CASE("Dye real dye") dyeCheck("|A:#0000FFFF,FF000050", "arrow_up_A.png"); } delete2(client); -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc index 295a7cac9..42770e878 100644 --- a/src/resources/dye/dyepalette_unittest.cc +++ b/src/resources/dye/dyepalette_unittest.cc @@ -41,7 +41,7 @@ #include "utils/delete2.h" #include "utils/env.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #ifndef USE_SDL2 #include <SDL.h> @@ -381,5 +381,5 @@ TEST_CASE("DyePalette tests") REQUIRE(palette.mColors[0].value[3] == 0x77); } delete2(client); -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/resources/loaders/imageloader.cpp b/src/resources/loaders/imageloader.cpp index 21e7479f4..4fada1f44 100644 --- a/src/resources/loaders/imageloader.cpp +++ b/src/resources/loaders/imageloader.cpp @@ -67,7 +67,7 @@ namespace { delete d; reportAlways("Image loading error: %s", path1.c_str()); - reportAlways("Physfs error: %s", PhysFs::getLastError()); + reportAlways("Physfs error: %s", VirtFs::getLastError()); BLOCK_END("DyedImageLoader::load") return nullptr; } diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp index 4610911bb..7b0cda647 100644 --- a/src/resources/loaders/musicloader.cpp +++ b/src/resources/loaders/musicloader.cpp @@ -48,7 +48,7 @@ namespace SDL_RWops *const rw = MPHYSFSRWOPS_openRead(rl->path.c_str()); if (!rw) { - reportAlways("Physfs error: %s", PhysFs::getLastError()); + reportAlways("Physfs error: %s", VirtFs::getLastError()); reportAlways("Error loading resource: %s", rl->path.c_str()); return nullptr; diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp index 0934c1852..569d2dfbe 100644 --- a/src/resources/loaders/soundloader.cpp +++ b/src/resources/loaders/soundloader.cpp @@ -48,7 +48,7 @@ namespace SDL_RWops *const rw = MPHYSFSRWOPS_openRead(rl->path.c_str()); if (!rw) { - reportAlways("Physfs error: %s", PhysFs::getLastError()); + reportAlways("Physfs error: %s", VirtFs::getLastError()); reportAlways("Error loading resource: %s", rl->path.c_str()); return nullptr; diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 5cd8affb9..afc2bbffd 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -63,7 +63,7 @@ #include "utils/delete2.h" #include "utils/dtor.h" #include "utils/mkdir.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/timer.h" #include <queue> diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 14adad5e2..414b87987 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -58,7 +58,7 @@ #include "utils/base64.h" #include "utils/checkutils.h" #include "utils/delete2.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "utils/stringmap.h" #include "utils/translation/podict.h" @@ -1279,7 +1279,7 @@ void MapReader::updateMusic(Map *const map) if (p != std::string::npos) name = name.substr(0, p); name.append(".ogg"); - if (PhysFs::exists(paths.getStringValue("music").append(name).c_str())) + if (VirtFs::exists(paths.getStringValue("music").append(name).c_str())) map->setProperty("music", name); } diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp index 0612fdbb4..8b51b1ec2 100644 --- a/src/resources/resourcemanager/resourcemanager.cpp +++ b/src/resources/resourcemanager/resourcemanager.cpp @@ -336,7 +336,7 @@ void ResourceManager::clearDeleted(const bool full) } bool ResourceManager::setWriteDir(const std::string &path) const { - return static_cast<bool>(PhysFs::setWriteDir(path.c_str())); + return static_cast<bool>(VirtFs::setWriteDir(path.c_str())); } bool ResourceManager::addToSearchPath(const std::string &path, @@ -344,12 +344,12 @@ bool ResourceManager::addToSearchPath(const std::string &path, { logger->log("Adding to PhysicsFS: %s (%s)", path.c_str(), append == Append_true ? "append" : "prepend"); - if (!PhysFs::addToSearchPath(path.c_str(), + if (!VirtFs::addToSearchPath(path.c_str(), append == Append_true ? 1 : 0)) { logger->log("Error: %s: addToSearchPath failed: %s", path.c_str(), - PhysFs::getLastError()); + VirtFs::getLastError()); return false; } return true; @@ -358,11 +358,11 @@ bool ResourceManager::addToSearchPath(const std::string &path, bool ResourceManager::removeFromSearchPath(const std::string &path) const { logger->log("Removing from PhysicsFS: %s", path.c_str()); - if (!PhysFs::removeFromSearchPath(path.c_str())) + if (!VirtFs::removeFromSearchPath(path.c_str())) { logger->log("Error: %s: removeFromSearchPath failed: %s", path.c_str(), - PhysFs::getLastError()); + VirtFs::getLastError()); return false; } return true; @@ -373,7 +373,7 @@ void ResourceManager::searchAndAddArchives(const std::string &restrict path, const Append append) const { const char *const dirSep = dirSeparator; - char **list = PhysFs::enumerateFiles(path.c_str()); + char **list = VirtFs::enumerateFiles(path.c_str()); for (char **i = list; *i; i++) { @@ -383,13 +383,13 @@ void ResourceManager::searchAndAddArchives(const std::string &restrict path, { const std::string file = path + (*i); const std::string realPath = std::string( - PhysFs::getRealDir(file.c_str())); + VirtFs::getRealDir(file.c_str())); addToSearchPath(std::string(realPath).append( dirSep).append(file), append); } } - PhysFs::freeList(list); + VirtFs::freeList(list); } void ResourceManager::searchAndRemoveArchives(const std::string &restrict path, @@ -397,7 +397,7 @@ void ResourceManager::searchAndRemoveArchives(const std::string &restrict path, const { const char *const dirSep = dirSeparator; - char **list = PhysFs::enumerateFiles(path.c_str()); + char **list = VirtFs::enumerateFiles(path.c_str()); for (char **i = list; *i; i++) { @@ -406,13 +406,13 @@ void ResourceManager::searchAndRemoveArchives(const std::string &restrict path, { const std::string file = path + (*i); const std::string realPath = std::string( - PhysFs::getRealDir(file.c_str())); + VirtFs::getRealDir(file.c_str())); removeFromSearchPath(std::string(realPath).append( dirSep).append(file)); } } - PhysFs::freeList(list); + VirtFs::freeList(list); } bool ResourceManager::addResource(const std::string &idPath, diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc index 2019f20d8..684f2d839 100644 --- a/src/resources/resourcemanager/resourcemanager_unittest.cc +++ b/src/resources/resourcemanager/resourcemanager_unittest.cc @@ -30,7 +30,7 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/env.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include <unistd.h> @@ -659,5 +659,5 @@ TEST_CASE("resourcemanager", "resourcemanager") resourceManager = safeResman; delete client; client = nullptr; -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc index a46fad9b0..17746f65c 100644 --- a/src/resources/sprite/animatedsprite_unittest.cc +++ b/src/resources/sprite/animatedsprite_unittest.cc @@ -41,7 +41,7 @@ #include "utils/env.h" #include "utils/mrand.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #ifndef USE_SDL2 #include <SDL.h> @@ -181,5 +181,5 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite") delete client; client = nullptr; -// PhysFs::deinit(); +// VirtFs::deinit(); } diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 0dadb9737..b98b9eb67 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -26,7 +26,7 @@ #include "resources/wallpaperdata.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include <algorithm> @@ -54,21 +54,21 @@ static void initDefaultWallpaperPaths() // Init the path wallpaperPath = branding.getStringValue("wallpapersPath"); - if (wallpaperPath.empty() || !PhysFs::isDirectory(wallpaperPath.c_str())) + if (wallpaperPath.empty() || !VirtFs::isDirectory(wallpaperPath.c_str())) wallpaperPath = paths.getValue("wallpapers", ""); - if (wallpaperPath.empty() || !PhysFs::isDirectory(wallpaperPath.c_str())) + if (wallpaperPath.empty() || !VirtFs::isDirectory(wallpaperPath.c_str())) wallpaperPath = "graphics/images/"; // Init the default file wallpaperFile = branding.getStringValue("wallpaperFile"); - if (!wallpaperFile.empty() && !PhysFs::isDirectory(wallpaperFile.c_str())) + if (!wallpaperFile.empty() && !VirtFs::isDirectory(wallpaperFile.c_str())) return; else wallpaperFile = paths.getValue("wallpaperFile", ""); - if (wallpaperFile.empty() || PhysFs::isDirectory(wallpaperFile.c_str())) + if (wallpaperFile.empty() || VirtFs::isDirectory(wallpaperFile.c_str())) wallpaperFile = "login_wallpaper.png"; } @@ -84,7 +84,7 @@ void Wallpaper::loadWallpapers() { wallpaperData.clear(); initDefaultWallpaperPaths(); - char **const imgs = PhysFs::enumerateFiles(wallpaperPath.c_str()); + char **const imgs = VirtFs::enumerateFiles(wallpaperPath.c_str()); for (char *const *i = imgs; *i; i++) { @@ -121,7 +121,7 @@ void Wallpaper::loadWallpapers() } } - PhysFs::freeList(imgs); + VirtFs::freeList(imgs); std::sort(wallpaperData.begin(), wallpaperData.end(), &wallpaperCompare); } diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index 00d285ca5..026a987ed 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -35,7 +35,7 @@ #include "resources/loaders/soundloader.h" #include "utils/checkutils.h" -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include <SDL.h> @@ -325,7 +325,7 @@ static SDLMusic *loadMusic(const std::string &fileName, const SkipError skipError) { const std::string path = paths.getStringValue("music").append(fileName); - if (!PhysFs::exists(path.c_str())) + if (!VirtFs::exists(path.c_str())) { if (skipError == SkipError_false) reportAlways("Music file not found: %s", fileName.c_str()); 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/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/physfstools.cpp b/src/utils/virtfs.cpp index cc17c09b3..3211d91dd 100644 --- a/src/utils/physfstools.cpp +++ b/src/utils/virtfs.cpp @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "utils/physfstools.h" +#include "utils/virtfs.h" #include "logger.h" @@ -33,7 +33,7 @@ const char *dirSeparator = nullptr; -namespace PhysFs +namespace VirtFs { #if defined(__native_client__) void init(const char *const name A_UNUSED) @@ -51,7 +51,7 @@ namespace PhysFs #endif // defined(__native_client__) { std::cout << "Error while initializing PhysFS: " - << PHYSFS_getLastError() << std::endl; + << VirtFs::getLastError() << std::endl; _exit(1); } updateDirSeparator(); @@ -141,23 +141,25 @@ namespace PhysFs 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()); + PHYSFS_file *const file = VirtFs::openRead(fileName.c_str()); if (!file) { logger->log("Warning: Failed to load %s: %s", - fileName.c_str(), PHYSFS_getLastError()); + fileName.c_str(), + VirtFs::getLastError()); return nullptr; } - logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()), + logger->log("Loaded %s/%s", + VirtFs::getRealDir(fileName.c_str()), fileName.c_str()); - fileSize = CAST_S32(PHYSFS_fileLength(file)); + fileSize = CAST_S32(VirtFs::fileLength(file)); // Allocate memory and load the file void *const buffer = calloc(fileSize, 1); - PHYSFS_read(file, buffer, 1, fileSize); - PHYSFS_close(file); + VirtFs::read(file, buffer, 1, fileSize); + VirtFs::close(file); return buffer; } @@ -166,7 +168,8 @@ namespace PhysFs { if (PHYSFS_deinit() != 0) { - logger->log("Physfs deinit error: %s", PHYSFS_getLastError()); + logger->log("Physfs deinit error: %s", + VirtFs::getLastError()); return false; } return true; @@ -181,4 +184,22 @@ namespace PhysFs { 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/physfstools.h b/src/utils/virtfs.h index 3db197927..8cbfe8c51 100644 --- a/src/utils/physfstools.h +++ b/src/utils/virtfs.h @@ -30,7 +30,7 @@ PRAGMA45(GCC diagnostic pop) #include <string> -namespace PhysFs +namespace VirtFs { void init(const char *const name); void updateDirSeparator(); @@ -53,6 +53,12 @@ namespace PhysFs 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; 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(); } |