summaryrefslogtreecommitdiff
path: root/src/fs/physfs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/physfs')
-rw-r--r--src/fs/physfs/virtfileprivate.cpp36
-rw-r--r--src/fs/physfs/virtfileprivate.h45
-rw-r--r--src/fs/physfs/virtfs.cpp221
-rw-r--r--src/fs/physfs/virtfsphys.cpp354
-rw-r--r--src/fs/physfs/virtfsphys.h83
-rw-r--r--src/fs/physfs/virtfsphys_unittest.cc505
6 files changed, 0 insertions, 1244 deletions
diff --git a/src/fs/physfs/virtfileprivate.cpp b/src/fs/physfs/virtfileprivate.cpp
deleted file mode 100644
index 6e6cd7dd6..000000000
--- a/src/fs/physfs/virtfileprivate.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 <http://www.gnu.org/licenses/>.
- */
-
-#ifdef USE_PHYSFS
-#include "fs/physfs/virtfileprivate.h"
-
-#include "debug.h"
-
-VirtFilePrivate::VirtFilePrivate(PHYSFS_file *restrict const file) :
- mFile(file)
-{
-}
-
-VirtFilePrivate::~VirtFilePrivate()
-{
- if (mFile != nullptr)
- PHYSFS_close(mFile);
-}
-#endif // USE_PHYSFS
diff --git a/src/fs/physfs/virtfileprivate.h b/src/fs/physfs/virtfileprivate.h
deleted file mode 100644
index 1067cfda0..000000000
--- a/src/fs/physfs/virtfileprivate.h
+++ /dev/null
@@ -1,45 +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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_VIRTFILEPRIVATE_H
-#define UTILS_VIRTFILEPRIVATE_H
-#ifdef USE_PHYSFS
-
-#include "localconsts.h"
-
-PRAGMA45(GCC diagnostic push)
-PRAGMA45(GCC diagnostic ignored "-Wlong-long")
-#include <physfs.h>
-PRAGMA45(GCC diagnostic pop)
-
-struct VirtFilePrivate final
-{
- explicit VirtFilePrivate(PHYSFS_file *restrict const file);
-
- A_DELETE_COPY(VirtFilePrivate)
-
- ~VirtFilePrivate();
-
- // physfs fields
- PHYSFS_file *mFile;
-};
-
-#endif // USE_PHYSFS
-#endif // UTILS_VIRTFILEPRIVATE_H
diff --git a/src/fs/physfs/virtfs.cpp b/src/fs/physfs/virtfs.cpp
deleted file mode 100644
index c9fd34ba4..000000000
--- a/src/fs/physfs/virtfs.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef USE_PHYSFS
-
-#include "fs/virtfs.h"
-
-#include "fs/physfs/virtfsphys.h"
-#include "fs/virtfile.h"
-#include "fs/virtfsfuncs.h"
-#include "fs/virtlist.h"
-
-#include "debug.h"
-
-const char *dirSeparator = nullptr;
-
-namespace VirtFs
-{
- void init(const std::string &restrict name)
- {
- VirtFsPhys::init(name);
- updateDirSeparator();
- }
-
- void updateDirSeparator()
- {
- dirSeparator = VirtFsPhys::getDirSeparator();
- }
-
- const char *getDirSeparator()
- {
- return dirSeparator;
- }
-
- const char *getBaseDir()
- {
- return VirtFsPhys::getBaseDir();
- }
-
- const char *getUserDir()
- {
- return VirtFsPhys::getUserDir();
- }
-
- bool exists(std::string name)
- {
- return VirtFsPhys::exists(name);
- }
-
- VirtList *enumerateFiles(std::string dirName)
- {
- return VirtFsPhys::enumerateFiles(dirName);
- }
-
- bool isDirectory(std::string name)
- {
- return VirtFsPhys::isDirectory(name);
- }
-
- bool isSymbolicLink(const std::string &restrict name)
- {
- return VirtFsPhys::isSymbolicLink(name);
- }
-
- void freeList(VirtList *restrict const handle)
- {
- delete handle;
- }
-
- VirtFile *openRead(std::string filename)
- {
- return VirtFsPhys::openRead(filename);
- }
-
- VirtFile *openWrite(std::string filename)
- {
- return VirtFsPhys::openWrite(filename);
- }
-
- VirtFile *openAppend(std::string filename)
- {
- return VirtFsPhys::openAppend(filename);
- }
-
- bool setWriteDir(const std::string &restrict newDir)
- {
- return VirtFsPhys::setWriteDir(newDir);
- }
-
- bool mountDir(std::string newDir,
- const Append append)
- {
- return VirtFsPhys::mountDir(newDir, append);
- }
-
- bool mountDirSilent(std::string newDir,
- const Append append)
- {
- return VirtFsPhys::mountDir(newDir, append);
- }
-
- bool unmountDir(std::string oldDir)
- {
- return VirtFsPhys::unmountDir(oldDir);
- }
-
- bool unmountDirSilent(std::string oldDir)
- {
- return VirtFsPhys::unmountDir(oldDir);
- }
-
- bool mountZip(std::string newDir,
- const Append append)
- {
- return VirtFsPhys::mountZip(newDir, append);
- }
-
- bool unmountZip(std::string oldDir)
- {
- return VirtFsPhys::unmountZip(oldDir);
- }
-
- std::string getRealDir(std::string filename)
- {
- return VirtFsPhys::getRealDir(filename);
- }
-
- bool mkdir(const std::string &restrict dirname)
- {
- return VirtFsPhys::mkdir(dirname);
- }
-
- bool remove(const std::string &restrict filename)
- {
- return VirtFsPhys::remove(filename);
- }
-
- bool deinit()
- {
- return VirtFsPhys::deinit();
- }
-
- void permitLinks(const bool val)
- {
- VirtFsPhys::permitLinks(val);
- }
-
- const char *getLastError()
- {
- return VirtFsPhys::getLastError();
- }
-
- int close(VirtFile *restrict const file)
- {
- if (file == nullptr)
- return 0;
- return file->funcs->close(file);
- }
-
- int64_t read(VirtFile *restrict const file,
- void *restrict const buffer,
- const uint32_t objSize,
- const uint32_t objCount)
- {
- return file->funcs->read(file,
- buffer,
- objSize,
- objCount);
- }
-
- int64_t write(VirtFile *restrict const file,
- const void *restrict const buffer,
- const uint32_t objSize,
- const uint32_t objCount)
- {
- return file->funcs->write(file,
- buffer,
- objSize,
- objCount);
- }
-
- int64_t fileLength(VirtFile *restrict const file)
- {
- return file->funcs->fileLength(file);
- }
-
- int64_t tell(VirtFile *restrict const file)
- {
- return file->funcs->tell(file);
- }
-
- int seek(VirtFile *restrict const file,
- const uint64_t pos)
- {
- return file->funcs->seek(file,
- pos);
- }
-
- int eof(VirtFile *restrict const file)
- {
- return file->funcs->eof(file);
- }
-} // namespace VirtFs
-#endif // USE_PHYSFS
diff --git a/src/fs/physfs/virtfsphys.cpp b/src/fs/physfs/virtfsphys.cpp
deleted file mode 100644
index f6d0abf47..000000000
--- a/src/fs/physfs/virtfsphys.cpp
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef USE_PHYSFS
-
-#include "fs/physfs/virtfsphys.h"
-
-#include "fs/virtfile.h"
-#include "fs/virtfsfuncs.h"
-#include "fs/virtlist.h"
-
-#include "fs/physfs/virtfileprivate.h"
-
-#include "utils/checkutils.h"
-
-#include <iostream>
-#include <unistd.h>
-
-#ifdef ANDROID
-#include "fs/paths.h"
-#endif // ANDROID
-
-#include "debug.h"
-
-namespace
-{
- const char *dirSeparator = nullptr;
- VirtFsFuncs funcs;
-} // namespace
-
-namespace VirtFsPhys
-{
-#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: "
- << VirtFsPhys::getLastError() << std::endl;
- _exit(1);
- }
- updateDirSeparator();
- atexit(reinterpret_cast<void(*)()>(PHYSFS_deinit));
- initFuncs(&funcs);
- }
-
- void initFuncs()
- {
- initFuncs(&funcs);
- }
-
- void initFuncs(VirtFsFuncs *restrict const ptr)
- {
- ptr->close = &VirtFsPhys::close;
- ptr->read = &VirtFsPhys::read;
- ptr->write = &VirtFsPhys::write;
- ptr->fileLength = &VirtFsPhys::fileLength;
- ptr->tell = &VirtFsPhys::tell;
- ptr->seek = &VirtFsPhys::seek;
- ptr->eof = &VirtFsPhys::eof;
- }
-
- 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(&funcs);
- 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(&funcs);
- 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(&funcs);
- file->mPrivate = new VirtFilePrivate(handle);
- return file;
- }
-
- bool setWriteDir(const std::string &restrict newDir)
- {
- return PHYSFS_setWriteDir(newDir.c_str());
- }
-
- bool mountDir(const std::string &restrict newDir,
- const Append append)
- {
- logger->log("Add virtual directory: " + newDir);
- if (newDir.find(".zip") != std::string::npos)
- {
- reportAlways("Called mountDir with zip archive");
- return false;
- }
- const int ret = PHYSFS_addToSearchPath(newDir.c_str(),
- append == Append_true ? 1 : 0);
- if (ret == 0)
- {
- logger->log("mountDir error: %s",
- VirtFsPhys::getLastError());
- }
- return ret;
- }
-
- bool unmountDir(const std::string &restrict oldDir)
- {
- logger->log("Remove virtual directory: " + oldDir);
- if (oldDir.find(".zip") != std::string::npos)
- {
- reportAlways("Called unmountDir with zip archive");
- return false;
- }
- const int ret = PHYSFS_removeFromSearchPath(oldDir.c_str());
- if (ret == 0)
- {
- logger->log("unmountDir error: %s",
- VirtFsPhys::getLastError());
- }
- return ret;
- }
-
- bool mountZip(const std::string &restrict newDir,
- const Append append)
- {
- logger->log("Add virtual zip: " + newDir);
- if (newDir.find(".zip") == std::string::npos)
- {
- reportAlways("Called mountZip without zip archive");
- return false;
- }
- const int ret = PHYSFS_addToSearchPath(newDir.c_str(),
- append == Append_true ? 1 : 0);
- if (ret == 0)
- {
- logger->log("mountZip error: %s",
- VirtFsPhys::getLastError());
- }
- return ret;
- }
-
- bool unmountZip(const std::string &restrict oldDir)
- {
- logger->log("Remove virtual zip: " + oldDir);
- if (oldDir.find(".zip") == std::string::npos)
- {
- reportAlways("Called unmountZip without zip archive");
- return false;
- }
- const int ret = PHYSFS_removeFromSearchPath(oldDir.c_str());
- if (ret == 0)
- {
- logger->log("unmountZip error: %s",
- VirtFsPhys::getLastError());
- }
- return ret;
- }
-
- 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",
- VirtFsPhys::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 VirtFsPhys
-#endif // USE_PHYSFS
diff --git a/src/fs/physfs/virtfsphys.h b/src/fs/physfs/virtfsphys.h
deleted file mode 100644
index 1daebfb4f..000000000
--- a/src/fs/physfs/virtfsphys.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_VIRTFSPHYS_H
-#define UTILS_VIRTFSPHYS_H
-
-#ifdef USE_PHYSFS
-
-#include "enums/simpletypes/append.h"
-
-#include "localconsts.h"
-
-#include <string>
-
-struct VirtFile;
-struct VirtFsFuncs;
-struct VirtList;
-
-namespace VirtFsPhys
-{
- void init(const std::string &restrict name);
- void initFuncs(VirtFsFuncs *restrict const ptr);
- void initFuncs();
- 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 mountDir(const std::string &restrict newDir,
- const Append append);
- bool unmountDir(const std::string &restrict oldDir);
- bool mountZip(const std::string &restrict newDir,
- const Append append);
- bool unmountZip(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 VirtFsPhys
-
-#endif // USE_PHYSFS
-#endif // UTILS_VIRTFSPHYS_H
diff --git a/src/fs/physfs/virtfsphys_unittest.cc b/src/fs/physfs/virtfsphys_unittest.cc
deleted file mode 100644
index 636d67a91..000000000
--- a/src/fs/physfs/virtfsphys_unittest.cc
+++ /dev/null
@@ -1,505 +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 <http://www.gnu.org/licenses/>.
- */
-
-#ifdef USE_PHYSFS
-#include "catch.hpp"
-
-#include "fs/paths.h"
-#include "fs/virtfs.h"
-#include "fs/virtlist.h"
-
-#include "fs/physfs/virtfsphys.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-TEST_CASE("VirtFsPhys dirSeparator")
-{
- VirtFsPhys::initFuncs();
- REQUIRE(VirtFs::getDirSeparator() != nullptr);
- REQUIRE(VirtFsPhys::getDirSeparator() ==
- std::string(VirtFs::getDirSeparator()));
- VirtFsPhys::updateDirSeparator();
- REQUIRE(VirtFs::getDirSeparator() != nullptr);
- REQUIRE(VirtFsPhys::getDirSeparator() ==
- std::string(VirtFs::getDirSeparator()));
-}
-
-TEST_CASE("VirtFsPhys getBaseDir")
-{
- VirtFsPhys::initFuncs();
- REQUIRE(VirtFsPhys::getBaseDir() != nullptr);
-}
-
-TEST_CASE("VirtFsPhys getUserDir")
-{
- VirtFsPhys::initFuncs();
- REQUIRE(VirtFsPhys::getUserDir() != nullptr);
- REQUIRE(VirtFsPhys::getUserDir() == getHomePath());
-}
-
-TEST_CASE("VirtFsPhys exists")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- VirtFsPhys::mountDir("data", Append_false);
- VirtFsPhys::mountDir("../data", Append_false);
-
- REQUIRE(VirtFsPhys::exists("test/units.xml") == true);
- REQUIRE(VirtFsPhys::exists("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::exists("units.xml") == false);
-
- VirtFsPhys::mountDir("data/test", Append_false);
- VirtFsPhys::mountDir("../data/test", Append_false);
-
- REQUIRE(VirtFsPhys::exists("test/units.xml") == true);
- REQUIRE(VirtFsPhys::exists("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::exists("units.xml") == true);
-
- VirtFsPhys::unmountDir("data/test");
- VirtFsPhys::unmountDir("../data/test");
-
- REQUIRE(VirtFsPhys::exists("test/units.xml") == true);
- REQUIRE(VirtFsPhys::exists("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::exists("units.xml") == false);
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys exists2")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- VirtFsPhys::mountZip("data/test/test2.zip", Append_false);
- VirtFsPhys::mountZip("../data/test/test2.zip", Append_false);
-
- REQUIRE(VirtFsPhys::exists("test/units.xml") == false);
- REQUIRE(VirtFsPhys::exists("test.txt") == true);
- REQUIRE(VirtFsPhys::exists("units123.xml") == false);
- REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::exists("units.xml") == true);
-
- VirtFsPhys::unmountZip("data/test/test2.zip");
- VirtFsPhys::unmountZip("../data/test/test2.zip");
- 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("VirtFsPhys enumerateFiles1")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger;
-
- VirtFsPhys::mountDir("data", Append_false);
- VirtFsPhys::mountDir("../data", Append_false);
-
- VirtList *list = nullptr;
-
- const int cnt1 = VirtFsPhys::exists("test/test2.txt") ? 28 : 27;
- const int cnt2 = 28;
-
- VirtFsPhys::permitLinks(false);
- list = VirtFsPhys::enumerateFiles("test");
- removeTemp(list->names);
- const size_t sz = list->names.size();
- REQUIRE(sz == cnt1);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::permitLinks(true);
- list = VirtFsPhys::enumerateFiles("test");
- removeTemp(list->names);
- REQUIRE(list->names.size() == cnt2);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::permitLinks(false);
- list = VirtFsPhys::enumerateFiles("test");
- removeTemp(list->names);
- REQUIRE(list->names.size() == cnt1);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys enumerateFiles2")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger;
-
- VirtFsPhys::mountDir("data/test/dir1",
- Append_false);
- VirtFsPhys::mountDir("../data/test/dir1",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsPhys::enumerateFiles("/");
- REQUIRE(list->names.size() == 5);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::unmountDir("data/test/dir1");
- VirtFsPhys::unmountDir("../data/test/dir1");
- delete2(logger);
-}
-
-static bool inList(VirtList *list,
- const std::string &name)
-{
- FOR_EACH (StringVectCIter, it, list->names)
- {
- if (*it == name)
- return true;
- }
- return false;
-}
-
-TEST_CASE("VirtFsPhys enumerateFiles3")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger;
-
- VirtFsPhys::mountZip("data/test/test.zip",
- Append_false);
- VirtFsPhys::mountZip("../data/test/test.zip",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsPhys::enumerateFiles("/");
- REQUIRE(inList(list, "units.xml") == false);
- REQUIRE(inList(list, "test.txt") == false);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::unmountZip("data/test/test.zip");
- VirtFsPhys::unmountZip("../data/test/test.zip");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys enumerateFiles4")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger;
-
- VirtFsPhys::mountZip("data/test/test2.zip",
- Append_false);
- VirtFsPhys::mountZip("../data/test/test2.zip",
- Append_false);
-
- VirtList *list = nullptr;
-
- list = VirtFsPhys::enumerateFiles("/");
- REQUIRE(inList(list, "units.xml") == true);
- REQUIRE(inList(list, "test.txt") == true);
- VirtFsPhys::freeList(list);
-
- VirtFsPhys::unmountZip("data/test/test2.zip");
- VirtFsPhys::unmountZip("../data/test/test2.zip");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys isDirectory")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- VirtFsPhys::mountDir("data", Append_false);
- VirtFsPhys::mountDir("../data", Append_false);
-
- REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/units.xml/") == false);
- REQUIRE(VirtFsPhys::isDirectory("test//units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test//units123.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("tesQ//units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test") == true);
- REQUIRE(VirtFsPhys::isDirectory("test/") == true);
- REQUIRE(VirtFsPhys::isDirectory("test//") == true);
- REQUIRE(VirtFsPhys::isDirectory("test/dir1") == true);
- REQUIRE(VirtFsPhys::isDirectory("test//dir1") == true);
- REQUIRE(VirtFsPhys::isDirectory("test//dir1/") == true);
- REQUIRE(VirtFsPhys::isDirectory("test//dir1//") == true);
- REQUIRE(VirtFsPhys::isDirectory("test/dir1/") == true);
- REQUIRE(VirtFsPhys::isDirectory("test/dir1//") == true);
- REQUIRE(VirtFsPhys::isDirectory("testQ") == false);
- REQUIRE(VirtFsPhys::isDirectory("testQ/") == false);
- REQUIRE(VirtFsPhys::isDirectory("testQ//") == false);
-
- VirtFsPhys::mountDir("data/test", Append_false);
- VirtFsPhys::mountDir("../data/test", Append_false);
-
- REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/units.xml/") == false);
- REQUIRE(VirtFsPhys::isDirectory("test//units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test") == true);
- REQUIRE(VirtFsPhys::isDirectory("testQ") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/dir1") == true);
-
- VirtFsPhys::unmountDir("data/test");
- VirtFsPhys::unmountDir("../data/test");
-
- REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/units123.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("tesQ/units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("units.xml") == false);
- REQUIRE(VirtFsPhys::isDirectory("units.xml/") == false);
- REQUIRE(VirtFsPhys::isDirectory("test") == true);
- REQUIRE(VirtFsPhys::isDirectory("test/") == true);
- REQUIRE(VirtFsPhys::isDirectory("testQ") == false);
- REQUIRE(VirtFsPhys::isDirectory("test/dir1") == true);
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys openRead")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- VirtFsPhys::mountDir("data", Append_false);
- VirtFsPhys::mountDir("../data", Append_false);
-
- VirtFile *file = nullptr;
-
- file = VirtFsPhys::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsPhys::close(file);
- file = VirtFsPhys::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("units.xml");
- REQUIRE(file == nullptr);
-// file = VirtFsPhys::openRead("test");
-// REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsPhys::mountDir("data/test", Append_false);
- VirtFsPhys::mountDir("../data/test", Append_false);
-
- file = VirtFsPhys::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsPhys::close(file);
- file = VirtFsPhys::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("units.xml");
- REQUIRE(file != nullptr);
- VirtFsPhys::close(file);
-// file = VirtFsPhys::openRead("test");
-// REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsPhys::unmountDir("data/test");
- VirtFsPhys::unmountDir("../data/test");
-
- file = VirtFsPhys::openRead("test/units.xml");
- REQUIRE(file != nullptr);
- VirtFsPhys::close(file);
- file = VirtFsPhys::openRead("test/units123.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("tesQ/units.xml");
- REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("units.xml");
- REQUIRE(file == nullptr);
-// file = VirtFsPhys::openRead("test");
-// REQUIRE(file == nullptr);
- file = VirtFsPhys::openRead("testQ");
- REQUIRE(file == nullptr);
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys mountZip")
-{
- // +++ need implement
-}
-
-TEST_CASE("VirtFsPhys unmountZip")
-{
- // +++ need implement
-}
-
-TEST_CASE("VirtFsPhys getRealDir")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- REQUIRE(VirtFsPhys::getRealDir(".") == "");
- REQUIRE(VirtFsPhys::getRealDir("..") == "");
- const bool dir1 = VirtFsPhys::mountDir("data", Append_false);
- REQUIRE((dir1 || VirtFsPhys::mountDir(
- "../data", Append_false)) == true);
- if (dir1 == true)
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "data");
- }
- else
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "../data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "../data");
- }
- REQUIRE(VirtFsPhys::getRealDir("zzz") == "");
-
- VirtFsPhys::mountDir("data/test", Append_false);
- VirtFsPhys::mountDir("../data/test", Append_false);
- if (dir1 == true)
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "data");
- REQUIRE(VirtFsPhys::getRealDir("test.txt") ==
- "data/test");
- }
- else
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "../data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "../data");
- REQUIRE(VirtFsPhys::getRealDir("test.txt") ==
- "../data/test");
- }
- REQUIRE(VirtFsPhys::getRealDir("zzz") == "");
-
- if (dir1 == true)
- {
- VirtFsPhys::mountZip("data/test/test.zip", Append_false);
- REQUIRE(VirtFsPhys::getRealDir("dir/brimmedhat.png") ==
- "data/test/test.zip");
- REQUIRE(VirtFsPhys::getRealDir("hide.png") == "data/test");
- }
- else
- {
- VirtFsPhys::mountZip("../data/test/test.zip", Append_false);
- REQUIRE(VirtFsPhys::getRealDir("dir/brimmedhat.png") ==
- "../data/test/test.zip");
- REQUIRE(VirtFsPhys::getRealDir("hide.png") == "../data/test");
- }
-
- VirtFsPhys::unmountDir("data/test");
- VirtFsPhys::unmountDir("../data/test");
-
- if (dir1 == true)
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "data");
- REQUIRE(VirtFsPhys::getRealDir("dir/hide.png") ==
- "data/test/test.zip");
- }
- else
- {
- REQUIRE(VirtFsPhys::getRealDir("test") == "../data");
- REQUIRE(VirtFsPhys::getRealDir("test/test.txt") ==
- "../data");
- REQUIRE(VirtFsPhys::getRealDir("dir/hide.png") ==
- "../data/test/test.zip");
- }
- REQUIRE(VirtFsPhys::exists("dir/hide.png"));
- REQUIRE(VirtFsPhys::getRealDir("zzz") == "");
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- VirtFsPhys::unmountZip("data/test/test.zip");
- VirtFsPhys::unmountZip("../data/test/test.zip");
- delete2(logger);
-}
-
-TEST_CASE("VirtFsPhys read")
-{
- VirtFsPhys::initFuncs();
- logger = new Logger();
- VirtFsPhys::mountDir("data", Append_false);
- VirtFsPhys::mountDir("../data", Append_false);
-
- VirtFile *file = VirtFsPhys::openRead("test/test.txt");
- REQUIRE(file != nullptr);
- REQUIRE(VirtFsPhys::fileLength(file) == 23);
- const int fileSize = VirtFsPhys::fileLength(file);
-
- void *restrict buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsPhys::read(file, buffer, 1, fileSize) == fileSize);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 1\ntest line 2") == 0);
- REQUIRE(VirtFsPhys::tell(file) == fileSize);
- REQUIRE(VirtFsPhys::eof(file) == true);
-
- free(buffer);
- buffer = calloc(fileSize + 1, 1);
- REQUIRE(VirtFsPhys::seek(file, 12) != 0);
- REQUIRE(VirtFsPhys::eof(file) == false);
- REQUIRE(VirtFsPhys::tell(file) == 12);
- REQUIRE(VirtFsPhys::read(file, buffer, 1, 11) == 11);
- REQUIRE(strcmp(static_cast<char*>(buffer),
- "test line 2") == 0);
- REQUIRE(VirtFsPhys::eof(file) == true);
-
- VirtFsPhys::close(file);
- free(buffer);
-
- VirtFsPhys::unmountDir("data");
- VirtFsPhys::unmountDir("../data");
- delete2(logger);
-}
-#endif // USE_PHYSFS