From fc60e6391b53c7e272bbbfe81e34f64ceb92fe06 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Feb 2017 17:08:42 +0300 Subject: Move virt fs related files into fs directory. --- src/CMakeLists.txt | 48 +-- src/Makefile.am | 26 +- src/chatlogger.cpp | 4 +- src/client.cpp | 15 +- src/configmanager.cpp | 3 +- src/dirs.cpp | 3 +- src/dyetool/client.cpp | 15 +- src/dyetool/dyemain.cpp | 3 +- src/fs/virtfile.cpp | 37 ++ src/fs/virtfile.h | 39 ++ src/fs/virtfileprivate.cpp | 42 ++ src/fs/virtfileprivate.h | 44 +++ src/fs/virtfs.cpp | 304 +++++++++++++++ src/fs/virtfs.h | 79 ++++ src/fs/virtfs_unittest.cc | 406 +++++++++++++++++++ src/fs/virtfsrwops.cpp | 434 +++++++++++++++++++++ src/fs/virtfsrwops.h | 75 ++++ src/fs/virtfstools.cpp | 223 +++++++++++ src/fs/virtfstools.h | 54 +++ src/fs/virtlist.cpp | 32 ++ src/fs/virtlist.h | 39 ++ src/game.cpp | 17 +- src/gui/fonts/font.cpp | 3 +- src/gui/theme.cpp | 7 +- src/gui/widgets/browserbox_unittest.cc | 3 +- src/gui/windowmanager.cpp | 3 +- src/gui/windowmanager_unittest.cc | 3 +- src/gui/windows/chatwindow.cpp | 3 +- src/gui/windows/helpwindow.cpp | 5 +- src/gui/windows/minimap.cpp | 3 +- src/gui/windows/updaterwindow.cpp | 5 +- src/integrity_unittest.cc | 7 +- src/maingui.cpp | 5 +- src/render/shaders/shadersmanager.cpp | 2 +- src/resources/atlas/atlasmanager.cpp | 5 +- src/resources/beingcommon.h | 3 +- src/resources/db/badgesdb.cpp | 3 +- src/resources/db/itemdb.cpp | 3 +- src/resources/db/palettedb.cpp | 3 +- src/resources/dye/dye_unittest.cc | 3 +- src/resources/dye/dyepalette_unittest.cc | 3 +- src/resources/loaders/imageloader.cpp | 5 +- src/resources/loaders/musicloader.cpp | 5 +- src/resources/loaders/soundloader.cpp | 5 +- src/resources/map/map.cpp | 19 +- src/resources/map/maplayer_unittest.cc | 3 +- src/resources/map/speciallayer_unittest.cc | 3 +- src/resources/mapreader.cpp | 3 +- .../resourcemanager/resourcemanager_unittest.cc | 3 +- src/resources/sprite/animatedsprite_unittest.cc | 3 +- src/resources/wallpaper.cpp | 6 +- src/soundmanager.cpp | 3 +- src/test/testlauncher.cpp | 4 +- src/utils/chatutils_unittest.cc | 3 +- src/utils/files.cpp | 7 +- src/utils/files_unittest.cc | 5 +- src/utils/gettexthelper.cpp | 2 +- src/utils/paths.cpp | 3 +- src/utils/stringutils_unittest.cc | 3 +- src/utils/translation/poparser.cpp | 5 +- src/utils/translation/poparser_unittest.cc | 3 +- src/utils/translation/translationmanager.cpp | 3 +- src/utils/virtfile.cpp | 36 -- src/utils/virtfile.h | 39 -- src/utils/virtfileprivate.cpp | 42 -- src/utils/virtfileprivate.h | 44 --- src/utils/virtfs.cpp | 303 -------------- src/utils/virtfs.h | 79 ---- src/utils/virtfs_unittest.cc | 405 ------------------- src/utils/virtfsrwops.cpp | 433 -------------------- src/utils/virtfsrwops.h | 75 ---- src/utils/virtfstools.cpp | 222 ----------- src/utils/virtfstools.h | 54 --- src/utils/virtlist.cpp | 32 -- src/utils/virtlist.h | 39 -- src/utils/xml/libxml.cpp | 3 +- src/utils/xml/pugixml.cpp | 3 +- src/utils/xml/pugixmlwriter.cpp | 3 +- src/utils/xml_unittest.cc | 3 +- src/utils/xmlutils_unittest.cc | 3 +- 80 files changed, 1991 insertions(+), 1937 deletions(-) create mode 100644 src/fs/virtfile.cpp create mode 100644 src/fs/virtfile.h create mode 100644 src/fs/virtfileprivate.cpp create mode 100644 src/fs/virtfileprivate.h create mode 100644 src/fs/virtfs.cpp create mode 100644 src/fs/virtfs.h create mode 100644 src/fs/virtfs_unittest.cc create mode 100644 src/fs/virtfsrwops.cpp create mode 100644 src/fs/virtfsrwops.h create mode 100644 src/fs/virtfstools.cpp create mode 100644 src/fs/virtfstools.h create mode 100644 src/fs/virtlist.cpp create mode 100644 src/fs/virtlist.h delete mode 100644 src/utils/virtfile.cpp delete mode 100644 src/utils/virtfile.h delete mode 100644 src/utils/virtfileprivate.cpp delete mode 100644 src/utils/virtfileprivate.h delete mode 100644 src/utils/virtfs.cpp delete mode 100644 src/utils/virtfs.h delete mode 100644 src/utils/virtfs_unittest.cc delete mode 100644 src/utils/virtfsrwops.cpp delete mode 100644 src/utils/virtfsrwops.h delete mode 100644 src/utils/virtfstools.cpp delete mode 100644 src/utils/virtfstools.h delete mode 100644 src/utils/virtlist.cpp delete mode 100644 src/utils/virtlist.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 910817468..ca320b926 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -887,14 +887,14 @@ SET(SRCS utils/perfomance.cpp utils/perfomance.h utils/debugmemoryobject.h - utils/virtfsrwops.cpp - utils/virtfsrwops.h - utils/virtfstools.cpp - utils/virtfstools.h - utils/virtlist.cpp - utils/virtlist.h - utils/virtfs.cpp - utils/virtfs.h + fs/virtfsrwops.cpp + fs/virtfsrwops.h + fs/virtfstools.cpp + fs/virtfstools.h + fs/virtlist.cpp + fs/virtlist.h + fs/virtfs.cpp + fs/virtfs.h utils/process.cpp utils/process.h utils/sdl2helper.cpp @@ -910,10 +910,10 @@ SET(SRCS utils/stringvector.h utils/timer.cpp utils/timer.h - utils/virtfile.cpp - utils/virtfile.h - utils/virtfileprivate.cpp - utils/virtfileprivate.h + fs/virtfile.cpp + fs/virtfile.h + fs/virtfileprivate.cpp + fs/virtfileprivate.h utils/mutex.h utils/naclmessages.cpp utils/naclmessages.h @@ -1773,14 +1773,14 @@ SET(DYE_CMD_SRCS utils/paths.h utils/perfomance.cpp utils/perfomance.h - utils/virtfsrwops.cpp - utils/virtfsrwops.h - utils/virtfstools.cpp - utils/virtfstools.h - utils/virtlist.cpp - utils/virtlist.h - utils/virtfs.cpp - utils/virtfs.h + fs/virtfsrwops.cpp + fs/virtfsrwops.h + fs/virtfstools.cpp + fs/virtfstools.h + fs/virtlist.cpp + fs/virtlist.h + fs/virtfs.cpp + fs/virtfs.h utils/sdl2helper.cpp utils/sdl2helper.h utils/sdlcheckutils.cpp @@ -1792,10 +1792,10 @@ SET(DYE_CMD_SRCS utils/stringutils.h utils/timer.cpp utils/timer.h - utils/virtfile.cpp - utils/virtfile.h - utils/virtfileprivate.cpp - utils/virtfileprivate.h + fs/virtfile.cpp + fs/virtfile.h + fs/virtfileprivate.cpp + fs/virtfileprivate.h utils/xml.cpp utils/xml.h utils/xml.inc diff --git a/src/Makefile.am b/src/Makefile.am index ff345a292..6c5b2d4e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -551,14 +551,14 @@ BASE_SRC += events/actionevent.h \ utils/perfomance.cpp \ utils/perfomance.h \ utils/debugmemoryobject.h \ - utils/virtfsrwops.cpp \ - utils/virtfsrwops.h \ - utils/virtfstools.cpp \ - utils/virtfstools.h \ - utils/virtlist.cpp \ - utils/virtlist.h \ - utils/virtfs.cpp \ - utils/virtfs.h \ + fs/virtfsrwops.cpp \ + fs/virtfsrwops.h \ + fs/virtfstools.cpp \ + fs/virtfstools.h \ + fs/virtlist.cpp \ + fs/virtlist.h \ + fs/virtfs.cpp \ + fs/virtfs.h \ utils/process.cpp \ utils/process.h \ utils/sdl2helper.cpp \ @@ -576,10 +576,10 @@ BASE_SRC += events/actionevent.h \ utils/stringvector.h \ utils/timer.cpp \ utils/timer.h \ - utils/virtfile.cpp \ - utils/virtfile.h \ - utils/virtfileprivate.cpp \ - utils/virtfileprivate.h \ + fs/virtfile.cpp \ + fs/virtfile.h \ + fs/virtfileprivate.cpp \ + fs/virtfileprivate.h \ utils/mutex.h \ utils/naclmessages.cpp \ utils/naclmessages.h \ @@ -1919,7 +1919,7 @@ manaplustests_SOURCES = ${SRC} \ enums/enums_unittest.cc \ utils/dumplibs_unittest.cc \ utils/checkutils_unittest.cc \ - utils/virtfs_unittest.cc \ + fs/virtfs_unittest.cc \ utils/xml_unittest.cc \ utils/timer_unittest.cc \ utils/xmlutils_unittest.cc \ diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index b047c62cd..1f6fae035 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -33,8 +33,10 @@ #endif // WIN32 #include "configuration.h" + +#include "fs/virtfs.h" + #include "utils/mkdir.h" -#include "utils/virtfs.h" #include "debug.h" diff --git a/src/client.cpp b/src/client.cpp index 5aae6960c..e87ac65cb 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -42,11 +42,8 @@ #include "enums/being/attributesstrings.h" -#include "input/inputmanager.h" -#include "input/joystick.h" -#include "input/keyboardconfig.h" - -#include "input/touch/touchmanager.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" #include "gui/dialogsmanager.h" #include "gui/gui.h" @@ -79,6 +76,12 @@ #include "gui/widgets/desktop.h" #include "gui/widgets/windowcontainer.h" +#include "input/inputmanager.h" +#include "input/joystick.h" +#include "input/keyboardconfig.h" + +#include "input/touch/touchmanager.h" + #include "net/charserverhandler.h" #include "net/chathandler.h" #include "net/download.h" @@ -143,8 +146,6 @@ #ifdef ANDROID #include "utils/paths.h" #endif // ANDROID -#include "utils/virtfs.h" -#include "utils/virtfstools.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 7acc8ebf5..95aac7ed1 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -29,11 +29,12 @@ #include "being/beingspeech.h" +#include "fs/virtfs.h" + #include "utils/files.h" #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" -#include "utils/virtfs.h" #include "render/renderers.h" diff --git a/src/dirs.cpp b/src/dirs.cpp index c1cd3ac49..43f27ae4c 100644 --- a/src/dirs.cpp +++ b/src/dirs.cpp @@ -28,6 +28,8 @@ #include "main.h" #include "settings.h" +#include "fs/virtfs.h" + #include "utils/base64.h" #if defined(__native_client__) || (defined(ANDROID) && defined(USE_SDL2)) #include "utils/files.h" @@ -36,7 +38,6 @@ #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" -#include "utils/virtfs.h" #ifdef ANDROID #ifdef USE_SDL2 diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index 3fdae7e14..0ee7d0c2c 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -30,11 +30,8 @@ #include "settings.h" #include "soundmanager.h" -#include "input/inputmanager.h" -#include "input/joystick.h" -#include "input/keyboardconfig.h" - -#include "input/touch/touchmanager.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" #include "gui/dialogsmanager.h" #include "gui/gui.h" @@ -48,6 +45,12 @@ #include "gui/widgets/windowcontainer.h" #include "gui/widgets/window.h" +#include "input/inputmanager.h" +#include "input/joystick.h" +#include "input/keyboardconfig.h" + +#include "input/touch/touchmanager.h" + #include "resources/imagehelper.h" #include "resources/resourcemanager/resourcemanager.h" @@ -63,8 +66,6 @@ #include "utils/paths.h" #endif // ANDROID -#include "utils/virtfs.h" -#include "utils/virtfstools.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" diff --git a/src/dyetool/dyemain.cpp b/src/dyetool/dyemain.cpp index 433233143..e36bf8547 100644 --- a/src/dyetool/dyemain.cpp +++ b/src/dyetool/dyemain.cpp @@ -24,6 +24,8 @@ #include "maingui.h" #include "sdlshared.h" +#include "fs/virtfs.h" + #include "resources/imagewriter.h" #include "resources/image/image.h" @@ -37,7 +39,6 @@ #include "resources/resourcemanager/resourcemanager.h" #include "utils/gettext.h" -#include "utils/virtfs.h" #include diff --git a/src/fs/virtfile.cpp b/src/fs/virtfile.cpp new file mode 100644 index 000000000..9f9ab6e98 --- /dev/null +++ b/src/fs/virtfile.cpp @@ -0,0 +1,37 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#include "fs/virtfile.h" + +#include "fs/virtfileprivate.h" + +#include "utils/delete2.h" + +#include "debug.h" + +VirtFile::VirtFile() : + mPrivate(nullptr) +{ +} + +VirtFile::~VirtFile() +{ + delete2(mPrivate); +} diff --git a/src/fs/virtfile.h b/src/fs/virtfile.h new file mode 100644 index 000000000..cf7ded1a4 --- /dev/null +++ b/src/fs/virtfile.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#ifndef UTILS_VIRTFILE_H +#define UTILS_VIRTFILE_H + +#include "localconsts.h" + +struct VirtFilePrivate; + +struct VirtFile final +{ + VirtFile(); + + A_DELETE_COPY(VirtFile) + + ~VirtFile(); + + VirtFilePrivate *mPrivate; +}; + +#endif // UTILS_VIRTFILE_H diff --git a/src/fs/virtfileprivate.cpp b/src/fs/virtfileprivate.cpp new file mode 100644 index 000000000..6bd5d3b9a --- /dev/null +++ b/src/fs/virtfileprivate.cpp @@ -0,0 +1,42 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#include "fs/virtfileprivate.h" + +#include "debug.h" + +VirtFilePrivate::VirtFilePrivate() : + mFile(nullptr) +{ +} + +VirtFilePrivate::VirtFilePrivate(PHYSFS_file *const file) : + mFile(file) +{ +} + +VirtFilePrivate::~VirtFilePrivate() +{ + if (mFile != nullptr) + { + PHYSFS_close(mFile); + mFile = nullptr; + } +} diff --git a/src/fs/virtfileprivate.h b/src/fs/virtfileprivate.h new file mode 100644 index 000000000..5b280de78 --- /dev/null +++ b/src/fs/virtfileprivate.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#ifndef UTILS_VIRTFILEPRIVATE_H +#define UTILS_VIRTFILEPRIVATE_H + +#include "localconsts.h" + +PRAGMA45(GCC diagnostic push) +PRAGMA45(GCC diagnostic ignored "-Wlong-long") +#include +PRAGMA45(GCC diagnostic pop) + +struct VirtFilePrivate final +{ + VirtFilePrivate(); + + explicit VirtFilePrivate(PHYSFS_file *const file); + + A_DELETE_COPY(VirtFilePrivate) + + ~VirtFilePrivate(); + + PHYSFS_file *mFile; +}; + +#endif // UTILS_VIRTFILEPRIVATE_H diff --git a/src/fs/virtfs.cpp b/src/fs/virtfs.cpp new file mode 100644 index 000000000..0db25f435 --- /dev/null +++ b/src/fs/virtfs.cpp @@ -0,0 +1,304 @@ +/* + * 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 . + */ + +#include "fs/virtfs.h" + +#include "fs/virtfile.h" +#include "fs/virtfileprivate.h" +#include "fs/virtlist.h" + +#include "utils/checkutils.h" + +#include +#include + +#ifdef ANDROID +#include "utils/paths.h" +#endif // ANDROID + +#include "debug.h" + +const char *dirSeparator = nullptr; + +namespace VirtFs +{ +#if defined(__native_client__) + void init(const std::string &restrict name A_UNUSED) + { + if (!PHYSFS_init("/fakebinary")) +#elif defined(ANDROID) + void init(const std::string &restrict name A_UNUSED) + { + if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) +#else // defined(__native_client__) + + void init(const std::string &restrict name) + { + if (!PHYSFS_init(name.c_str())) +#endif // defined(__native_client__) + { + std::cout << "Error while initializing PhysFS: " + << VirtFs::getLastError() << std::endl; + _exit(1); + } + updateDirSeparator(); + atexit(reinterpret_cast(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 std::string &restrict name) + { + return PHYSFS_exists(name.c_str()); + } + + VirtList *enumerateFiles(const std::string &restrict dir) + { + char ** handle = PHYSFS_enumerateFiles(dir.c_str()); + VirtList *const files = new VirtList; + if (handle == nullptr) + return files; + for (const char *const *i = handle; *i; i++) + { + std::string str = *i; + files->names.push_back(str); + } + PHYSFS_freeList(handle); + return files; + } + + bool isDirectory(const std::string &restrict name) + { + return PHYSFS_isDirectory(name.c_str()); + } + + bool isSymbolicLink(const std::string &restrict name) + { + return PHYSFS_isSymbolicLink(name.c_str()); + } + + void freeList(VirtList *restrict const handle) + { + delete handle; + } + + VirtFile *openRead(const std::string &restrict filename) + { + PHYSFS_file *restrict const handle = PHYSFS_openRead( + filename.c_str()); + if (!handle) + return nullptr; + VirtFile *restrict const file = new VirtFile; + file->mPrivate = new VirtFilePrivate(handle); + return file; + } + + VirtFile *openWrite(const std::string &restrict filename) + { + PHYSFS_file *restrict const handle = PHYSFS_openWrite( + filename.c_str()); + if (!handle) + return nullptr; + VirtFile *restrict const file = new VirtFile; + file->mPrivate = new VirtFilePrivate(handle); + return file; + } + + VirtFile *openAppend(const std::string &restrict filename) + { + PHYSFS_file *restrict const handle = PHYSFS_openAppend( + filename.c_str()); + if (!handle) + return nullptr; + VirtFile *restrict const file = new VirtFile; + file->mPrivate = new VirtFilePrivate(handle); + return file; + } + + bool setWriteDir(const std::string &restrict newDir) + { + return PHYSFS_setWriteDir(newDir.c_str()); + } + + bool addDirToSearchPath(const std::string &restrict newDir, + const Append append) + { + logger->log("Add virtual directory: " + newDir); + if (newDir.find(".zip") != std::string::npos) + { + reportAlways("Called addDirToSearchPath with zip archive"); + return false; + } + return PHYSFS_addToSearchPath(newDir.c_str(), + append == Append_true ? 1 : 0); + } + + bool removeDirFromSearchPath(const std::string &restrict oldDir) + { + logger->log("Remove virtual directory: " + oldDir); + if (oldDir.find(".zip") != std::string::npos) + { + reportAlways("Called removeDirFromSearchPath with zip archive"); + return false; + } + return PHYSFS_removeFromSearchPath(oldDir.c_str()); + } + + bool addZipToSearchPath(const std::string &restrict newDir, + const Append append) + { + logger->log("Add virtual zip: " + newDir); + if (newDir.find(".zip") == std::string::npos) + { + reportAlways("Called addZipToSearchPath without zip archive"); + return false; + } + return PHYSFS_addToSearchPath(newDir.c_str(), + append == Append_true ? 1 : 0); + } + + bool removeZipFromSearchPath(const std::string &restrict oldDir) + { + logger->log("Remove virtual zip: " + oldDir); + if (oldDir.find(".zip") == std::string::npos) + { + reportAlways("Called removeZipFromSearchPath without zip archive"); + return false; + } + return PHYSFS_removeFromSearchPath(oldDir.c_str()); + } + + std::string getRealDir(const std::string &restrict filename) + { + const char *const str = PHYSFS_getRealDir(filename.c_str()); + if (str == nullptr) + return std::string(); + return str; + } + + bool mkdir(const std::string &restrict dirname) + { + return PHYSFS_mkdir(dirname.c_str()); + } + + bool remove(const std::string &restrict filename) + { + return PHYSFS_delete(filename.c_str()); + } + + 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(); + } + + int close(VirtFile *restrict const file) + { + if (file == nullptr) + return 0; + delete file; + return 1; + } + + int64_t read(VirtFile *restrict const file, + void *restrict const buffer, + const uint32_t objSize, + const uint32_t objCount) + { + if (file == nullptr) + return 0; + return PHYSFS_read(file->mPrivate->mFile, + buffer, + objSize, + objCount); + } + + int64_t write(VirtFile *restrict const file, + const void *restrict const buffer, + const uint32_t objSize, + const uint32_t objCount) + { + if (file == nullptr) + return 0; + return PHYSFS_write(file->mPrivate->mFile, + buffer, + objSize, + objCount); + } + + int64_t fileLength(VirtFile *restrict const file) + { + if (file == nullptr) + return -1; + return PHYSFS_fileLength(file->mPrivate->mFile); + } + + int64_t tell(VirtFile *restrict const file) + { + if (file == nullptr) + return -1; + return PHYSFS_tell(file->mPrivate->mFile); + } + + int seek(VirtFile *restrict const file, + const uint64_t pos) + { + return PHYSFS_seek(file->mPrivate->mFile, + pos); + } + + int eof(VirtFile *restrict const file) + { + return PHYSFS_eof(file->mPrivate->mFile); + } +} // namespace VirtFs diff --git a/src/fs/virtfs.h b/src/fs/virtfs.h new file mode 100644 index 000000000..e0f188cfb --- /dev/null +++ b/src/fs/virtfs.h @@ -0,0 +1,79 @@ +/* + * 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 . + */ + +#ifndef UTILS_VIRTFS_H +#define UTILS_VIRTFS_H + +#include "enums/simpletypes/append.h" + +#include "localconsts.h" + +#include + +struct VirtFile; +struct VirtList; + +namespace VirtFs +{ + void init(const std::string &restrict name); + void updateDirSeparator(); + const char *getDirSeparator(); + const char *getBaseDir(); + const char *getUserDir(); + bool exists(const std::string &restrict name); + VirtList *enumerateFiles(const std::string &restrict dir) RETURNS_NONNULL; + bool isDirectory(const std::string &restrict name); + bool isSymbolicLink(const std::string &restrict name); + void freeList(VirtList *restrict const handle); + VirtFile *openRead(const std::string &restrict filename); + VirtFile *openWrite(const std::string &restrict filename); + VirtFile *openAppend(const std::string &restrict filename); + bool setWriteDir(const std::string &restrict newDir); + bool addDirToSearchPath(const std::string &restrict newDir, + const Append append); + bool removeDirFromSearchPath(const std::string &restrict oldDir); + bool addZipToSearchPath(const std::string &restrict newDir, + const Append append); + bool removeZipFromSearchPath(const std::string &restrict oldDir); + std::string getRealDir(const std::string &restrict filename); + bool mkdir(const std::string &restrict dirName); + bool remove(const std::string &restrict filename); + bool deinit(); + void permitLinks(const bool val); + const char *getLastError(); + int64_t read(VirtFile *restrict const handle, + void *restrict const buffer, + const uint32_t objSize, + const uint32_t objCount); + int64_t write(VirtFile *restrict const file, + const void *restrict const buffer, + const uint32_t objSize, + const uint32_t objCount); + int close(VirtFile *restrict const file); + int64_t fileLength(VirtFile *restrict const file); + int64_t tell(VirtFile *restrict const file); + int seek(VirtFile *restrict const file, + const uint64_t pos); + int eof(VirtFile *restrict const file); +} // namespace VirtFs + +extern const char *dirSeparator; + +#endif // UTILS_VIRTFS_H diff --git a/src/fs/virtfs_unittest.cc b/src/fs/virtfs_unittest.cc new file mode 100644 index 000000000..4f3a74a7b --- /dev/null +++ b/src/fs/virtfs_unittest.cc @@ -0,0 +1,406 @@ +/* + * The ManaPlus Client + * Copyright (C) 2016-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 . + */ + +#include "catch.hpp" + +#include "fs/virtfs.h" +#include "fs/virtfstools.h" +#include "fs/virtlist.h" + +#include "utils/checkutils.h" +#include "utils/delete2.h" + +#include "debug.h" + +TEST_CASE("VirtFs dirSeparator") +{ + REQUIRE(dirSeparator != nullptr); + REQUIRE(VirtFs::getDirSeparator() == std::string(dirSeparator)); + VirtFs::updateDirSeparator(); + REQUIRE(dirSeparator != nullptr); + REQUIRE(VirtFs::getDirSeparator() == std::string(dirSeparator)); +} + +TEST_CASE("VirtFs getBaseDir") +{ + REQUIRE(VirtFs::getBaseDir() != nullptr); +} + +TEST_CASE("VirtFs getUserDir") +{ + REQUIRE(VirtFs::getUserDir() != nullptr); +} + +TEST_CASE("VirtFs exists") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + REQUIRE(VirtFs::exists("test/units.xml") == true); + REQUIRE(VirtFs::exists("test/units123.xml") == false); + REQUIRE(VirtFs::exists("tesQ/units.xml") == false); + REQUIRE(VirtFs::exists("units.xml") == false); + + VirtFs::addDirToSearchPath("data/test", Append_false); + VirtFs::addDirToSearchPath("../data/test", Append_false); + + REQUIRE(VirtFs::exists("test/units.xml") == true); + REQUIRE(VirtFs::exists("test/units123.xml") == false); + REQUIRE(VirtFs::exists("tesQ/units.xml") == false); + REQUIRE(VirtFs::exists("units.xml") == true); + + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + + REQUIRE(VirtFs::exists("test/units.xml") == true); + REQUIRE(VirtFs::exists("test/units123.xml") == false); + REQUIRE(VirtFs::exists("tesQ/units.xml") == false); + REQUIRE(VirtFs::exists("units.xml") == false); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +static void removeTemp(StringVect &restrict list) +{ + int cnt = 0; + std::sort(list.begin(), list.end()); + + FOR_EACH (StringVectIter, it, list) + { + if (*it != "serverlistplus.xml.part") + { + logger->log("file: %d %s", + cnt, + (*it).c_str()); + cnt ++; + } + } + + FOR_EACH (StringVectIter, it, list) + { + if (*it == "serverlistplus.xml.part") + { + list.erase(it); + return; + } + } +} + +TEST_CASE("VirtFs enumerateFiles") +{ + logger = new Logger; + + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + VirtList *list = nullptr; + + const int cnt1 = VirtFs::exists("test/test2.txt") ? 23 : 22; + const int cnt2 = 23; + + VirtFs::permitLinks(false); + list = VirtFs::enumerateFiles("test"); + removeTemp(list->names); + const size_t sz = list->names.size(); + REQUIRE(sz == cnt1); + VirtFs::freeList(list); + + VirtFs::permitLinks(true); + list = VirtFs::enumerateFiles("test"); + removeTemp(list->names); + REQUIRE(list->names.size() == cnt2); + VirtFs::freeList(list); + + VirtFs::permitLinks(false); + list = VirtFs::enumerateFiles("test"); + removeTemp(list->names); + REQUIRE(list->names.size() == cnt1); + VirtFs::freeList(list); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +TEST_CASE("VirtFs isDirectory") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + REQUIRE(VirtFs::isDirectory("test/units.xml") == false); + REQUIRE(VirtFs::isDirectory("test/units.xml/") == false); + REQUIRE(VirtFs::isDirectory("test//units.xml") == false); + REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); + REQUIRE(VirtFs::isDirectory("test//units123.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ//units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml") == false); + REQUIRE(VirtFs::isDirectory("test") == true); + REQUIRE(VirtFs::isDirectory("test/") == true); + REQUIRE(VirtFs::isDirectory("test//") == true); + REQUIRE(VirtFs::isDirectory("test/dir1") == true); + REQUIRE(VirtFs::isDirectory("test//dir1") == true); + REQUIRE(VirtFs::isDirectory("test//dir1/") == true); + REQUIRE(VirtFs::isDirectory("test//dir1//") == true); + REQUIRE(VirtFs::isDirectory("test/dir1/") == true); + REQUIRE(VirtFs::isDirectory("test/dir1//") == true); + REQUIRE(VirtFs::isDirectory("testQ") == false); + REQUIRE(VirtFs::isDirectory("testQ/") == false); + REQUIRE(VirtFs::isDirectory("testQ//") == false); + + VirtFs::addDirToSearchPath("data/test", Append_false); + VirtFs::addDirToSearchPath("../data/test", Append_false); + + REQUIRE(VirtFs::isDirectory("test/units.xml") == false); + REQUIRE(VirtFs::isDirectory("test/units.xml/") == false); + REQUIRE(VirtFs::isDirectory("test//units.xml") == false); + REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml") == false); + REQUIRE(VirtFs::isDirectory("test") == true); + REQUIRE(VirtFs::isDirectory("testQ") == false); + REQUIRE(VirtFs::isDirectory("test/dir1") == true); + + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + + REQUIRE(VirtFs::isDirectory("test/units.xml") == false); + REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); + REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml") == false); + REQUIRE(VirtFs::isDirectory("units.xml/") == false); + REQUIRE(VirtFs::isDirectory("test") == true); + REQUIRE(VirtFs::isDirectory("test/") == true); + REQUIRE(VirtFs::isDirectory("testQ") == false); + REQUIRE(VirtFs::isDirectory("test/dir1") == true); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +TEST_CASE("VirtFs openRead") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + VirtFile *file = nullptr; + + file = VirtFs::openRead("test/units.xml"); + REQUIRE(file != nullptr); + VirtFs::close(file); + file = VirtFs::openRead("test/units123.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("tesQ/units.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("units.xml"); + REQUIRE(file == nullptr); +// file = VirtFs::openRead("test"); +// REQUIRE(file == nullptr); + file = VirtFs::openRead("testQ"); + REQUIRE(file == nullptr); + + VirtFs::addDirToSearchPath("data/test", Append_false); + VirtFs::addDirToSearchPath("../data/test", Append_false); + + file = VirtFs::openRead("test/units.xml"); + REQUIRE(file != nullptr); + VirtFs::close(file); + file = VirtFs::openRead("test/units123.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("tesQ/units.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("units.xml"); + REQUIRE(file != nullptr); + VirtFs::close(file); +// file = VirtFs::openRead("test"); +// REQUIRE(file == nullptr); + file = VirtFs::openRead("testQ"); + REQUIRE(file == nullptr); + + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + + file = VirtFs::openRead("test/units.xml"); + REQUIRE(file != nullptr); + VirtFs::close(file); + file = VirtFs::openRead("test/units123.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("tesQ/units.xml"); + REQUIRE(file == nullptr); + file = VirtFs::openRead("units.xml"); + REQUIRE(file == nullptr); +// file = VirtFs::openRead("test"); +// REQUIRE(file == nullptr); + file = VirtFs::openRead("testQ"); + REQUIRE(file == nullptr); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +TEST_CASE("VirtFs addZipToSearchPath") +{ + // +++ need implement +} + +TEST_CASE("VirtFs removeZipFromSearchPath") +{ + // +++ need implement +} + +TEST_CASE("VirtFs getRealDir") +{ + logger = new Logger(); + REQUIRE(VirtFs::getRealDir(".") == ""); + REQUIRE(VirtFs::getRealDir("..") == ""); + const bool dir1 = VirtFs::addDirToSearchPath("data", Append_false); + REQUIRE((dir1 || VirtFs::addDirToSearchPath("../data", Append_false)) == + true); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == "../data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "../data"); + } + REQUIRE(VirtFs::getRealDir("zzz") == ""); + + VirtFs::addDirToSearchPath("data/test", Append_false); + VirtFs::addDirToSearchPath("../data/test", Append_false); + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + REQUIRE(VirtFs::getRealDir("test.txt") == + "data/test"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == "../data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "../data"); + REQUIRE(VirtFs::getRealDir("test.txt") == + "../data/test"); + } + REQUIRE(VirtFs::getRealDir("zzz") == ""); + + VirtFs::removeDirFromSearchPath("data/test"); + VirtFs::removeDirFromSearchPath("../data/test"); + + if (dir1 == true) + { + REQUIRE(VirtFs::getRealDir("test") == "data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "data"); + } + else + { + REQUIRE(VirtFs::getRealDir("test") == "../data"); + REQUIRE(VirtFs::getRealDir("test/test.txt") == + "../data"); + } + REQUIRE(VirtFs::getRealDir("zzz") == ""); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +TEST_CASE("VirtFs permitLinks") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + const int cnt1 = VirtFs::exists("test/test2.txt") ? 22 : 21; + const int cnt2 = 22; + + StringVect list; + VirtFs::permitLinks(false); + VirtFs::getFiles("test", list); + removeTemp(list); + const size_t sz = list.size(); + REQUIRE(sz == cnt1); + + list.clear(); + VirtFs::permitLinks(true); + VirtFs::getFiles("test", list); + removeTemp(list); + REQUIRE(list.size() == cnt2); + + list.clear(); + VirtFs::permitLinks(false); + VirtFs::getFiles("test", list); + removeTemp(list); + REQUIRE(list.size() == cnt1); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} + +TEST_CASE("VirtFs read") +{ + logger = new Logger(); + VirtFs::addDirToSearchPath("data", Append_false); + VirtFs::addDirToSearchPath("../data", Append_false); + + VirtFile *file = VirtFs::openRead("test/test.txt"); + REQUIRE(file != nullptr); + REQUIRE(VirtFs::fileLength(file) == 23); + const int fileSize = VirtFs::fileLength(file); + + void *restrict buffer = calloc(fileSize + 1, 1); + REQUIRE(VirtFs::read(file, buffer, 1, fileSize) == fileSize); + REQUIRE(strcmp(static_cast(buffer), + "test line 1\ntest line 2") == 0); + REQUIRE(VirtFs::tell(file) == fileSize); + REQUIRE(VirtFs::eof(file) == true); + + free(buffer); + buffer = calloc(fileSize + 1, 1); + REQUIRE(VirtFs::seek(file, 12) != 0); + REQUIRE(VirtFs::eof(file) == false); + REQUIRE(VirtFs::tell(file) == 12); + REQUIRE(VirtFs::read(file, buffer, 1, 11) == 11); + REQUIRE(strcmp(static_cast(buffer), + "test line 2") == 0); + REQUIRE(VirtFs::eof(file) == true); + + VirtFs::close(file); + free(buffer); + + VirtFs::removeDirFromSearchPath("data"); + VirtFs::removeDirFromSearchPath("../data"); + delete2(logger); +} diff --git a/src/fs/virtfsrwops.cpp b/src/fs/virtfsrwops.cpp new file mode 100644 index 000000000..036d8bb60 --- /dev/null +++ b/src/fs/virtfsrwops.cpp @@ -0,0 +1,434 @@ +/* + * 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 . + */ + +/* + * This code provides a glue layer between PhysicsFS and Simple Directmedia + * Layer's (SDL) RWops i/o abstraction. + * + * License: this code is public domain. I make no warranty that it is useful, + * correct, harmless, or environmentally safe. + * + * This particular file may be used however you like, including copying it + * verbatim into a closed-source project, exploiting it commercially, and + * removing any trace of my name from the source (although I hope you won't + * do that). I welcome enhancements and corrections to this file, but I do + * not require you to send me patches if you make changes. This code has + * NO WARRANTY. + * + * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. + * Please see LICENSE.txt in the root of the source tree. + * + * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/ + * + * This file was written by Ryan C. Gordon. (icculus@icculus.org). + * + * Copyright (C) 2012-2017 The ManaPlus Developers + */ + +#include "fs/virtfsrwops.h" + +#include "logger.h" + +#include "fs/virtfs.h" + +#ifdef DEBUG_VIRTFS +#include "utils/debugmemoryobject.h" + +#include +#endif // DEBUG_VIRTFS + +#include "utils/fuzzer.h" + +#include "debug.h" + +#ifdef USE_SDL2 +#define RWOPSINT int64_t +#define RWOPSSIZE size_t +#else // USE_SDL2 +#define RWOPSINT int32_t +#define RWOPSSIZE int +#endif // USE_SDL2 + +#ifdef DUMP_LEAKED_RESOURCES +static int openedRWops = 0; +#endif // DUMP_LEAKED_RESOURCES + +#ifdef DEBUG_VIRTFS +namespace +{ + std::map mRWops; +} // namespace + +static SDL_RWops *addDebugRWops(SDL_RWops *restrict const rwops, + const char *restrict const name, + const char *restrict const file, + const unsigned line) +{ + if (!rwops) + return nullptr; + + mRWops[rwops] = new VirtFs::DebugMemoryObject(name, file, line); + return rwops; +} + +static void deleteDebugRWops(SDL_RWops *const rwops) +{ + if (!rwops) + return; + + std::map::iterator it = + mRWops.find(rwops); + if (it == mRWops.end()) + { + logger->log("bad RWops delete: %p", static_cast(rwops)); + } + else + { + VirtFs::DebugMemoryObject *const obj = (*it).second; + if (obj) + { + mRWops.erase(rwops); + delete obj; + } + } +} + +void VirtFs::reportLeaks() +{ + if (!mRWops.empty()) + { + logger->log("RWops leaks detected"); + std::map::iterator it = + mRWops.begin(); + const std::map::iterator + it_end = mRWops.end(); + for (; it != it_end; ++it) + { + VirtFs::DebugMemoryObject *obj = (*it).second; + if (obj) + { + logger->log("file: %s at %s", obj->mName.c_str(), + obj->mAddFile.c_str()); + delete obj; + } + } + mRWops.clear(); + } +} +#endif // DEBUG_VIRTFS + +static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, + const RWOPSINT offset, + const int whence) +{ + if (!rw) + return -1; + VirtFile *const handle = static_cast( + rw->hidden.unknown.data1); + RWOPSINT pos = 0; + + if (whence == SEEK_SET) + { + pos = offset; + } /* if */ + else if (whence == SEEK_CUR) + { + const int64_t current = VirtFs::tell(handle); + if (current == -1) + { + logger->assertLog( + "virtfsrwops_seek: Can't find position in file: %s", + VirtFs::getLastError()); + return -1; + } /* if */ + + pos = CAST_S32(current); + if (static_cast(pos) != current) + { + logger->assertLog("virtfsrwops_seek: " + "Can't fit current file position in an int!"); + return -1; + } /* if */ + + if (offset == 0) /* this is a "tell" call. We're done. */ + return pos; + + pos += offset; + } /* else if */ + else if (whence == SEEK_END) + { + const int64_t len = VirtFs::fileLength(handle); + if (len == -1) + { + logger->assertLog("virtfsrwops_seek:Can't find end of file: %s", + VirtFs::getLastError()); + return -1; + } /* if */ + + pos = static_cast(len); + if (static_cast(pos) != len) + { + logger->assertLog("virtfsrwops_seek: " + "Can't fit end-of-file position in an int!"); + return -1; + } /* if */ + + pos += offset; + } /* else if */ + else + { + logger->assertLog("virtfsrwops_seek: Invalid 'whence' parameter."); + return -1; + } /* else */ + + if (pos < 0) + { + logger->assertLog("virtfsrwops_seek: " + "Attempt to seek past start of file."); + return -1; + } /* if */ + + if (!VirtFs::seek(handle, static_cast(pos))) + { + logger->assertLog("virtfsrwops_seek: seek error: %s", + VirtFs::getLastError()); + return -1; + } /* if */ + + return pos; +} /* virtfsrwops_seek */ + +static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw, + void *const ptr, + const RWOPSSIZE size, + const RWOPSSIZE maxnum) +{ + if (!rw) + return 0; + VirtFile *const handle = static_cast( + rw->hidden.unknown.data1); + const int64_t rc = VirtFs::read(handle, ptr, + CAST_U32(size), + CAST_U32(maxnum)); + if (rc != static_cast(maxnum)) + { + if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */ + { + logger->assertLog("virtfsrwops_seek: read error: %s", + VirtFs::getLastError()); + } + } /* if */ + + return CAST_S32(rc); +} /* virtfsrwops_read */ + +static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw, + const void *const ptr, + const RWOPSSIZE size, + const RWOPSSIZE num) +{ + if (!rw) + return 0; + VirtFile *const handle = static_cast( + rw->hidden.unknown.data1); + const int64_t rc = VirtFs::write(handle, ptr, + CAST_U32(size), + CAST_U32(num)); + if (rc != static_cast(num)) + { + logger->assertLog("virtfsrwops_seek: write error: %s", + VirtFs::getLastError()); + } + + return CAST_S32(rc); +} /* virtfsrwops_write */ + +static int virtfsrwops_close(SDL_RWops *const rw) +{ + if (!rw) + return 0; + VirtFile *const handle = static_cast( + rw->hidden.unknown.data1); + if (!VirtFs::close(handle)) + { + logger->assertLog("virtfsrwops_seek: close error: %s", + VirtFs::getLastError()); + return -1; + } /* if */ + + SDL_FreeRW(rw); +#ifdef DUMP_LEAKED_RESOURCES + if (openedRWops <= 0) + logger->assertLog("virtfsrwops_seek: closing already closed RWops"); + openedRWops --; +#endif // DUMP_LEAKED_RESOURCES +#ifdef DEBUG_VIRTFS + deleteDebugRWops(rw); +#endif // DEBUG_VIRTFS + + return 0; +} /* virtfsrwops_close */ + +#ifdef USE_SDL2 +static RWOPSINT virtfsrwops_size(SDL_RWops *const rw) +{ + VirtFile *const handle = static_cast( + rw->hidden.unknown.data1); + return VirtFs::fileLength(handle); +} /* virtfsrwops_size */ +#endif // USE_SDL2 + +static SDL_RWops *create_rwops(VirtFile *const file) +{ + SDL_RWops *retval = nullptr; + + if (!file) + { + logger->assertLog("virtfsrwops_seek: create rwops error: %s", + VirtFs::getLastError()); + } + else + { + retval = SDL_AllocRW(); + if (retval) + { +#ifdef USE_SDL2 + retval->size = &virtfsrwops_size; +#endif // USE_SDL2 + + retval->seek = &virtfsrwops_seek; + retval->read = &virtfsrwops_read; + retval->write = &virtfsrwops_write; + retval->close = &virtfsrwops_close; + retval->hidden.unknown.data1 = file; + } /* if */ +#ifdef DUMP_LEAKED_RESOURCES + openedRWops ++; +#endif // DUMP_LEAKED_RESOURCES + } /* else */ + + return retval; +} /* create_rwops */ + +SDL_RWops *VirtFs::MakeRWops(VirtFile *const handle) +{ + SDL_RWops *retval = nullptr; + if (!handle) + { + logger->assertLog("virtfsrwops_seek: NULL pointer passed to " + "RWopsmakeRWops()."); + } + else + { + retval = create_rwops(handle); + } + + return retval; +} /* RWopsmakeRWops */ + +#ifdef __APPLE__ +static bool checkFilePath(const std::string &restrict fname) +{ + if (fname.empty()) + return false; + if (!VirtFs::exists(fname) || VirtFs::isDirectory(fname)) + return false; + return true; +} +#endif // __APPLE__ + +#ifdef DEBUG_VIRTFS +#undef RWopsOpenRead +SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname, + const char *restrict const file, + const unsigned line) +#else // DEBUG_VIRTFS +SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname) +#endif // DEBUG_VIRTFS +{ + BLOCK_START("RWopsopenRead") +#ifdef __APPLE__ + if (!checkFilePath(fname)) + return nullptr; +#endif // __APPLE__ +#ifdef USE_FUZZER + if (Fuzzer::conditionTerminate(fname)) + return nullptr; +#endif // USE_FUZZER +#ifdef USE_PROFILER + +#ifdef DEBUG_VIRTFS + SDL_RWops *const ret = addDebugRWops( + create_rwops(VirtFs::openRead(fname)), + fname, + file, + line); +#else // DEBUG_VIRTFS + SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname)); +#endif // DEBUG_VIRTFS + + BLOCK_END("RWopsopenRead") + return ret; +#else // USE_PROFILER + +#ifdef DEBUG_VIRTFS + return addDebugRWops( + create_rwops(VirtFs::openRead(fname)), + fname, + file, + line); +#else // DEBUG_VIRTFS + return create_rwops(VirtFs::openRead(fname)); +#endif // DEBUG_VIRTFS +#endif // USE_PROFILER +} /* RWopsopenRead */ + +SDL_RWops *VirtFs::RWopsOpenWrite(const std::string &restrict fname) +{ +#ifdef __APPLE__ + if (!checkFilePath(fname)) + return nullptr; +#endif // __APPLE__ + + return create_rwops(VirtFs::openWrite(fname)); +} /* RWopsopenWrite */ + +SDL_RWops *VirtFs::RWopsOpenAppend(const std::string &restrict fname) +{ +#ifdef __APPLE__ + if (!checkFilePath(fname)) + return nullptr; +#endif // __APPLE__ + + return create_rwops(VirtFs::openAppend(fname)); +} /* RWopsopenAppend */ + +#ifdef DUMP_LEAKED_RESOURCES +void VirtFs::reportRWops() +{ + if (openedRWops) + { + logger->assertLog("virtfsrwops_seek: leaking RWops: %d", + openedRWops); + } +} +#endif // DUMP_LEAKED_RESOURCES + +/* end of physfsrwops.c ... */ diff --git a/src/fs/virtfsrwops.h b/src/fs/virtfsrwops.h new file mode 100644 index 000000000..82bb740de --- /dev/null +++ b/src/fs/virtfsrwops.h @@ -0,0 +1,75 @@ +/* + * 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 . + */ + +/* + * This code provides a glue layer between PhysicsFS and Simple Directmedia + * Layer's (SDL) RWops i/o abstraction. + * + * License: this code is public domain. I make no warranty that it is useful, + * correct, harmless, or environmentally safe. + * + * This particular file may be used however you like, including copying it + * verbatim into a closed-source project, exploiting it commercially, and + * removing any trace of my name from the source (although I hope you won't + * do that). I welcome enhancements and corrections to this file, but I do + * not require you to send me patches if you make changes. This code has + * NO WARRANTY. + * + * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. + * Please see LICENSE.txt in the root of the source tree. + * + * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/ + * + * This file was written by Ryan C. Gordon. (icculus@icculus.org). + * + * Copyright (C) 2012-2017 The ManaPlus Developers + */ + +#ifndef UTILS_PHYSFSRWOPS_H +#define UTILS_PHYSFSRWOPS_H + +#include "localconsts.h" + +#include +#include + +struct VirtFile; + +namespace VirtFs +{ +#ifdef DEBUG_VIRTFS + SDL_RWops *RWopsOpenRead(const std::string &restrict fname, + const char *restrict const file, + const unsigned line); + void reportLeaks(); +#else // DEBUG_VIRTFS + SDL_RWops *RWopsOpenRead(const std::string &restrict fname); +#endif // DEBUG_VIRTFS + + SDL_RWops *RWopsOpenWrite(const std::string &restrict fname) A_WARN_UNUSED; + SDL_RWops *RWopsOpenAppend(const std::string &restrict fname) + A_WARN_UNUSED; + SDL_RWops *MakeRWops(VirtFile *const handle) A_WARN_UNUSED; +#ifdef DUMP_LEAKED_RESOURCES + void reportRWops(); +#endif // DUMP_LEAKED_RESOURCES +} // namespace VirtFs + +#endif // UTILS_PHYSFSRWOPS_H diff --git a/src/fs/virtfstools.cpp b/src/fs/virtfstools.cpp new file mode 100644 index 000000000..4d6c96c33 --- /dev/null +++ b/src/fs/virtfstools.cpp @@ -0,0 +1,223 @@ +/* + * 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 . + */ + +#include "fs/virtfstools.h" + +#include "logger.h" + +#include "fs/virtfs.h" +#include "fs/virtlist.h" + +#include "utils/paths.h" +#include "utils/stringutils.h" + +#include +#include + +#include "debug.h" + +namespace VirtFs +{ + void *loadFile(const std::string &restrict fileName, + int &restrict fileSize) + { + // Attempt to open the specified file using PhysicsFS + VirtFile *restrict const file = VirtFs::openRead(fileName); + + 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 *restrict const buffer = calloc(fileSize, 1); + VirtFs::read(file, buffer, 1, fileSize); + VirtFs::close(file); + + return buffer; + } + + void searchAndAddArchives(const std::string &restrict path, + const std::string &restrict ext, + const Append append) + { + VirtList *const list = VirtFs::enumerateFiles(path); + FOR_EACH (StringVectCIter, i, list->names) + { + const std::string str = *i; + const size_t len = str.size(); + + if (len > ext.length() && + !ext.compare(str.substr(len - ext.length()))) + { + const std::string file = path + str; + const std::string realPath = VirtFs::getRealDir(file); + VirtFs::addZipToSearchPath(std::string(realPath).append( + dirSeparator).append(file), append); + } + } + VirtFs::freeList(list); + } + + void searchAndRemoveArchives(const std::string &restrict path, + const std::string &restrict ext) + { + VirtList *const list = VirtFs::enumerateFiles(path); + FOR_EACH (StringVectCIter, i, list->names) + { + const std::string str = *i; + const size_t len = str.size(); + if (len > ext.length() && + !ext.compare(str.substr(len - ext.length()))) + { + const std::string file = path + str; + const std::string realPath = VirtFs::getRealDir(file); + VirtFs::removeZipFromSearchPath(std::string( + realPath).append( + dirSeparator).append( + file)); + } + } + VirtFs::freeList(list); + } + + void getFilesWithDir(const std::string &path, + StringVect &list) + { + VirtList *const fonts = VirtFs::enumerateFiles(path); + FOR_EACH (StringVectCIter, i, fonts->names) + { + if (!VirtFs::isDirectory(path + *i)) + list.push_back(path + *i); + } + VirtFs::freeList(fonts); + } + + void getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext) + { + const std::string path = dir + "/"; + StringVect tempList; + VirtFs::getFilesWithDir(path, tempList); + FOR_EACH (StringVectCIter, it, tempList) + { + const std::string &str = *it; + if (findLast(str, ext)) + list.push_back(str); + } + std::sort(list.begin(), list.end()); + } + + void getFiles(const std::string &path, + StringVect &list) + { + VirtList *const fonts = VirtFs::enumerateFiles(path); + FOR_EACH (StringVectCIter, i, fonts->names) + { + if (!VirtFs::isDirectory(path + dirSeparator + *i)) + list.push_back(*i); + } + VirtFs::freeList(fonts); + } + + void getDirs(const std::string &path, StringVect &list) + { + VirtList *const fonts = VirtFs::enumerateFiles(path); + FOR_EACH (StringVectCIter, i, fonts->names) + { + if (VirtFs::isDirectory(path + dirSeparator + *i)) + list.push_back(*i); + } + VirtFs::freeList(fonts); + } + + std::string getPath(const std::string &file) + { + // get the real path to the file + const std::string tmp = VirtFs::getRealDir(file); + std::string path; + + // if the file is not in the search path, then its empty + if (!tmp.empty()) + { + path = std::string(tmp).append(dirSeparator).append(file); +#if defined __native_client__ + std::string dataZip = "/http/data.zip/"; + if (path.substr(0, dataZip.length()) == dataZip) + path = path.replace(0, dataZip.length(), "/http/data/"); +#endif // defined __native_client__ + } + else + { + // if not found in search path return the default path + path = getPackageDir().append(dirSeparator).append(file); + } + + return path; + } + + std::string loadTextFileString(const std::string &fileName) + { + int contentsLength; + char *fileContents = static_cast( + VirtFs::loadFile(fileName, contentsLength)); + + if (!fileContents) + { + logger->log("Couldn't load text file: %s", fileName.c_str()); + return std::string(); + } + const std::string str = std::string(fileContents, contentsLength); + free(fileContents); + return str; + } + + bool loadTextFile(const std::string &fileName, + StringVect &lines) + { + int contentsLength; + char *fileContents = static_cast( + VirtFs::loadFile(fileName, contentsLength)); + + if (!fileContents) + { + logger->log("Couldn't load text file: %s", fileName.c_str()); + return false; + } + + std::istringstream iss(std::string(fileContents, contentsLength)); + std::string line; + + while (getline(iss, line)) + lines.push_back(line); + + free(fileContents); + return true; + } +} // namespace VirtFs diff --git a/src/fs/virtfstools.h b/src/fs/virtfstools.h new file mode 100644 index 000000000..4f2a77f4c --- /dev/null +++ b/src/fs/virtfstools.h @@ -0,0 +1,54 @@ +/* + * 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 . + */ + +#ifndef UTILS_VIRTFSTOOLS_H +#define UTILS_VIRTFSTOOLS_H + +#include "enums/simpletypes/append.h" + +#include "utils/stringvector.h" + +#include "localconsts.h" + +namespace VirtFs +{ + void *loadFile(const std::string &restrict fileName, + int &restrict fileSize); + void searchAndAddArchives(const std::string &restrict path, + const std::string &restrict ext, + const Append append); + void searchAndRemoveArchives(const std::string &restrict path, + const std::string &restrict ext); + void getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext); + void getFilesWithDir(const std::string &restrict path, + StringVect &restrict list); + void getFiles(const std::string &path, + StringVect &list); + void getDirs(const std::string &path, + StringVect &list); + std::string getPath(const std::string &file); + bool loadTextFile(const std::string &fileName, + StringVect &lines); + std::string loadTextFileString(const std::string &fileName); +} // namespace VirtFs + +#endif // UTILS_VIRTFSTOOLS_H diff --git a/src/fs/virtlist.cpp b/src/fs/virtlist.cpp new file mode 100644 index 000000000..d561e6b66 --- /dev/null +++ b/src/fs/virtlist.cpp @@ -0,0 +1,32 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#include "fs/virtlist.h" + +#include "debug.h" + +VirtList::VirtList() : + names() +{ +} + +VirtList::~VirtList() +{ +} diff --git a/src/fs/virtlist.h b/src/fs/virtlist.h new file mode 100644 index 000000000..5b1d10924 --- /dev/null +++ b/src/fs/virtlist.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 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 . + */ + +#ifndef UTILS_VIRTLIST_H +#define UTILS_VIRTLIST_H + +#include "utils/stringvector.h" + +#include "localconsts.h" + +struct VirtList final +{ + VirtList(); + + A_DELETE_COPY(VirtList) + + ~VirtList(); + + StringVect names; +}; + +#endif // UTILS_VIRTLIST_H diff --git a/src/game.cpp b/src/game.cpp index 4d4ece3fe..3318c4268 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -41,13 +41,7 @@ #include "enums/being/beingdirection.h" -#include "particle/particleengine.h" - -#include "input/inputmanager.h" -#include "input/joystick.h" -#include "input/keyboardconfig.h" - -#include "input/touch/touchmanager.h" +#include "fs/virtfs.h" #include "gui/dialogsmanager.h" #include "gui/gui.h" @@ -100,11 +94,19 @@ #include "gui/widgets/tabs/chat/langtab.h" #include "gui/widgets/tabs/chat/tradetab.h" +#include "input/inputmanager.h" +#include "input/joystick.h" +#include "input/keyboardconfig.h" + +#include "input/touch/touchmanager.h" + #include "net/generalhandler.h" #include "net/gamehandler.h" #include "net/packetcounters.h" #include "net/serverfeatures.h" +#include "particle/particleengine.h" + #include "resources/delayedmanager.h" #include "resources/imagewriter.h" #include "resources/mapreader.h" @@ -121,7 +123,6 @@ #include "utils/delete2.h" #include "utils/gettext.h" #include "utils/mkdir.h" -#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "utils/timer.h" diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp index 61bb93453..877f112e0 100644 --- a/src/gui/fonts/font.cpp +++ b/src/gui/fonts/font.cpp @@ -66,6 +66,8 @@ #include "gui/fonts/font.h" +#include "fs/virtfstools.h" + #include "gui/fonts/textchunk.h" #include "render/graphics.h" @@ -79,7 +81,6 @@ #include "utils/sdlcheckutils.h" #include "utils/stringutils.h" #include "utils/timer.h" -#include "utils/virtfstools.h" #include "debug.h" diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 1888627d1..206d8f9a5 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -29,6 +29,10 @@ #include "const/gui/theme.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" +#include "fs/virtlist.h" + #include "gui/skin.h" #include "gui/themeinfo.h" @@ -45,9 +49,6 @@ #include "resources/loaders/xmlloader.h" #include "utils/dtor.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" -#include "utils/virtlist.h" #include "debug.h" diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index 68a38300d..4e2244a2f 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -24,6 +24,8 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/fonts/font.h" @@ -31,7 +33,6 @@ #include "gui/widgets/browserbox.h" #include "utils/delete2.h" -#include "utils/virtfs.h" #include "render/sdlgraphics.h" diff --git a/src/gui/windowmanager.cpp b/src/gui/windowmanager.cpp index 28a57e7e0..ce0b0132d 100644 --- a/src/gui/windowmanager.cpp +++ b/src/gui/windowmanager.cpp @@ -29,6 +29,8 @@ #include "settings.h" #include "spellmanager.h" +#include "fs/virtfstools.h" + #include "gui/gui.h" #include "gui/userpalette.h" @@ -59,7 +61,6 @@ #include "utils/delete2.h" #include "utils/sdlcheckutils.h" #include "utils/sdlhelper.h" -#include "utils/virtfstools.h" #ifdef __native_client__ #include "utils/naclmessages.h" #endif // __native_client__ diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc index 68fc3852b..902068376 100644 --- a/src/gui/windowmanager_unittest.cc +++ b/src/gui/windowmanager_unittest.cc @@ -29,6 +29,8 @@ #include "const/resources/currency.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/mailmessage.h" #include "gui/userpalette.h" @@ -117,7 +119,6 @@ #include "utils/delete2.h" #include "utils/env.h" #include "utils/gettext.h" -#include "utils/virtfs.h" #include "utils/translation/translationmanager.h" diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 094faea6d..40016d4f0 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -35,6 +35,8 @@ #include "const/gui/chat.h" +#include "fs/virtfstools.h" + #include "input/inputmanager.h" #include "gui/focushandler.h" @@ -71,7 +73,6 @@ #include "utils/copynpaste.h" #include "utils/delete2.h" -#include "utils/virtfstools.h" #include diff --git a/src/gui/windows/helpwindow.cpp b/src/gui/windows/helpwindow.cpp index e1ba2de30..91bdbe13e 100644 --- a/src/gui/windows/helpwindow.cpp +++ b/src/gui/windows/helpwindow.cpp @@ -26,7 +26,7 @@ #include "enums/gui/layouttype.h" -#include "input/inputmanager.h" +#include "fs/virtfstools.h" #include "gui/gui.h" @@ -37,10 +37,11 @@ #include "gui/widgets/layout.h" #include "gui/widgets/scrollarea.h" +#include "input/inputmanager.h" + #include "utils/gettext.h" #include "utils/paths.h" #include "utils/process.h" -#include "utils/virtfstools.h" #include "utils/translation/podict.h" #include "utils/translation/translationmanager.h" diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index f19fb2239..e261dead7 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -31,6 +31,8 @@ #include "enums/resources/map/blockmask.h" +#include "fs/virtfs.h" + #include "gui/popupmanager.h" #include "gui/viewport.h" #include "gui/userpalette.h" @@ -50,7 +52,6 @@ #include "resources/loaders/imageloader.h" #include "utils/gettext.h" -#include "utils/virtfs.h" #include "utils/sdlcheckutils.h" #include "debug.h" diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index ddb265bc7..4d0ff9f3a 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -29,6 +29,9 @@ #include "enums/gui/layouttype.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" + #include "gui/widgets/browserbox.h" #include "gui/widgets/button.h" #include "gui/widgets/containerplacer.h" @@ -45,8 +48,6 @@ #include "utils/delete2.h" #include "utils/files.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" #include "utils/gettext.h" #include "utils/mkdir.h" #include "utils/paths.h" diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc index 158ce51fc..b7b97321a 100644 --- a/src/integrity_unittest.cc +++ b/src/integrity_unittest.cc @@ -25,6 +25,10 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" +#include "fs/virtfstools.h" + #include "input/inputactionmap.h" #include "resources/image/image.h" @@ -40,9 +44,6 @@ #include "utils/env.h" #include "utils/delete2.h" -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" -#include "utils/virtfstools.h" #include #include diff --git a/src/maingui.cpp b/src/maingui.cpp index c94c456a5..7bf5e1290 100644 --- a/src/maingui.cpp +++ b/src/maingui.cpp @@ -26,13 +26,14 @@ #include "commandline.h" #include "settings.h" +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" + #include "utils/delete2.h" #ifdef ANDROID #include "utils/mkdir.h" #include "utils/paths.h" #endif // ANDROID -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" #include "utils/process.h" #include "utils/xml.h" diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp index d4854cfe2..f8a5b608c 100644 --- a/src/render/shaders/shadersmanager.cpp +++ b/src/render/shaders/shadersmanager.cpp @@ -25,7 +25,7 @@ #include "configuration.h" #include "logger.h" -#include "utils/virtfstools.h" +#include "fs/virtfstools.h" #include "render/opengl/mgl.h" #ifdef __native_client__ diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp index ef06c9527..f724618b5 100644 --- a/src/resources/atlas/atlasmanager.cpp +++ b/src/resources/atlas/atlasmanager.cpp @@ -28,9 +28,10 @@ #include "logger.h" #endif // DEBUG_IMAGES +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" + #include "utils/mathutils.h" -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" #include "utils/sdlcheckutils.h" #include "resources/openglimagehelper.h" diff --git a/src/resources/beingcommon.h b/src/resources/beingcommon.h index 769ac238c..901b5e65e 100644 --- a/src/resources/beingcommon.h +++ b/src/resources/beingcommon.h @@ -21,7 +21,8 @@ #ifndef RESOURCES_BEINGCOMMON_H #define RESOURCES_BEINGCOMMON_H -#include "utils/virtfstools.h" +#include "fs/virtfstools.h" + #include "utils/xml.h" #include "localconsts.h" diff --git a/src/resources/db/badgesdb.cpp b/src/resources/db/badgesdb.cpp index 031d78945..59080efe6 100644 --- a/src/resources/db/badgesdb.cpp +++ b/src/resources/db/badgesdb.cpp @@ -22,7 +22,8 @@ #include "configuration.h" -#include "utils/virtfstools.h" +#include "fs/virtfstools.h" + #include "utils/xmlutils.h" #include "debug.h" diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 9ff9d78c6..06ce15542 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -28,6 +28,8 @@ #include "enums/resources/spritedirection.h" +#include "fs/virtfstools.h" + #include "resources/iteminfo.h" #include "resources/itemtypemapdata.h" @@ -43,7 +45,6 @@ #include "utils/delete2.h" #include "utils/dtor.h" #include "utils/stringmap.h" -#include "utils/virtfstools.h" #include "debug.h" diff --git a/src/resources/db/palettedb.cpp b/src/resources/db/palettedb.cpp index 4c9c4cd76..a17403769 100644 --- a/src/resources/db/palettedb.cpp +++ b/src/resources/db/palettedb.cpp @@ -22,8 +22,9 @@ #include "configuration.h" +#include "fs/virtfstools.h" + #include "utils/checkutils.h" -#include "utils/virtfstools.h" #include "resources/dye/dyecolor.h" diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc index 5f38aa77a..d562118b3 100644 --- a/src/resources/dye/dye_unittest.cc +++ b/src/resources/dye/dye_unittest.cc @@ -26,6 +26,8 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "resources/sdlimagehelper.h" #ifdef USE_SDL2 #include "resources/surfaceimagehelper.h" @@ -42,7 +44,6 @@ #include "utils/delete2.h" #include "utils/env.h" -#include "utils/virtfs.h" #ifndef USE_SDL2 #include diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc index 9431f0d72..285ac22a8 100644 --- a/src/resources/dye/dyepalette_unittest.cc +++ b/src/resources/dye/dyepalette_unittest.cc @@ -26,6 +26,8 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/theme.h" @@ -41,7 +43,6 @@ #include "utils/delete2.h" #include "utils/env.h" -#include "utils/virtfs.h" #ifndef USE_SDL2 #include diff --git a/src/resources/loaders/imageloader.cpp b/src/resources/loaders/imageloader.cpp index b4826238a..3a4909d94 100644 --- a/src/resources/loaders/imageloader.cpp +++ b/src/resources/loaders/imageloader.cpp @@ -22,6 +22,9 @@ #include "resources/imagehelper.h" +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" + #include "resources/image/image.h" #include "resources/loaders/imageloader.h" @@ -31,8 +34,6 @@ #include "resources/dye/dye.h" #include "utils/checkutils.h" -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" #include "debug.h" diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp index 62fde088b..ee464ae48 100644 --- a/src/resources/loaders/musicloader.cpp +++ b/src/resources/loaders/musicloader.cpp @@ -22,13 +22,14 @@ #include "resources/sdlmusic.h" +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" + #include "resources/loaders/musicloader.h" #include "resources/resourcemanager/resourcemanager.h" #include "utils/checkutils.h" -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" #include "debug.h" diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp index 35a938f76..cbc0cbde9 100644 --- a/src/resources/loaders/soundloader.cpp +++ b/src/resources/loaders/soundloader.cpp @@ -22,13 +22,14 @@ #include "resources/soundeffect.h" +#include "fs/virtfs.h" +#include "fs/virtfsrwops.h" + #include "resources/loaders/soundloader.h" #include "resources/resourcemanager/resourcemanager.h" #include "utils/checkutils.h" -#include "utils/virtfs.h" -#include "utils/virtfsrwops.h" #include "debug.h" diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index afc2bbffd..5af4e72f3 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -27,14 +27,6 @@ #include "notifymanager.h" #include "settings.h" -#include "resources/map/mapheights.h" -#include "resources/map/maplayer.h" -#include "resources/map/mapitem.h" -#include "resources/map/objectslayer.h" -#include "resources/map/speciallayer.h" -#include "resources/map/tileset.h" -#include "resources/map/walklayer.h" - #include "being/localplayer.h" #include "enums/resources/notifytypes.h" @@ -42,6 +34,8 @@ #include "enums/resources/map/blockmask.h" #include "enums/resources/map/mapitemtype.h" +#include "fs/virtfs.h" + #include "gui/userpalette.h" #include "particle/particle.h" @@ -53,8 +47,16 @@ #include "resources/loaders/imageloader.h" #include "resources/map/location.h" +#include "resources/map/mapheights.h" #include "resources/map/mapobjectlist.h" +#include "resources/map/maplayer.h" +#include "resources/map/mapitem.h" +#include "resources/map/objectslayer.h" +#include "resources/map/speciallayer.h" #include "resources/map/tileanimation.h" +#include "resources/map/tileset.h" +#include "resources/map/walklayer.h" + #ifdef USE_OPENGL #include "render/renderers.h" @@ -63,7 +65,6 @@ #include "utils/delete2.h" #include "utils/dtor.h" #include "utils/mkdir.h" -#include "utils/virtfs.h" #include "utils/timer.h" #include diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc index f2efd49a6..34a0f128b 100644 --- a/src/resources/map/maplayer_unittest.cc +++ b/src/resources/map/maplayer_unittest.cc @@ -26,10 +26,11 @@ #include "enums/resources/map/blockmask.h" #include "enums/resources/map/mapitemtype.h" +#include "fs/virtfs.h" + #include "gui/theme.h" #include "utils/delete2.h" -#include "utils/virtfs.h" #include "render/mockgraphics.h" diff --git a/src/resources/map/speciallayer_unittest.cc b/src/resources/map/speciallayer_unittest.cc index 70f3d07e1..cf6c17120 100644 --- a/src/resources/map/speciallayer_unittest.cc +++ b/src/resources/map/speciallayer_unittest.cc @@ -28,8 +28,9 @@ #include "enums/resources/map/mapitemtype.h" +#include "fs/virtfs.h" + #include "utils/delete2.h" -#include "utils/virtfs.h" #include "resources/sdlimagehelper.h" diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 35081c7ba..bf0b95f71 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -33,6 +33,8 @@ #include "enums/resources/map/collisiontype.h" #include "enums/resources/map/mapitemtype.h" +#include "fs/virtfs.h" + #include "resources/map/map.h" #include "resources/map/mapheights.h" #include "resources/map/maplayer.h" @@ -58,7 +60,6 @@ #include "utils/base64.h" #include "utils/checkutils.h" #include "utils/delete2.h" -#include "utils/virtfs.h" #include "utils/stringmap.h" #include "utils/translation/podict.h" diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc index 56f055b86..6613a42c1 100644 --- a/src/resources/resourcemanager/resourcemanager_unittest.cc +++ b/src/resources/resourcemanager/resourcemanager_unittest.cc @@ -25,13 +25,14 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "resources/sdlimagehelper.h" #include "resources/resourcemanager/resourcemanager.h" #include "utils/env.h" #include "utils/delete2.h" -#include "utils/virtfs.h" #include diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc index 8eeb2178d..8d31125f5 100644 --- a/src/resources/sprite/animatedsprite_unittest.cc +++ b/src/resources/sprite/animatedsprite_unittest.cc @@ -28,6 +28,8 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/theme.h" @@ -42,7 +44,6 @@ #include "utils/env.h" #include "utils/delete2.h" #include "utils/mrand.h" -#include "utils/virtfs.h" #ifndef USE_SDL2 #include diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 397f29af5..413f733be 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -24,10 +24,10 @@ #include "configuration.h" -#include "resources/wallpaperdata.h" +#include "fs/virtfs.h" +#include "fs/virtlist.h" -#include "utils/virtfs.h" -#include "utils/virtlist.h" +#include "resources/wallpaperdata.h" #include diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index 940c51451..5342f82d1 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -28,6 +28,8 @@ #include "being/localplayer.h" #endif // DYECMD +#include "fs/virtfs.h" + #include "resources/sdlmusic.h" #include "resources/soundeffect.h" @@ -35,7 +37,6 @@ #include "resources/loaders/soundloader.h" #include "utils/checkutils.h" -#include "utils/virtfs.h" #include diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index ac872fa54..7e3586d44 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -26,13 +26,13 @@ #include "settings.h" #include "soundmanager.h" +#include "fs/virtfsrwops.h" + #include "gui/skin.h" #include "gui/theme.h" #include "gui/fonts/font.h" -#include "utils/virtfsrwops.h" - #include "render/graphics.h" #include "render/vertexes/imagecollection.h" diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc index 56d37e7a6..fc9677c30 100644 --- a/src/utils/chatutils_unittest.cc +++ b/src/utils/chatutils_unittest.cc @@ -27,12 +27,13 @@ #include "being/localplayer.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/theme.h" #include "utils/chatutils.h" #include "utils/delete2.h" -#include "utils/virtfs.h" #include "render/sdlgraphics.h" diff --git a/src/utils/files.cpp b/src/utils/files.cpp index da7270364..4dd26126a 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -28,10 +28,11 @@ #include "utils/mkdir.h" #if defined(ANDROID) || defined(__native_client__) +#include "fs/virtfs.h" +#include "fs/virtfstools.h" +#include "fs/virtlist.h" + #include "utils/paths.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" -#include "utils/virtlist.h" #endif // defined(ANDROID) || defined(__native_client__) #include diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc index 78be3d924..1012221f2 100644 --- a/src/utils/files_unittest.cc +++ b/src/utils/files_unittest.cc @@ -23,9 +23,10 @@ #include "catch.hpp" #include "logger.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" + #include "utils/delete2.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" #include "resources/resourcemanager/resourcemanager.h" diff --git a/src/utils/gettexthelper.cpp b/src/utils/gettexthelper.cpp index 5b1999925..e95f26289 100644 --- a/src/utils/gettexthelper.cpp +++ b/src/utils/gettexthelper.cpp @@ -28,7 +28,7 @@ #include "client.h" #include "logger.h" -#include "utils/virtfs.h" +#include "fs/virtfs.h" #include diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 43fff958e..3e5bf8829 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -24,9 +24,10 @@ #include "config.h" #endif // _MSC_VER +#include "fs/virtfs.h" + #include "utils/paths.h" -#include "utils/virtfs.h" #include "utils/stringutils.h" #ifdef USE_X11 diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc index 1356e214b..60588571a 100644 --- a/src/utils/stringutils_unittest.cc +++ b/src/utils/stringutils_unittest.cc @@ -24,9 +24,10 @@ #include "const/utils/utf8.h" +#include "fs/virtfs.h" + #include "utils/delete2.h" #include "utils/dtor.h" -#include "utils/virtfs.h" #include "resources/iteminfo.h" diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index 1bd051b48..3d112f22d 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -20,8 +20,9 @@ #include "utils/translation/poparser.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" +#include "fs/virtfs.h" +#include "fs/virtfstools.h" + #include "utils/stringutils.h" #include "utils/translation/podict.h" diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc index 73ef6d396..f8f536f88 100644 --- a/src/utils/translation/poparser_unittest.cc +++ b/src/utils/translation/poparser_unittest.cc @@ -24,12 +24,13 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/theme.h" #include "utils/delete2.h" #include "utils/env.h" -#include "utils/virtfs.h" #include "utils/translation/podict.h" #include "utils/translation/poparser.h" diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp index 199acc844..14751d01c 100644 --- a/src/utils/translation/translationmanager.cpp +++ b/src/utils/translation/translationmanager.cpp @@ -20,8 +20,9 @@ #include "utils/translation/translationmanager.h" +#include "fs/virtfstools.h" + #include "utils/delete2.h" -#include "utils/virtfstools.h" #include "utils/stringutils.h" #include "utils/translation/podict.h" diff --git a/src/utils/virtfile.cpp b/src/utils/virtfile.cpp deleted file mode 100644 index b7e6cce1f..000000000 --- a/src/utils/virtfile.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#include "utils/virtfile.h" - -#include "utils/delete2.h" -#include "utils/virtfileprivate.h" - -#include "debug.h" - -VirtFile::VirtFile() : - mPrivate(nullptr) -{ -} - -VirtFile::~VirtFile() -{ - delete2(mPrivate); -} diff --git a/src/utils/virtfile.h b/src/utils/virtfile.h deleted file mode 100644 index cf7ded1a4..000000000 --- a/src/utils/virtfile.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#ifndef UTILS_VIRTFILE_H -#define UTILS_VIRTFILE_H - -#include "localconsts.h" - -struct VirtFilePrivate; - -struct VirtFile final -{ - VirtFile(); - - A_DELETE_COPY(VirtFile) - - ~VirtFile(); - - VirtFilePrivate *mPrivate; -}; - -#endif // UTILS_VIRTFILE_H diff --git a/src/utils/virtfileprivate.cpp b/src/utils/virtfileprivate.cpp deleted file mode 100644 index e1a5885f7..000000000 --- a/src/utils/virtfileprivate.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#include "utils/virtfileprivate.h" - -#include "debug.h" - -VirtFilePrivate::VirtFilePrivate() : - mFile(nullptr) -{ -} - -VirtFilePrivate::VirtFilePrivate(PHYSFS_file *const file) : - mFile(file) -{ -} - -VirtFilePrivate::~VirtFilePrivate() -{ - if (mFile != nullptr) - { - PHYSFS_close(mFile); - mFile = nullptr; - } -} diff --git a/src/utils/virtfileprivate.h b/src/utils/virtfileprivate.h deleted file mode 100644 index 5b280de78..000000000 --- a/src/utils/virtfileprivate.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#ifndef UTILS_VIRTFILEPRIVATE_H -#define UTILS_VIRTFILEPRIVATE_H - -#include "localconsts.h" - -PRAGMA45(GCC diagnostic push) -PRAGMA45(GCC diagnostic ignored "-Wlong-long") -#include -PRAGMA45(GCC diagnostic pop) - -struct VirtFilePrivate final -{ - VirtFilePrivate(); - - explicit VirtFilePrivate(PHYSFS_file *const file); - - A_DELETE_COPY(VirtFilePrivate) - - ~VirtFilePrivate(); - - PHYSFS_file *mFile; -}; - -#endif // UTILS_VIRTFILEPRIVATE_H diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp deleted file mode 100644 index cf1d353b6..000000000 --- a/src/utils/virtfs.cpp +++ /dev/null @@ -1,303 +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 . - */ - -#include "utils/virtfs.h" - -#include "utils/checkutils.h" -#include "utils/virtfile.h" -#include "utils/virtfileprivate.h" -#include "utils/virtlist.h" - -#include -#include - -#ifdef ANDROID -#include "utils/paths.h" -#endif // ANDROID - -#include "debug.h" - -const char *dirSeparator = nullptr; - -namespace VirtFs -{ -#if defined(__native_client__) - void init(const std::string &restrict name A_UNUSED) - { - if (!PHYSFS_init("/fakebinary")) -#elif defined(ANDROID) - void init(const std::string &restrict name A_UNUSED) - { - if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) -#else // defined(__native_client__) - - void init(const std::string &restrict name) - { - if (!PHYSFS_init(name.c_str())) -#endif // defined(__native_client__) - { - std::cout << "Error while initializing PhysFS: " - << VirtFs::getLastError() << std::endl; - _exit(1); - } - updateDirSeparator(); - atexit(reinterpret_cast(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 std::string &restrict name) - { - return PHYSFS_exists(name.c_str()); - } - - VirtList *enumerateFiles(const std::string &restrict dir) - { - char ** handle = PHYSFS_enumerateFiles(dir.c_str()); - VirtList *const files = new VirtList; - if (handle == nullptr) - return files; - for (const char *const *i = handle; *i; i++) - { - std::string str = *i; - files->names.push_back(str); - } - PHYSFS_freeList(handle); - return files; - } - - bool isDirectory(const std::string &restrict name) - { - return PHYSFS_isDirectory(name.c_str()); - } - - bool isSymbolicLink(const std::string &restrict name) - { - return PHYSFS_isSymbolicLink(name.c_str()); - } - - void freeList(VirtList *restrict const handle) - { - delete handle; - } - - VirtFile *openRead(const std::string &restrict filename) - { - PHYSFS_file *restrict const handle = PHYSFS_openRead( - filename.c_str()); - if (!handle) - return nullptr; - VirtFile *restrict const file = new VirtFile; - file->mPrivate = new VirtFilePrivate(handle); - return file; - } - - VirtFile *openWrite(const std::string &restrict filename) - { - PHYSFS_file *restrict const handle = PHYSFS_openWrite( - filename.c_str()); - if (!handle) - return nullptr; - VirtFile *restrict const file = new VirtFile; - file->mPrivate = new VirtFilePrivate(handle); - return file; - } - - VirtFile *openAppend(const std::string &restrict filename) - { - PHYSFS_file *restrict const handle = PHYSFS_openAppend( - filename.c_str()); - if (!handle) - return nullptr; - VirtFile *restrict const file = new VirtFile; - file->mPrivate = new VirtFilePrivate(handle); - return file; - } - - bool setWriteDir(const std::string &restrict newDir) - { - return PHYSFS_setWriteDir(newDir.c_str()); - } - - bool addDirToSearchPath(const std::string &restrict newDir, - const Append append) - { - logger->log("Add virtual directory: " + newDir); - if (newDir.find(".zip") != std::string::npos) - { - reportAlways("Called addDirToSearchPath with zip archive"); - return false; - } - return PHYSFS_addToSearchPath(newDir.c_str(), - append == Append_true ? 1 : 0); - } - - bool removeDirFromSearchPath(const std::string &restrict oldDir) - { - logger->log("Remove virtual directory: " + oldDir); - if (oldDir.find(".zip") != std::string::npos) - { - reportAlways("Called removeDirFromSearchPath with zip archive"); - return false; - } - return PHYSFS_removeFromSearchPath(oldDir.c_str()); - } - - bool addZipToSearchPath(const std::string &restrict newDir, - const Append append) - { - logger->log("Add virtual zip: " + newDir); - if (newDir.find(".zip") == std::string::npos) - { - reportAlways("Called addZipToSearchPath without zip archive"); - return false; - } - return PHYSFS_addToSearchPath(newDir.c_str(), - append == Append_true ? 1 : 0); - } - - bool removeZipFromSearchPath(const std::string &restrict oldDir) - { - logger->log("Remove virtual zip: " + oldDir); - if (oldDir.find(".zip") == std::string::npos) - { - reportAlways("Called removeZipFromSearchPath without zip archive"); - return false; - } - return PHYSFS_removeFromSearchPath(oldDir.c_str()); - } - - std::string getRealDir(const std::string &restrict filename) - { - const char *const str = PHYSFS_getRealDir(filename.c_str()); - if (str == nullptr) - return std::string(); - return str; - } - - bool mkdir(const std::string &restrict dirname) - { - return PHYSFS_mkdir(dirname.c_str()); - } - - bool remove(const std::string &restrict filename) - { - return PHYSFS_delete(filename.c_str()); - } - - 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(); - } - - int close(VirtFile *restrict const file) - { - if (file == nullptr) - return 0; - delete file; - return 1; - } - - int64_t read(VirtFile *restrict const file, - void *restrict const buffer, - const uint32_t objSize, - const uint32_t objCount) - { - if (file == nullptr) - return 0; - return PHYSFS_read(file->mPrivate->mFile, - buffer, - objSize, - objCount); - } - - int64_t write(VirtFile *restrict const file, - const void *restrict const buffer, - const uint32_t objSize, - const uint32_t objCount) - { - if (file == nullptr) - return 0; - return PHYSFS_write(file->mPrivate->mFile, - buffer, - objSize, - objCount); - } - - int64_t fileLength(VirtFile *restrict const file) - { - if (file == nullptr) - return -1; - return PHYSFS_fileLength(file->mPrivate->mFile); - } - - int64_t tell(VirtFile *restrict const file) - { - if (file == nullptr) - return -1; - return PHYSFS_tell(file->mPrivate->mFile); - } - - int seek(VirtFile *restrict const file, - const uint64_t pos) - { - return PHYSFS_seek(file->mPrivate->mFile, - pos); - } - - int eof(VirtFile *restrict const file) - { - return PHYSFS_eof(file->mPrivate->mFile); - } -} // namespace VirtFs diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h deleted file mode 100644 index e0f188cfb..000000000 --- a/src/utils/virtfs.h +++ /dev/null @@ -1,79 +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 . - */ - -#ifndef UTILS_VIRTFS_H -#define UTILS_VIRTFS_H - -#include "enums/simpletypes/append.h" - -#include "localconsts.h" - -#include - -struct VirtFile; -struct VirtList; - -namespace VirtFs -{ - void init(const std::string &restrict name); - void updateDirSeparator(); - const char *getDirSeparator(); - const char *getBaseDir(); - const char *getUserDir(); - bool exists(const std::string &restrict name); - VirtList *enumerateFiles(const std::string &restrict dir) RETURNS_NONNULL; - bool isDirectory(const std::string &restrict name); - bool isSymbolicLink(const std::string &restrict name); - void freeList(VirtList *restrict const handle); - VirtFile *openRead(const std::string &restrict filename); - VirtFile *openWrite(const std::string &restrict filename); - VirtFile *openAppend(const std::string &restrict filename); - bool setWriteDir(const std::string &restrict newDir); - bool addDirToSearchPath(const std::string &restrict newDir, - const Append append); - bool removeDirFromSearchPath(const std::string &restrict oldDir); - bool addZipToSearchPath(const std::string &restrict newDir, - const Append append); - bool removeZipFromSearchPath(const std::string &restrict oldDir); - std::string getRealDir(const std::string &restrict filename); - bool mkdir(const std::string &restrict dirName); - bool remove(const std::string &restrict filename); - bool deinit(); - void permitLinks(const bool val); - const char *getLastError(); - int64_t read(VirtFile *restrict const handle, - void *restrict const buffer, - const uint32_t objSize, - const uint32_t objCount); - int64_t write(VirtFile *restrict const file, - const void *restrict const buffer, - const uint32_t objSize, - const uint32_t objCount); - int close(VirtFile *restrict const file); - int64_t fileLength(VirtFile *restrict const file); - int64_t tell(VirtFile *restrict const file); - int seek(VirtFile *restrict const file, - const uint64_t pos); - int eof(VirtFile *restrict const file); -} // namespace VirtFs - -extern const char *dirSeparator; - -#endif // UTILS_VIRTFS_H diff --git a/src/utils/virtfs_unittest.cc b/src/utils/virtfs_unittest.cc deleted file mode 100644 index e8af0bb1d..000000000 --- a/src/utils/virtfs_unittest.cc +++ /dev/null @@ -1,405 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2016-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 . - */ - -#include "catch.hpp" - -#include "utils/checkutils.h" -#include "utils/delete2.h" -#include "utils/virtfs.h" -#include "utils/virtfstools.h" -#include "utils/virtlist.h" - -#include "debug.h" - -TEST_CASE("VirtFs dirSeparator") -{ - REQUIRE(dirSeparator != nullptr); - REQUIRE(VirtFs::getDirSeparator() == std::string(dirSeparator)); - VirtFs::updateDirSeparator(); - REQUIRE(dirSeparator != nullptr); - REQUIRE(VirtFs::getDirSeparator() == std::string(dirSeparator)); -} - -TEST_CASE("VirtFs getBaseDir") -{ - REQUIRE(VirtFs::getBaseDir() != nullptr); -} - -TEST_CASE("VirtFs getUserDir") -{ - REQUIRE(VirtFs::getUserDir() != nullptr); -} - -TEST_CASE("VirtFs exists") -{ - logger = new Logger(); - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - REQUIRE(VirtFs::exists("test/units.xml") == true); - REQUIRE(VirtFs::exists("test/units123.xml") == false); - REQUIRE(VirtFs::exists("tesQ/units.xml") == false); - REQUIRE(VirtFs::exists("units.xml") == false); - - VirtFs::addDirToSearchPath("data/test", Append_false); - VirtFs::addDirToSearchPath("../data/test", Append_false); - - REQUIRE(VirtFs::exists("test/units.xml") == true); - REQUIRE(VirtFs::exists("test/units123.xml") == false); - REQUIRE(VirtFs::exists("tesQ/units.xml") == false); - REQUIRE(VirtFs::exists("units.xml") == true); - - VirtFs::removeDirFromSearchPath("data/test"); - VirtFs::removeDirFromSearchPath("../data/test"); - - REQUIRE(VirtFs::exists("test/units.xml") == true); - REQUIRE(VirtFs::exists("test/units123.xml") == false); - REQUIRE(VirtFs::exists("tesQ/units.xml") == false); - REQUIRE(VirtFs::exists("units.xml") == false); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -static void removeTemp(StringVect &restrict list) -{ - int cnt = 0; - std::sort(list.begin(), list.end()); - - FOR_EACH (StringVectIter, it, list) - { - if (*it != "serverlistplus.xml.part") - { - logger->log("file: %d %s", - cnt, - (*it).c_str()); - cnt ++; - } - } - - FOR_EACH (StringVectIter, it, list) - { - if (*it == "serverlistplus.xml.part") - { - list.erase(it); - return; - } - } -} - -TEST_CASE("VirtFs enumerateFiles") -{ - logger = new Logger; - - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - VirtList *list = nullptr; - - const int cnt1 = VirtFs::exists("test/test2.txt") ? 23 : 22; - const int cnt2 = 23; - - VirtFs::permitLinks(false); - list = VirtFs::enumerateFiles("test"); - removeTemp(list->names); - const size_t sz = list->names.size(); - REQUIRE(sz == cnt1); - VirtFs::freeList(list); - - VirtFs::permitLinks(true); - list = VirtFs::enumerateFiles("test"); - removeTemp(list->names); - REQUIRE(list->names.size() == cnt2); - VirtFs::freeList(list); - - VirtFs::permitLinks(false); - list = VirtFs::enumerateFiles("test"); - removeTemp(list->names); - REQUIRE(list->names.size() == cnt1); - VirtFs::freeList(list); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -TEST_CASE("VirtFs isDirectory") -{ - logger = new Logger(); - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - REQUIRE(VirtFs::isDirectory("test/units.xml") == false); - REQUIRE(VirtFs::isDirectory("test/units.xml/") == false); - REQUIRE(VirtFs::isDirectory("test//units.xml") == false); - REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); - REQUIRE(VirtFs::isDirectory("test//units123.xml") == false); - REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); - REQUIRE(VirtFs::isDirectory("tesQ//units.xml") == false); - REQUIRE(VirtFs::isDirectory("units.xml") == false); - REQUIRE(VirtFs::isDirectory("test") == true); - REQUIRE(VirtFs::isDirectory("test/") == true); - REQUIRE(VirtFs::isDirectory("test//") == true); - REQUIRE(VirtFs::isDirectory("test/dir1") == true); - REQUIRE(VirtFs::isDirectory("test//dir1") == true); - REQUIRE(VirtFs::isDirectory("test//dir1/") == true); - REQUIRE(VirtFs::isDirectory("test//dir1//") == true); - REQUIRE(VirtFs::isDirectory("test/dir1/") == true); - REQUIRE(VirtFs::isDirectory("test/dir1//") == true); - REQUIRE(VirtFs::isDirectory("testQ") == false); - REQUIRE(VirtFs::isDirectory("testQ/") == false); - REQUIRE(VirtFs::isDirectory("testQ//") == false); - - VirtFs::addDirToSearchPath("data/test", Append_false); - VirtFs::addDirToSearchPath("../data/test", Append_false); - - REQUIRE(VirtFs::isDirectory("test/units.xml") == false); - REQUIRE(VirtFs::isDirectory("test/units.xml/") == false); - REQUIRE(VirtFs::isDirectory("test//units.xml") == false); - REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); - REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); - REQUIRE(VirtFs::isDirectory("units.xml") == false); - REQUIRE(VirtFs::isDirectory("test") == true); - REQUIRE(VirtFs::isDirectory("testQ") == false); - REQUIRE(VirtFs::isDirectory("test/dir1") == true); - - VirtFs::removeDirFromSearchPath("data/test"); - VirtFs::removeDirFromSearchPath("../data/test"); - - REQUIRE(VirtFs::isDirectory("test/units.xml") == false); - REQUIRE(VirtFs::isDirectory("test/units123.xml") == false); - REQUIRE(VirtFs::isDirectory("tesQ/units.xml") == false); - REQUIRE(VirtFs::isDirectory("units.xml") == false); - REQUIRE(VirtFs::isDirectory("units.xml/") == false); - REQUIRE(VirtFs::isDirectory("test") == true); - REQUIRE(VirtFs::isDirectory("test/") == true); - REQUIRE(VirtFs::isDirectory("testQ") == false); - REQUIRE(VirtFs::isDirectory("test/dir1") == true); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -TEST_CASE("VirtFs openRead") -{ - logger = new Logger(); - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - VirtFile *file = nullptr; - - file = VirtFs::openRead("test/units.xml"); - REQUIRE(file != nullptr); - VirtFs::close(file); - file = VirtFs::openRead("test/units123.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("tesQ/units.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("units.xml"); - REQUIRE(file == nullptr); -// file = VirtFs::openRead("test"); -// REQUIRE(file == nullptr); - file = VirtFs::openRead("testQ"); - REQUIRE(file == nullptr); - - VirtFs::addDirToSearchPath("data/test", Append_false); - VirtFs::addDirToSearchPath("../data/test", Append_false); - - file = VirtFs::openRead("test/units.xml"); - REQUIRE(file != nullptr); - VirtFs::close(file); - file = VirtFs::openRead("test/units123.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("tesQ/units.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("units.xml"); - REQUIRE(file != nullptr); - VirtFs::close(file); -// file = VirtFs::openRead("test"); -// REQUIRE(file == nullptr); - file = VirtFs::openRead("testQ"); - REQUIRE(file == nullptr); - - VirtFs::removeDirFromSearchPath("data/test"); - VirtFs::removeDirFromSearchPath("../data/test"); - - file = VirtFs::openRead("test/units.xml"); - REQUIRE(file != nullptr); - VirtFs::close(file); - file = VirtFs::openRead("test/units123.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("tesQ/units.xml"); - REQUIRE(file == nullptr); - file = VirtFs::openRead("units.xml"); - REQUIRE(file == nullptr); -// file = VirtFs::openRead("test"); -// REQUIRE(file == nullptr); - file = VirtFs::openRead("testQ"); - REQUIRE(file == nullptr); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -TEST_CASE("VirtFs addZipToSearchPath") -{ - // +++ need implement -} - -TEST_CASE("VirtFs removeZipFromSearchPath") -{ - // +++ need implement -} - -TEST_CASE("VirtFs getRealDir") -{ - logger = new Logger(); - REQUIRE(VirtFs::getRealDir(".") == ""); - REQUIRE(VirtFs::getRealDir("..") == ""); - const bool dir1 = VirtFs::addDirToSearchPath("data", Append_false); - REQUIRE((dir1 || VirtFs::addDirToSearchPath("../data", Append_false)) == - true); - if (dir1 == true) - { - REQUIRE(VirtFs::getRealDir("test") == "data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "data"); - } - else - { - REQUIRE(VirtFs::getRealDir("test") == "../data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "../data"); - } - REQUIRE(VirtFs::getRealDir("zzz") == ""); - - VirtFs::addDirToSearchPath("data/test", Append_false); - VirtFs::addDirToSearchPath("../data/test", Append_false); - if (dir1 == true) - { - REQUIRE(VirtFs::getRealDir("test") == "data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "data"); - REQUIRE(VirtFs::getRealDir("test.txt") == - "data/test"); - } - else - { - REQUIRE(VirtFs::getRealDir("test") == "../data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "../data"); - REQUIRE(VirtFs::getRealDir("test.txt") == - "../data/test"); - } - REQUIRE(VirtFs::getRealDir("zzz") == ""); - - VirtFs::removeDirFromSearchPath("data/test"); - VirtFs::removeDirFromSearchPath("../data/test"); - - if (dir1 == true) - { - REQUIRE(VirtFs::getRealDir("test") == "data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "data"); - } - else - { - REQUIRE(VirtFs::getRealDir("test") == "../data"); - REQUIRE(VirtFs::getRealDir("test/test.txt") == - "../data"); - } - REQUIRE(VirtFs::getRealDir("zzz") == ""); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -TEST_CASE("VirtFs permitLinks") -{ - logger = new Logger(); - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - const int cnt1 = VirtFs::exists("test/test2.txt") ? 22 : 21; - const int cnt2 = 22; - - StringVect list; - VirtFs::permitLinks(false); - VirtFs::getFiles("test", list); - removeTemp(list); - const size_t sz = list.size(); - REQUIRE(sz == cnt1); - - list.clear(); - VirtFs::permitLinks(true); - VirtFs::getFiles("test", list); - removeTemp(list); - REQUIRE(list.size() == cnt2); - - list.clear(); - VirtFs::permitLinks(false); - VirtFs::getFiles("test", list); - removeTemp(list); - REQUIRE(list.size() == cnt1); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} - -TEST_CASE("VirtFs read") -{ - logger = new Logger(); - VirtFs::addDirToSearchPath("data", Append_false); - VirtFs::addDirToSearchPath("../data", Append_false); - - VirtFile *file = VirtFs::openRead("test/test.txt"); - REQUIRE(file != nullptr); - REQUIRE(VirtFs::fileLength(file) == 23); - const int fileSize = VirtFs::fileLength(file); - - void *restrict buffer = calloc(fileSize + 1, 1); - REQUIRE(VirtFs::read(file, buffer, 1, fileSize) == fileSize); - REQUIRE(strcmp(static_cast(buffer), - "test line 1\ntest line 2") == 0); - REQUIRE(VirtFs::tell(file) == fileSize); - REQUIRE(VirtFs::eof(file) == true); - - free(buffer); - buffer = calloc(fileSize + 1, 1); - REQUIRE(VirtFs::seek(file, 12) != 0); - REQUIRE(VirtFs::eof(file) == false); - REQUIRE(VirtFs::tell(file) == 12); - REQUIRE(VirtFs::read(file, buffer, 1, 11) == 11); - REQUIRE(strcmp(static_cast(buffer), - "test line 2") == 0); - REQUIRE(VirtFs::eof(file) == true); - - VirtFs::close(file); - free(buffer); - - VirtFs::removeDirFromSearchPath("data"); - VirtFs::removeDirFromSearchPath("../data"); - delete2(logger); -} diff --git a/src/utils/virtfsrwops.cpp b/src/utils/virtfsrwops.cpp deleted file mode 100644 index 837704465..000000000 --- a/src/utils/virtfsrwops.cpp +++ /dev/null @@ -1,433 +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 . - */ - -/* - * This code provides a glue layer between PhysicsFS and Simple Directmedia - * Layer's (SDL) RWops i/o abstraction. - * - * License: this code is public domain. I make no warranty that it is useful, - * correct, harmless, or environmentally safe. - * - * This particular file may be used however you like, including copying it - * verbatim into a closed-source project, exploiting it commercially, and - * removing any trace of my name from the source (although I hope you won't - * do that). I welcome enhancements and corrections to this file, but I do - * not require you to send me patches if you make changes. This code has - * NO WARRANTY. - * - * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. - * Please see LICENSE.txt in the root of the source tree. - * - * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/ - * - * This file was written by Ryan C. Gordon. (icculus@icculus.org). - * - * Copyright (C) 2012-2017 The ManaPlus Developers - */ - -#include "utils/virtfsrwops.h" - -#include "logger.h" - -#ifdef DEBUG_VIRTFS -#include "utils/debugmemoryobject.h" - -#include -#endif // DEBUG_VIRTFS - -#include "utils/fuzzer.h" -#include "utils/virtfs.h" - -#include "debug.h" - -#ifdef USE_SDL2 -#define RWOPSINT int64_t -#define RWOPSSIZE size_t -#else // USE_SDL2 -#define RWOPSINT int32_t -#define RWOPSSIZE int -#endif // USE_SDL2 - -#ifdef DUMP_LEAKED_RESOURCES -static int openedRWops = 0; -#endif // DUMP_LEAKED_RESOURCES - -#ifdef DEBUG_VIRTFS -namespace -{ - std::map mRWops; -} // namespace - -static SDL_RWops *addDebugRWops(SDL_RWops *restrict const rwops, - const char *restrict const name, - const char *restrict const file, - const unsigned line) -{ - if (!rwops) - return nullptr; - - mRWops[rwops] = new VirtFs::DebugMemoryObject(name, file, line); - return rwops; -} - -static void deleteDebugRWops(SDL_RWops *const rwops) -{ - if (!rwops) - return; - - std::map::iterator it = - mRWops.find(rwops); - if (it == mRWops.end()) - { - logger->log("bad RWops delete: %p", static_cast(rwops)); - } - else - { - VirtFs::DebugMemoryObject *const obj = (*it).second; - if (obj) - { - mRWops.erase(rwops); - delete obj; - } - } -} - -void VirtFs::reportLeaks() -{ - if (!mRWops.empty()) - { - logger->log("RWops leaks detected"); - std::map::iterator it = - mRWops.begin(); - const std::map::iterator - it_end = mRWops.end(); - for (; it != it_end; ++it) - { - VirtFs::DebugMemoryObject *obj = (*it).second; - if (obj) - { - logger->log("file: %s at %s", obj->mName.c_str(), - obj->mAddFile.c_str()); - delete obj; - } - } - mRWops.clear(); - } -} -#endif // DEBUG_VIRTFS - -static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw, - const RWOPSINT offset, - const int whence) -{ - if (!rw) - return -1; - VirtFile *const handle = static_cast( - rw->hidden.unknown.data1); - RWOPSINT pos = 0; - - if (whence == SEEK_SET) - { - pos = offset; - } /* if */ - else if (whence == SEEK_CUR) - { - const int64_t current = VirtFs::tell(handle); - if (current == -1) - { - logger->assertLog( - "virtfsrwops_seek: Can't find position in file: %s", - VirtFs::getLastError()); - return -1; - } /* if */ - - pos = CAST_S32(current); - if (static_cast(pos) != current) - { - logger->assertLog("virtfsrwops_seek: " - "Can't fit current file position in an int!"); - return -1; - } /* if */ - - if (offset == 0) /* this is a "tell" call. We're done. */ - return pos; - - pos += offset; - } /* else if */ - else if (whence == SEEK_END) - { - const int64_t len = VirtFs::fileLength(handle); - if (len == -1) - { - logger->assertLog("virtfsrwops_seek:Can't find end of file: %s", - VirtFs::getLastError()); - return -1; - } /* if */ - - pos = static_cast(len); - if (static_cast(pos) != len) - { - logger->assertLog("virtfsrwops_seek: " - "Can't fit end-of-file position in an int!"); - return -1; - } /* if */ - - pos += offset; - } /* else if */ - else - { - logger->assertLog("virtfsrwops_seek: Invalid 'whence' parameter."); - return -1; - } /* else */ - - if (pos < 0) - { - logger->assertLog("virtfsrwops_seek: " - "Attempt to seek past start of file."); - return -1; - } /* if */ - - if (!VirtFs::seek(handle, static_cast(pos))) - { - logger->assertLog("virtfsrwops_seek: seek error: %s", - VirtFs::getLastError()); - return -1; - } /* if */ - - return pos; -} /* virtfsrwops_seek */ - -static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw, - void *const ptr, - const RWOPSSIZE size, - const RWOPSSIZE maxnum) -{ - if (!rw) - return 0; - VirtFile *const handle = static_cast( - rw->hidden.unknown.data1); - const int64_t rc = VirtFs::read(handle, ptr, - CAST_U32(size), - CAST_U32(maxnum)); - if (rc != static_cast(maxnum)) - { - if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */ - { - logger->assertLog("virtfsrwops_seek: read error: %s", - VirtFs::getLastError()); - } - } /* if */ - - return CAST_S32(rc); -} /* virtfsrwops_read */ - -static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw, - const void *const ptr, - const RWOPSSIZE size, - const RWOPSSIZE num) -{ - if (!rw) - return 0; - VirtFile *const handle = static_cast( - rw->hidden.unknown.data1); - const int64_t rc = VirtFs::write(handle, ptr, - CAST_U32(size), - CAST_U32(num)); - if (rc != static_cast(num)) - { - logger->assertLog("virtfsrwops_seek: write error: %s", - VirtFs::getLastError()); - } - - return CAST_S32(rc); -} /* virtfsrwops_write */ - -static int virtfsrwops_close(SDL_RWops *const rw) -{ - if (!rw) - return 0; - VirtFile *const handle = static_cast( - rw->hidden.unknown.data1); - if (!VirtFs::close(handle)) - { - logger->assertLog("virtfsrwops_seek: close error: %s", - VirtFs::getLastError()); - return -1; - } /* if */ - - SDL_FreeRW(rw); -#ifdef DUMP_LEAKED_RESOURCES - if (openedRWops <= 0) - logger->assertLog("virtfsrwops_seek: closing already closed RWops"); - openedRWops --; -#endif // DUMP_LEAKED_RESOURCES -#ifdef DEBUG_VIRTFS - deleteDebugRWops(rw); -#endif // DEBUG_VIRTFS - - return 0; -} /* virtfsrwops_close */ - -#ifdef USE_SDL2 -static RWOPSINT virtfsrwops_size(SDL_RWops *const rw) -{ - VirtFile *const handle = static_cast( - rw->hidden.unknown.data1); - return VirtFs::fileLength(handle); -} /* virtfsrwops_size */ -#endif // USE_SDL2 - -static SDL_RWops *create_rwops(VirtFile *const file) -{ - SDL_RWops *retval = nullptr; - - if (!file) - { - logger->assertLog("virtfsrwops_seek: create rwops error: %s", - VirtFs::getLastError()); - } - else - { - retval = SDL_AllocRW(); - if (retval) - { -#ifdef USE_SDL2 - retval->size = &virtfsrwops_size; -#endif // USE_SDL2 - - retval->seek = &virtfsrwops_seek; - retval->read = &virtfsrwops_read; - retval->write = &virtfsrwops_write; - retval->close = &virtfsrwops_close; - retval->hidden.unknown.data1 = file; - } /* if */ -#ifdef DUMP_LEAKED_RESOURCES - openedRWops ++; -#endif // DUMP_LEAKED_RESOURCES - } /* else */ - - return retval; -} /* create_rwops */ - -SDL_RWops *VirtFs::MakeRWops(VirtFile *const handle) -{ - SDL_RWops *retval = nullptr; - if (!handle) - { - logger->assertLog("virtfsrwops_seek: NULL pointer passed to " - "RWopsmakeRWops()."); - } - else - { - retval = create_rwops(handle); - } - - return retval; -} /* RWopsmakeRWops */ - -#ifdef __APPLE__ -static bool checkFilePath(const std::string &restrict fname) -{ - if (fname.empty()) - return false; - if (!VirtFs::exists(fname) || VirtFs::isDirectory(fname)) - return false; - return true; -} -#endif // __APPLE__ - -#ifdef DEBUG_VIRTFS -#undef RWopsOpenRead -SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname, - const char *restrict const file, - const unsigned line) -#else // DEBUG_VIRTFS -SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname) -#endif // DEBUG_VIRTFS -{ - BLOCK_START("RWopsopenRead") -#ifdef __APPLE__ - if (!checkFilePath(fname)) - return nullptr; -#endif // __APPLE__ -#ifdef USE_FUZZER - if (Fuzzer::conditionTerminate(fname)) - return nullptr; -#endif // USE_FUZZER -#ifdef USE_PROFILER - -#ifdef DEBUG_VIRTFS - SDL_RWops *const ret = addDebugRWops( - create_rwops(VirtFs::openRead(fname)), - fname, - file, - line); -#else // DEBUG_VIRTFS - SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname)); -#endif // DEBUG_VIRTFS - - BLOCK_END("RWopsopenRead") - return ret; -#else // USE_PROFILER - -#ifdef DEBUG_VIRTFS - return addDebugRWops( - create_rwops(VirtFs::openRead(fname)), - fname, - file, - line); -#else // DEBUG_VIRTFS - return create_rwops(VirtFs::openRead(fname)); -#endif // DEBUG_VIRTFS -#endif // USE_PROFILER -} /* RWopsopenRead */ - -SDL_RWops *VirtFs::RWopsOpenWrite(const std::string &restrict fname) -{ -#ifdef __APPLE__ - if (!checkFilePath(fname)) - return nullptr; -#endif // __APPLE__ - - return create_rwops(VirtFs::openWrite(fname)); -} /* RWopsopenWrite */ - -SDL_RWops *VirtFs::RWopsOpenAppend(const std::string &restrict fname) -{ -#ifdef __APPLE__ - if (!checkFilePath(fname)) - return nullptr; -#endif // __APPLE__ - - return create_rwops(VirtFs::openAppend(fname)); -} /* RWopsopenAppend */ - -#ifdef DUMP_LEAKED_RESOURCES -void VirtFs::reportRWops() -{ - if (openedRWops) - { - logger->assertLog("virtfsrwops_seek: leaking RWops: %d", - openedRWops); - } -} -#endif // DUMP_LEAKED_RESOURCES - -/* end of physfsrwops.c ... */ diff --git a/src/utils/virtfsrwops.h b/src/utils/virtfsrwops.h deleted file mode 100644 index 82bb740de..000000000 --- a/src/utils/virtfsrwops.h +++ /dev/null @@ -1,75 +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 . - */ - -/* - * This code provides a glue layer between PhysicsFS and Simple Directmedia - * Layer's (SDL) RWops i/o abstraction. - * - * License: this code is public domain. I make no warranty that it is useful, - * correct, harmless, or environmentally safe. - * - * This particular file may be used however you like, including copying it - * verbatim into a closed-source project, exploiting it commercially, and - * removing any trace of my name from the source (although I hope you won't - * do that). I welcome enhancements and corrections to this file, but I do - * not require you to send me patches if you make changes. This code has - * NO WARRANTY. - * - * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. - * Please see LICENSE.txt in the root of the source tree. - * - * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/ - * - * This file was written by Ryan C. Gordon. (icculus@icculus.org). - * - * Copyright (C) 2012-2017 The ManaPlus Developers - */ - -#ifndef UTILS_PHYSFSRWOPS_H -#define UTILS_PHYSFSRWOPS_H - -#include "localconsts.h" - -#include -#include - -struct VirtFile; - -namespace VirtFs -{ -#ifdef DEBUG_VIRTFS - SDL_RWops *RWopsOpenRead(const std::string &restrict fname, - const char *restrict const file, - const unsigned line); - void reportLeaks(); -#else // DEBUG_VIRTFS - SDL_RWops *RWopsOpenRead(const std::string &restrict fname); -#endif // DEBUG_VIRTFS - - SDL_RWops *RWopsOpenWrite(const std::string &restrict fname) A_WARN_UNUSED; - SDL_RWops *RWopsOpenAppend(const std::string &restrict fname) - A_WARN_UNUSED; - SDL_RWops *MakeRWops(VirtFile *const handle) A_WARN_UNUSED; -#ifdef DUMP_LEAKED_RESOURCES - void reportRWops(); -#endif // DUMP_LEAKED_RESOURCES -} // namespace VirtFs - -#endif // UTILS_PHYSFSRWOPS_H diff --git a/src/utils/virtfstools.cpp b/src/utils/virtfstools.cpp deleted file mode 100644 index adc1c9772..000000000 --- a/src/utils/virtfstools.cpp +++ /dev/null @@ -1,222 +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 . - */ - -#include "utils/virtfstools.h" - -#include "logger.h" - -#include "utils/paths.h" -#include "utils/stringutils.h" -#include "utils/virtfs.h" -#include "utils/virtlist.h" - -#include -#include - -#include "debug.h" - -namespace VirtFs -{ - void *loadFile(const std::string &restrict fileName, - int &restrict fileSize) - { - // Attempt to open the specified file using PhysicsFS - VirtFile *restrict const file = VirtFs::openRead(fileName); - - 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 *restrict const buffer = calloc(fileSize, 1); - VirtFs::read(file, buffer, 1, fileSize); - VirtFs::close(file); - - return buffer; - } - - void searchAndAddArchives(const std::string &restrict path, - const std::string &restrict ext, - const Append append) - { - VirtList *const list = VirtFs::enumerateFiles(path); - FOR_EACH (StringVectCIter, i, list->names) - { - const std::string str = *i; - const size_t len = str.size(); - - if (len > ext.length() && - !ext.compare(str.substr(len - ext.length()))) - { - const std::string file = path + str; - const std::string realPath = VirtFs::getRealDir(file); - VirtFs::addZipToSearchPath(std::string(realPath).append( - dirSeparator).append(file), append); - } - } - VirtFs::freeList(list); - } - - void searchAndRemoveArchives(const std::string &restrict path, - const std::string &restrict ext) - { - VirtList *const list = VirtFs::enumerateFiles(path); - FOR_EACH (StringVectCIter, i, list->names) - { - const std::string str = *i; - const size_t len = str.size(); - if (len > ext.length() && - !ext.compare(str.substr(len - ext.length()))) - { - const std::string file = path + str; - const std::string realPath = VirtFs::getRealDir(file); - VirtFs::removeZipFromSearchPath(std::string( - realPath).append( - dirSeparator).append( - file)); - } - } - VirtFs::freeList(list); - } - - void getFilesWithDir(const std::string &path, - StringVect &list) - { - VirtList *const fonts = VirtFs::enumerateFiles(path); - FOR_EACH (StringVectCIter, i, fonts->names) - { - if (!VirtFs::isDirectory(path + *i)) - list.push_back(path + *i); - } - VirtFs::freeList(fonts); - } - - void getFilesInDir(const std::string &dir, - StringVect &list, - const std::string &ext) - { - const std::string path = dir + "/"; - StringVect tempList; - VirtFs::getFilesWithDir(path, tempList); - FOR_EACH (StringVectCIter, it, tempList) - { - const std::string &str = *it; - if (findLast(str, ext)) - list.push_back(str); - } - std::sort(list.begin(), list.end()); - } - - void getFiles(const std::string &path, - StringVect &list) - { - VirtList *const fonts = VirtFs::enumerateFiles(path); - FOR_EACH (StringVectCIter, i, fonts->names) - { - if (!VirtFs::isDirectory(path + dirSeparator + *i)) - list.push_back(*i); - } - VirtFs::freeList(fonts); - } - - void getDirs(const std::string &path, StringVect &list) - { - VirtList *const fonts = VirtFs::enumerateFiles(path); - FOR_EACH (StringVectCIter, i, fonts->names) - { - if (VirtFs::isDirectory(path + dirSeparator + *i)) - list.push_back(*i); - } - VirtFs::freeList(fonts); - } - - std::string getPath(const std::string &file) - { - // get the real path to the file - const std::string tmp = VirtFs::getRealDir(file); - std::string path; - - // if the file is not in the search path, then its empty - if (!tmp.empty()) - { - path = std::string(tmp).append(dirSeparator).append(file); -#if defined __native_client__ - std::string dataZip = "/http/data.zip/"; - if (path.substr(0, dataZip.length()) == dataZip) - path = path.replace(0, dataZip.length(), "/http/data/"); -#endif // defined __native_client__ - } - else - { - // if not found in search path return the default path - path = getPackageDir().append(dirSeparator).append(file); - } - - return path; - } - - std::string loadTextFileString(const std::string &fileName) - { - int contentsLength; - char *fileContents = static_cast( - VirtFs::loadFile(fileName, contentsLength)); - - if (!fileContents) - { - logger->log("Couldn't load text file: %s", fileName.c_str()); - return std::string(); - } - const std::string str = std::string(fileContents, contentsLength); - free(fileContents); - return str; - } - - bool loadTextFile(const std::string &fileName, - StringVect &lines) - { - int contentsLength; - char *fileContents = static_cast( - VirtFs::loadFile(fileName, contentsLength)); - - if (!fileContents) - { - logger->log("Couldn't load text file: %s", fileName.c_str()); - return false; - } - - std::istringstream iss(std::string(fileContents, contentsLength)); - std::string line; - - while (getline(iss, line)) - lines.push_back(line); - - free(fileContents); - return true; - } -} // namespace VirtFs diff --git a/src/utils/virtfstools.h b/src/utils/virtfstools.h deleted file mode 100644 index 4f2a77f4c..000000000 --- a/src/utils/virtfstools.h +++ /dev/null @@ -1,54 +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 . - */ - -#ifndef UTILS_VIRTFSTOOLS_H -#define UTILS_VIRTFSTOOLS_H - -#include "enums/simpletypes/append.h" - -#include "utils/stringvector.h" - -#include "localconsts.h" - -namespace VirtFs -{ - void *loadFile(const std::string &restrict fileName, - int &restrict fileSize); - void searchAndAddArchives(const std::string &restrict path, - const std::string &restrict ext, - const Append append); - void searchAndRemoveArchives(const std::string &restrict path, - const std::string &restrict ext); - void getFilesInDir(const std::string &dir, - StringVect &list, - const std::string &ext); - void getFilesWithDir(const std::string &restrict path, - StringVect &restrict list); - void getFiles(const std::string &path, - StringVect &list); - void getDirs(const std::string &path, - StringVect &list); - std::string getPath(const std::string &file); - bool loadTextFile(const std::string &fileName, - StringVect &lines); - std::string loadTextFileString(const std::string &fileName); -} // namespace VirtFs - -#endif // UTILS_VIRTFSTOOLS_H diff --git a/src/utils/virtlist.cpp b/src/utils/virtlist.cpp deleted file mode 100644 index 932afc4df..000000000 --- a/src/utils/virtlist.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#include "utils/virtlist.h" - -#include "debug.h" - -VirtList::VirtList() : - names() -{ -} - -VirtList::~VirtList() -{ -} diff --git a/src/utils/virtlist.h b/src/utils/virtlist.h deleted file mode 100644 index 5b1d10924..000000000 --- a/src/utils/virtlist.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 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 . - */ - -#ifndef UTILS_VIRTLIST_H -#define UTILS_VIRTLIST_H - -#include "utils/stringvector.h" - -#include "localconsts.h" - -struct VirtList final -{ - VirtList(); - - A_DELETE_COPY(VirtList) - - ~VirtList(); - - StringVect names; -}; - -#endif // UTILS_VIRTLIST_H diff --git a/src/utils/xml/libxml.cpp b/src/utils/xml/libxml.cpp index b85e456f4..8b5b34efc 100644 --- a/src/utils/xml/libxml.cpp +++ b/src/utils/xml/libxml.cpp @@ -24,9 +24,10 @@ #include "utils/xml/libxml.h" +#include "fs/virtfstools.h" + #include "utils/checkutils.h" #include "utils/fuzzer.h" -#include "utils/virtfstools.h" #include "utils/stringutils.h" #include "utils/translation/podict.h" diff --git a/src/utils/xml/pugixml.cpp b/src/utils/xml/pugixml.cpp index 955b170f6..47d6b25de 100644 --- a/src/utils/xml/pugixml.cpp +++ b/src/utils/xml/pugixml.cpp @@ -24,10 +24,11 @@ #include "utils/xml/pugixml.h" +#include "fs/virtfstools.h" + #include "utils/checkutils.h" #include "utils/delete2.h" #include "utils/fuzzer.h" -#include "utils/virtfstools.h" #include "utils/stringutils.h" #include "utils/translation/podict.h" diff --git a/src/utils/xml/pugixmlwriter.cpp b/src/utils/xml/pugixmlwriter.cpp index 1681cdfab..2e61800be 100644 --- a/src/utils/xml/pugixmlwriter.cpp +++ b/src/utils/xml/pugixmlwriter.cpp @@ -24,9 +24,10 @@ #include "logger.h" +#include "fs/virtfs.h" + #include "utils/delete2.h" #include "utils/fuzzer.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 3076e9f0b..795cd2fa0 100644 --- a/src/utils/xml_unittest.cc +++ b/src/utils/xml_unittest.cc @@ -24,12 +24,13 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "gui/gui.h" #include "gui/theme.h" #include "utils/delete2.h" #include "utils/env.h" -#include "utils/virtfs.h" #ifdef ENABLE_PUGIXML #include "utils/xmlwriter.h" #endif // ENABLE_PUGIXML diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc index e2bcfb546..b3b9cba81 100644 --- a/src/utils/xmlutils_unittest.cc +++ b/src/utils/xmlutils_unittest.cc @@ -26,8 +26,9 @@ #include "being/actorsprite.h" +#include "fs/virtfs.h" + #include "utils/delete2.h" -#include "utils/virtfs.h" #include "render/sdlgraphics.h" -- cgit v1.2.3-70-g09d2