Merge pull request #174 from halx99/rename-filestream

Rename PXFileStream to CCFileStream
This commit is contained in:
HALX99 2020-08-26 20:33:21 -07:00 committed by GitHub
commit f85c34acd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 50 deletions

View File

@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include "platform/CCFileStream.h"
namespace cocos2d { namespace cocos2d {
enum class AUDIO_SOURCE_FORMAT : uint16_t enum class AUDIO_SOURCE_FORMAT : uint16_t

View File

@ -26,7 +26,6 @@
#pragma once #pragma once
#include "audio/include/AudioDecoder.h" #include "audio/include/AudioDecoder.h"
#include "platform/PXFileStream.h"
#if !defined(CC_USE_MPG123) #if !defined(CC_USE_MPG123)
#define CC_USE_MPG123 0 #define CC_USE_MPG123 0
@ -81,7 +80,7 @@ protected:
static bool lazyInit(); static bool lazyInit();
static void destroy(); static void destroy();
PXFileStream _fileStream; FileStream _fileStream;
mp3dec_handle_t _handle; mp3dec_handle_t _handle;
friend class AudioDecoderManager; friend class AudioDecoderManager;

View File

@ -29,8 +29,6 @@
#include "vorbis/vorbisfile.h" #include "vorbis/vorbisfile.h"
#include "platform/PXFileStream.h"
namespace cocos2d { namespace cocos2d {
/** /**
@ -70,7 +68,7 @@ protected:
AudioDecoderOgg(); AudioDecoderOgg();
~AudioDecoderOgg(); ~AudioDecoderOgg();
PXFileStream _fileStream; FileStream _fileStream;
OggVorbis_File _vf; OggVorbis_File _vf;
friend class AudioDecoderManager; friend class AudioDecoderManager;

View File

@ -28,7 +28,6 @@
#pragma once #pragma once
#include "audio/include/AudioDecoder.h" #include "audio/include/AudioDecoder.h"
#include "platform/PXFileStream.h"
#if !defined(MAKE_FOURCC) #if !defined(MAKE_FOURCC)
#define MAKE_FOURCC(a,b,c,d) ((uint32_t)((a) | ((b) << 8) | ((c) << 16) | (((uint32_t)(d)) << 24))) #define MAKE_FOURCC(a,b,c,d) ((uint32_t)((a) | ((b) << 8) | ((c) << 16) | (((uint32_t)(d)) << 24)))
@ -107,7 +106,7 @@ struct WAV_FILE
WAV_FILE_HEADER FileHeader; WAV_FILE_HEADER FileHeader;
AUDIO_SOURCE_FORMAT SourceFormat; AUDIO_SOURCE_FORMAT SourceFormat;
uint32_t PcmDataOffset; uint32_t PcmDataOffset;
cocos2d::PXFileStream Stream; cocos2d::FileStream Stream;
}; };

View File

@ -56,28 +56,28 @@ namespace cocos2d {
#if !CC_USE_MPG123 #if !CC_USE_MPG123
static size_t minimp3_read_r(void* buf, size_t size, void* user_data) static size_t minimp3_read_r(void* buf, size_t size, void* user_data)
{ {
return ((PXFileStream*)user_data)->read(buf, size); return ((FileStream*)user_data)->read(buf, size);
} }
static int minimp3_seek_r(uint64_t position, void* user_data) static int minimp3_seek_r(uint64_t position, void* user_data)
{ {
return ((PXFileStream*)user_data)->seek(position, SEEK_SET) >= 0 ? 0 : -1; return ((FileStream*)user_data)->seek(position, SEEK_SET) >= 0 ? 0 : -1;
} }
#else #else
static bool __mp3Inited = false; static bool __mp3Inited = false;
static ssize_t mpg123_read_r(void * handle, void * buffer, size_t count) static ssize_t mpg123_read_r(void * handle, void * buffer, size_t count)
{ {
return ((PXFileStream*)handle)->read(buffer, count); return ((FileStream*)handle)->read(buffer, count);
} }
static off_t mpg123_lseek_r(void * handle, off_t offset, int whence) static off_t mpg123_lseek_r(void * handle, off_t offset, int whence)
{ {
return ((PXFileStream*)handle)->seek(offset, whence); return ((FileStream*)handle)->seek(offset, whence);
} }
void mpg123_close_r(void* handle) { void mpg123_close_r(void* handle) {
((PXFileStream*)handle)->close(); ((FileStream*)handle)->close();
} }
#endif #endif
bool AudioDecoderMp3::lazyInit() bool AudioDecoderMp3::lazyInit()
@ -128,7 +128,7 @@ namespace cocos2d {
#if !CC_USE_MPG123 #if !CC_USE_MPG123
do do
{ {
if (!_fileStream.open(fullPath)) if (!_fileStream.open(fullPath, FileStream::Mode::READ))
{ {
ALOGE("Trouble with minimp3(1): %s\n", strerror(errno)); ALOGE("Trouble with minimp3(1): %s\n", strerror(errno));
break; break;

View File

@ -39,22 +39,22 @@ namespace cocos2d {
static size_t ov_fread_r(void* buffer, size_t element_size, size_t element_count, void* handle) static size_t ov_fread_r(void* buffer, size_t element_size, size_t element_count, void* handle)
{ {
return ((PXFileStream*)handle)->read(buffer, static_cast<uint32_t>(element_size * element_count)); return ((FileStream*)handle)->read(buffer, static_cast<uint32_t>(element_size * element_count));
} }
static int ov_fseek_r(void * handle, ogg_int64_t offset, int whence) static int ov_fseek_r(void * handle, ogg_int64_t offset, int whence)
{ {
auto n = ((PXFileStream*)handle)->seek(offset, whence); auto n = ((FileStream*)handle)->seek(offset, whence);
return n >= 0 ? 0 : -1; return n >= 0 ? 0 : -1;
} }
static long ov_ftell_r(void * handle) static long ov_ftell_r(void * handle)
{ {
return ((PXFileStream*)handle)->seek(0, SEEK_CUR); return ((FileStream*)handle)->seek(0, SEEK_CUR);
} }
static int ov_fclose_r(void* handle) { static int ov_fclose_r(void* handle) {
((PXFileStream*)handle)->close(); ((FileStream*)handle)->close();
return 0; return 0;
} }
@ -69,7 +69,7 @@ namespace cocos2d {
bool AudioDecoderOgg::open(const std::string& fullPath) bool AudioDecoderOgg::open(const std::string& fullPath)
{ {
if (!_fileStream.open(fullPath)) if (!_fileStream.open(fullPath, FileStream::Mode::READ))
{ {
ALOGE("Trouble with ogg(1): %s\n", strerror(errno)); ALOGE("Trouble with ogg(1): %s\n", strerror(errno));
return false; return false;

View File

@ -76,7 +76,7 @@ namespace cocos2d {
} }
static bool wav_open(const std::string& fullPath, WAV_FILE* wavf) static bool wav_open(const std::string& fullPath, WAV_FILE* wavf)
{ {
bool succeed = wavf->Stream.open(fullPath); bool succeed = wavf->Stream.open(fullPath, FileStream::Mode::READ);
if (!succeed) if (!succeed)
return false; return false;

View File

@ -35,7 +35,7 @@
#include "base/CCScheduler.h" #include "base/CCScheduler.h"
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"
#include "network/CCDownloader.h" #include "network/CCDownloader.h"
#include "platform/PXFileStream.h" #include "platform/CCFileStream.h"
#include "md5/md5.h" #include "md5/md5.h"
#include "yasio/xxsocket.hpp" #include "yasio/xxsocket.hpp"
@ -151,7 +151,7 @@ namespace cocos2d { namespace network {
} }
} }
// open file // open file
_fs.open(_tempFileName, PXFileStream::kModeAppend); _fs.open(_tempFileName, FileStream::Mode::APPEND);
if (!_fs) if (!_fs)
{ {
_errCode = DownloadTask::ERROR_OPEN_FILE_FAILED; _errCode = DownloadTask::ERROR_OPEN_FILE_FAILED;
@ -163,7 +163,7 @@ namespace cocos2d { namespace network {
// init md5 state // init md5 state
_checksumFileName = filename + ".chksum"; _checksumFileName = filename + ".chksum";
_fsMd5.open(_checksumFileName.c_str(), PXFileStream::kModeWrite); _fsMd5.open(_checksumFileName.c_str(), FileStream::Mode::WRITE);
if (_fsMd5.seek(0, SEEK_END) != sizeof(md5_state_s)) { if (_fsMd5.seek(0, SEEK_END) != sizeof(md5_state_s)) {
md5_init(&_md5State); md5_init(&_md5State);
} }
@ -305,10 +305,10 @@ namespace cocos2d { namespace network {
string _tempFileName; string _tempFileName;
std::string _checksumFileName; std::string _checksumFileName;
vector<unsigned char> _buf; vector<unsigned char> _buf;
PXFileStream _fs; FileStream _fs;
// calculate md5 in downloading time support // calculate md5 in downloading time support
PXFileStream _fsMd5; // store md5 state realtime FileStream _fsMd5; // store md5 state realtime
md5_state_s _md5State; md5_state_s _md5State;
@ -901,8 +901,8 @@ public:
if (checkState & kCheckSumStateSucceed) // No need download if (checkState & kCheckSumStateSucceed) // No need download
{ {
PXFileStream fsOrigin; FileStream fsOrigin;
if (fsOrigin.open(coTask._fileName)) { if (fsOrigin.open(coTask._fileName, FileStream::Mode::READ)) {
task.progressInfo.totalBytesExpected = fsOrigin.seek(0, SEEK_END); task.progressInfo.totalBytesExpected = fsOrigin.seek(0, SEEK_END);
task.progressInfo.bytesReceived = task.progressInfo.totalBytesExpected; task.progressInfo.bytesReceived = task.progressInfo.totalBytesExpected;
task.progressInfo.totalBytesReceived = task.progressInfo.totalBytesExpected; task.progressInfo.totalBytesReceived = task.progressInfo.totalBytesExpected;

View File

@ -1,5 +1,6 @@
// Copyright (c) 2018-2019 HALX99. // Copyright (c) 2018-2019 HALX99.
#include "platform/PXFileStream.h" // Copyright (c) 2020 c4games.com
#include "platform/CCFileStream.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "base/ZipUtils.h" #include "base/ZipUtils.h"
@ -36,16 +37,16 @@ struct PXIoF {
int(*close)(PXFileHandle& handle); int(*close)(PXFileHandle& handle);
}; };
static int pfs_posix_open(const std::string& path, int mode, PXFileHandle& handle) static int pfs_posix_open(const std::string& path, FileStream::Mode mode, PXFileHandle& handle)
{ {
switch (mode) { switch (mode) {
case PXFileStream::kModeReadOnly: case FileStream::Mode::READ:
handle._fd = posix_open(path.c_str(), O_READ_FLAGS); handle._fd = posix_open(path.c_str(), O_READ_FLAGS);
break; break;
case PXFileStream::kModeWrite: case FileStream::Mode::WRITE:
handle._fd = posix_open(path.c_str(), O_WRITE_FLAGS); handle._fd = posix_open(path.c_str(), O_WRITE_FLAGS);
break; break;
case PXFileStream::kModeAppend: case FileStream::Mode::APPEND:
handle._fd = posix_open(path.c_str(), O_APPEND_FLAGS); handle._fd = posix_open(path.c_str(), O_APPEND_FLAGS);
break; break;
default: default:
@ -102,16 +103,16 @@ static PXIoF pfs_obb_iof = {
}; };
#endif #endif
PXFileStream::PXFileStream() : _iof(&pfs_posix_iof) FileStream::FileStream() : _iof(&pfs_posix_iof)
{ {
} }
PXFileStream::~PXFileStream() FileStream::~FileStream()
{ {
this->close(); this->close();
} }
bool PXFileStream::open(const std::string& path, int mode) bool FileStream::open(const std::string& path, FileStream::Mode mode)
{ {
#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
return pfs_posix_open(path, mode, _handle) != -1; return pfs_posix_open(path, mode, _handle) != -1;
@ -152,7 +153,7 @@ bool PXFileStream::open(const std::string& path, int mode)
#endif #endif
} }
PXFileStream::operator bool() const FileStream::operator bool() const
{ {
#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID #if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
return _handle._fd != -1; return _handle._fd != -1;
@ -161,22 +162,22 @@ PXFileStream::operator bool() const
#endif #endif
} }
int PXFileStream::close() int FileStream::close()
{ {
return _iof->close(_handle); return _iof->close(_handle);
} }
int PXFileStream::seek(long offset, int origin) int FileStream::seek(long offset, int origin)
{ {
return _iof->seek(_handle, offset, origin); return _iof->seek(_handle, offset, origin);
} }
int PXFileStream::read(void* buf, unsigned int size) int FileStream::read(void* buf, unsigned int size)
{ {
return _iof->read(_handle, buf, size); return _iof->read(_handle, buf, size);
} }
int PXFileStream::write(const void* buf, unsigned int size) int FileStream::write(const void* buf, unsigned int size)
{ {
return posix_write(_handle._fd, buf, size); return posix_write(_handle._fd, buf, size);
} }

View File

@ -1,4 +1,5 @@
// Copyright (c) 2018-2019 HALX99, TODO: may rename this file to PXFileStream // Copyright (c) 2018-2019 HALX99
// Copyright (c) 2020 c4games.com
#pragma once #pragma once
#include "platform/CCPlatformConfig.h" #include "platform/CCPlatformConfig.h"
@ -36,18 +37,18 @@ union PXFileHandle {
struct PXIoF; struct PXIoF;
class CC_DLL PXFileStream { class CC_DLL FileStream {
public: public:
PXFileStream(); FileStream();
~PXFileStream(); ~FileStream();
enum Mode { enum class Mode {
kModeReadOnly, READ,
kModeWrite, WRITE,
kModeAppend, APPEND,
}; };
bool open(const std::string& path, int mode = kModeReadOnly); bool open(const std::string& path, Mode mode);
int close(); int close();
int seek(long offset, int origin); int seek(long offset, int origin);

View File

@ -144,7 +144,7 @@ set(COCOS_PLATFORM_HEADER
platform/CCPlatformMacros.h platform/CCPlatformMacros.h
platform/CCSAXParser.h platform/CCSAXParser.h
platform/CCStdC.h platform/CCStdC.h
platform/PXFileStream.h platform/CCFileStream.h
) )
set(COCOS_PLATFORM_SRC set(COCOS_PLATFORM_SRC
@ -153,5 +153,5 @@ set(COCOS_PLATFORM_SRC
platform/CCGLView.cpp platform/CCGLView.cpp
platform/CCFileUtils.cpp platform/CCFileUtils.cpp
platform/CCImage.cpp platform/CCImage.cpp
platform/PXFileStream.cpp platform/CCFileStream.cpp
) )