diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-29 17:16:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-29 17:16:27 +0300 |
commit | d9c0d1c3b2800b0c995393426b65a031203ca2f0 (patch) | |
tree | ae5a5bab4a7a2ef5fbb9229fa5ce153f0178d011 /src/fs/virtfs | |
parent | d1fb04c1d91596706ebf402acfdab24dabad19f4 (diff) | |
download | mv-d9c0d1c3b2800b0c995393426b65a031203ca2f0.tar.gz mv-d9c0d1c3b2800b0c995393426b65a031203ca2f0.tar.bz2 mv-d9c0d1c3b2800b0c995393426b65a031203ca2f0.tar.xz mv-d9c0d1c3b2800b0c995393426b65a031203ca2f0.zip |
Merge virtfileprivate with virtfile.
Because now physfs is gone and nothing to hide from other code.
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r-- | src/fs/virtfs/virtfile.cpp | 25 | ||||
-rw-r--r-- | src/fs/virtfs/virtfile.h | 21 | ||||
-rw-r--r-- | src/fs/virtfs/virtfileprivate.cpp | 55 | ||||
-rw-r--r-- | src/fs/virtfs/virtfileprivate.h | 52 | ||||
-rw-r--r-- | src/fs/virtfs/virtfsdir.cpp | 17 | ||||
-rw-r--r-- | src/fs/virtfs/virtfszip.cpp | 24 |
6 files changed, 56 insertions, 138 deletions
diff --git a/src/fs/virtfs/virtfile.cpp b/src/fs/virtfs/virtfile.cpp index b60db8c99..957392bef 100644 --- a/src/fs/virtfs/virtfile.cpp +++ b/src/fs/virtfs/virtfile.cpp @@ -20,17 +20,32 @@ #include "fs/virtfs/virtfile.h" -#include "fs/virtfs/virtfileprivate.h" - #include "debug.h" -VirtFile::VirtFile(const VirtFsFuncs *restrict const funcs0) : +VirtFile::VirtFile(const VirtFsFuncs *restrict const funcs0, + const uint8_t *restrict const buf, + const size_t sz) : + funcs(funcs0), + mBuf(buf), + mPos(0U), + mSize(sz), + mFd(FILEHDEFAULT) +{ +} + +VirtFile::VirtFile(const VirtFsFuncs *restrict const funcs0, + FILEHTYPE fd) : funcs(funcs0), - mPrivate(nullptr) + mBuf(nullptr), + mPos(0U), + mSize(0U), + mFd(fd) { } VirtFile::~VirtFile() { - delete mPrivate; + if (mFd != FILEHDEFAULT) + FILECLOSE(mFd); + delete [] mBuf; } diff --git a/src/fs/virtfs/virtfile.h b/src/fs/virtfs/virtfile.h index 1cb819a6a..7896c848f 100644 --- a/src/fs/virtfs/virtfile.h +++ b/src/fs/virtfs/virtfile.h @@ -23,19 +23,34 @@ #include "localconsts.h" -struct VirtFilePrivate; +#include "fs/virtfs/fileapi.h" + struct VirtFsFuncs; struct VirtFile final { - explicit VirtFile(const VirtFsFuncs *restrict const funcs0); + VirtFile(const VirtFsFuncs *restrict const funcs0, + const uint8_t *restrict const buf, + const size_t sz); + + VirtFile(const VirtFsFuncs *restrict const funcs0, + FILEHTYPE fd); A_DELETE_COPY(VirtFile) ~VirtFile(); const VirtFsFuncs *funcs; - VirtFilePrivate *mPrivate; + + // zipfs fields + const uint8_t *mBuf; + + // zipfs fields + size_t mPos; + size_t mSize; + + // dirfs fields + FILEHTYPE mFd; }; #endif // UTILS_VIRTFILE_H diff --git a/src/fs/virtfs/virtfileprivate.cpp b/src/fs/virtfs/virtfileprivate.cpp deleted file mode 100644 index 62efdb434..000000000 --- a/src/fs/virtfs/virtfileprivate.cpp +++ /dev/null @@ -1,55 +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/>. - */ - -#include "fs/virtfs/virtfileprivate.h" - -#include "debug.h" - -VirtFilePrivate::VirtFilePrivate() : - mBuf(nullptr), - mPos(0U), - mSize(0U), - mFd(FILEHDEFAULT) -{ -} - -VirtFilePrivate::VirtFilePrivate(FILEHTYPE fd) : - mBuf(nullptr), - mPos(0U), - mSize(0U), - mFd(fd) -{ -} - -VirtFilePrivate::VirtFilePrivate(const uint8_t *restrict const buf, - const size_t sz) : - mBuf(buf), - mPos(0U), - mSize(sz), - mFd(FILEHDEFAULT) -{ -} - -VirtFilePrivate::~VirtFilePrivate() -{ - if (mFd != FILEHDEFAULT) - FILECLOSE(mFd); - delete [] mBuf; -} diff --git a/src/fs/virtfs/virtfileprivate.h b/src/fs/virtfs/virtfileprivate.h deleted file mode 100644 index 735a0209f..000000000 --- a/src/fs/virtfs/virtfileprivate.h +++ /dev/null @@ -1,52 +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 - -#include "localconsts.h" - -#include "fs/virtfs/fileapi.h" - -struct VirtFilePrivate final -{ - VirtFilePrivate(); - - explicit VirtFilePrivate(FILEHTYPE fd); - - VirtFilePrivate(const uint8_t *restrict const buf, - const size_t sz); - - A_DELETE_COPY(VirtFilePrivate) - - ~VirtFilePrivate(); - - // zipfs fields - const uint8_t *mBuf; - - // zipfs fields - size_t mPos; - size_t mSize; - - // dirfs fields - FILEHTYPE mFd; -}; - -#endif // UTILS_VIRTFILEPRIVATE_H diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp index 7521764fd..923d1409d 100644 --- a/src/fs/virtfs/virtfsdir.cpp +++ b/src/fs/virtfs/virtfsdir.cpp @@ -26,7 +26,6 @@ #include "fs/virtfs/virtdirentry.h" #include "fs/virtfs/virtfile.h" -#include "fs/virtfs/virtfileprivate.h" #include "fs/virtfs/virtfsfuncs.h" #include "fs/virtfs/virtlist.h" @@ -73,9 +72,7 @@ namespace VirtFsDir filename.c_str()); return nullptr; } - VirtFile *restrict const file = new VirtFile(&funcs); - file->mPrivate = new VirtFilePrivate(fd); - + VirtFile *restrict const file = new VirtFile(&funcs, fd); return file; } @@ -311,7 +308,7 @@ namespace VirtFsDir { if (file == nullptr) return 0; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::read file not opened."); @@ -335,7 +332,7 @@ namespace VirtFsDir { if (file == nullptr) return 0; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::write file not opened."); @@ -356,7 +353,7 @@ namespace VirtFsDir { if (file == nullptr) return -1; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::fileLength file not opened."); @@ -384,7 +381,7 @@ namespace VirtFsDir if (file == nullptr) return -1; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::tell file not opened."); @@ -404,7 +401,7 @@ namespace VirtFsDir if (file == nullptr) return 0; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::seek file not opened."); @@ -421,7 +418,7 @@ namespace VirtFsDir if (file == nullptr) return -1; - FILEHTYPE fd = file->mPrivate->mFd; + FILEHTYPE fd = file->mFd; if (fd == FILEHDEFAULT) { reportAlways("VirtFsDir::eof file not opened."); diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp index 8490cb981..62ad591ae 100644 --- a/src/fs/virtfs/virtfszip.cpp +++ b/src/fs/virtfs/virtfszip.cpp @@ -21,7 +21,6 @@ #include "fs/virtfs/virtfszip.h" #include "fs/virtfs/virtfile.h" -#include "fs/virtfs/virtfileprivate.h" #include "fs/virtfs/virtfsfuncs.h" #include "fs/virtfs/virtlist.h" #include "fs/virtfs/virtzipentry.h" @@ -223,8 +222,8 @@ namespace VirtFsZip const uint8_t *restrict const buf = Zip::readFile(header); if (buf == nullptr) return nullptr; - VirtFile *restrict const file = new VirtFile(&funcs); - file->mPrivate = new VirtFilePrivate(buf, + VirtFile *restrict const file = new VirtFile(&funcs, + buf, header->uncompressSize); return file; } @@ -270,14 +269,13 @@ namespace VirtFsZip reportAlways("VirtFsZip::read buffer is null"); return 0; } - VirtFilePrivate *restrict const priv = file->mPrivate; - const uint32_t pos = priv->mPos; - const uint32_t sz = priv->mSize; + const uint32_t pos = file->mPos; + const uint32_t sz = file->mSize; // if outside of buffer, return if (pos >= sz) return 0; // pointer to start for buffer ready to read - const uint8_t *restrict const memPtr = priv->mBuf + pos; + const uint8_t *restrict const memPtr = file->mBuf + pos; // left buffer size from pos to end const uint32_t memSize = sz - pos; // number of objects possible to read @@ -290,7 +288,7 @@ namespace VirtFsZip // number of bytes to read from buffer const uint32_t memEnd = memCount * objSize; memcpy(buffer, memPtr, memEnd); - priv->mPos += memEnd; + file->mPos += memEnd; return memCount; } @@ -307,7 +305,7 @@ namespace VirtFsZip if (file == nullptr) return -1; - return file->mPrivate->mSize; + return file->mSize; } int64_t tell(VirtFile *restrict const file) @@ -315,7 +313,7 @@ namespace VirtFsZip if (file == nullptr) return -1; - return file->mPrivate->mPos; + return file->mPos; } int seek(VirtFile *restrict const file, @@ -324,9 +322,9 @@ namespace VirtFsZip if (file == nullptr) return 0; - if (pos > file->mPrivate->mSize) + if (pos > file->mSize) return 0; - file->mPrivate->mPos = pos; + file->mPos = pos; return 1; } @@ -335,7 +333,7 @@ namespace VirtFsZip if (file == nullptr) return -1; - return file->mPrivate->mPos >= file->mPrivate->mSize; + return file->mPos >= file->mSize; } char *loadFile(VirtFsEntry *restrict const entry, |