From 924816ac8dc5206d3b3f5be6cc67102be13ff09b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Jun 2020 10:59:11 +0200 Subject: [PATCH] - Inlined most of libsmackerdec's FileStream. This should probably be removed altogether and use FileReader directly. --- source/common/utility/files.h | 8 ++ source/games/duke/src/filestream.cpp | 136 ------------------------ source/libsmackerdec/src/FileStream.cpp | 74 ------------- 3 files changed, 8 insertions(+), 210 deletions(-) delete mode 100644 source/games/duke/src/filestream.cpp diff --git a/source/common/utility/files.h b/source/common/utility/files.h index d40587457..f4156c9e0 100644 --- a/source/common/utility/files.h +++ b/source/common/utility/files.h @@ -292,6 +292,14 @@ public: return BigLong(v); } + uint32_t ReadUInt64() + { + uint64_t v = 0; + Read(&v, 8); + // Prove to me that there's a relevant 64 bit Big Endian architecture and I fix this! :P + return v; + } + friend class FileSystem; }; diff --git a/source/games/duke/src/filestream.cpp b/source/games/duke/src/filestream.cpp deleted file mode 100644 index ded1dbaf5..000000000 --- a/source/games/duke/src/filestream.cpp +++ /dev/null @@ -1,136 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010-2020 EDuke32 developers and contributors -Copyright (C) 2020 sirlemonhead -This file is part of Rednukem. -Rednukem is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. -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, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "filestream.h" -#include - -namespace RedNukem { - -bool FileStream::Open(const char *fileName) -{ - file = kopen4loadfrommod(fileName, 0); - if (file == -1) - { - // log error - return false; - } - - return true; -} - -bool FileStream::Is_Open() -{ - return file != -1; -} - -void FileStream::Close() -{ - kclose(file); - file = -1; -} - -int32_t FileStream::ReadBytes(uint8_t *data, uint32_t nBytes) -{ - uint32_t nCount = (uint32_t)kread(file, data, static_cast(nBytes)); - - if (nCount != nBytes) { - return 0; - } - - return (int32_t)nCount; -} - -uint64_t FileStream::ReadUint64LE() -{ - uint64_t value; - kread(file, &value, 8); - return B_LITTLE64(value); -} - -uint64_t FileStream::ReadUint64BE() -{ - uint64_t value; - kread(file, &value, 8); - return B_BIG64(value); -} - -uint32_t FileStream::ReadUint32LE() -{ - uint32_t value; - kread(file, &value, 4); - return B_LITTLE32(value); -} - -uint32_t FileStream::ReadUint32BE() -{ - uint32_t value; - kread(file, &value, 4); - return B_BIG32(value); -} - -uint16_t FileStream::ReadUint16LE() -{ - uint16_t value; - kread(file, &value, 2); - return B_LITTLE16(value); -} - -uint16_t FileStream::ReadUint16BE() -{ - uint16_t value; - kread(file, &value, 2); - return B_BIG16(value); -} - -uint8_t FileStream::ReadByte() -{ - uint8_t value; - kread(file, &value, 1); - return value; -} - -int32_t FileStream::Seek(int32_t offset, SeekDirection direction) -{ - int32_t nStatus = -1; - if (kSeekStart == direction) - { - nStatus = klseek(file, offset, SEEK_SET); - } - else if (kSeekCurrent == direction) - { - nStatus = klseek(file, offset, SEEK_CUR); - } - else if (kSeekEnd == direction) - { - nStatus = klseek(file, offset, SEEK_END); - } - - return nStatus; -} - -int32_t FileStream::Skip(int32_t offset) -{ - return Seek(offset, kSeekCurrent); -} - -int32_t FileStream::GetPosition() -{ - return ktell(file); -} - -} // close namespace RedNukem diff --git a/source/libsmackerdec/src/FileStream.cpp b/source/libsmackerdec/src/FileStream.cpp index 09303b993..454143ff1 100644 --- a/source/libsmackerdec/src/FileStream.cpp +++ b/source/libsmackerdec/src/FileStream.cpp @@ -34,81 +34,7 @@ bool FileStream::Open(const char *fileName) // log error return false; } - return true; } -bool FileStream::Is_Open() -{ - return file.isOpen(); -} - -void FileStream::Close() -{ - file.Close(); -} - -int32_t FileStream::ReadBytes(uint8_t *data, uint32_t nBytes) -{ - uint32_t nCount = (uint32_t)file.Read(data, static_cast(nBytes)); - - if (nCount != nBytes) - { - return 0; - } - - return (int32_t)nCount; -} - -uint32_t FileStream::ReadUint32LE() -{ - return file.ReadInt32(); -} - -uint32_t FileStream::ReadUint32BE() -{ - return file.ReadInt32BE(); -} - -uint16_t FileStream::ReadUint16LE() -{ - return file.ReadInt16(); -} - -uint16_t FileStream::ReadUint16BE() -{ - return file.ReadInt16BE(); -} - -uint8_t FileStream::ReadByte() -{ - return file.ReadInt8(); -} - -int32_t FileStream::Seek(int32_t offset, SeekDirection direction) -{ - int32_t nStatus = -1; - if (kSeekStart == direction) { - nStatus = file.Seek(offset, FileReader::SeekSet); - } - else if (kSeekCurrent == direction) { - nStatus = file.Seek(offset, FileReader::SeekCur); - } - else if (kSeekEnd == direction) { - nStatus = file.Seek(offset, FileReader::SeekEnd); - } - - return nStatus; -} - -int32_t FileStream::Skip(int32_t offset) -{ - return Seek(offset, kSeekCurrent); -} - -int32_t FileStream::GetPosition() -{ - return file.Tell(); -} - } // close namespace SmackerCommon