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 <string>
#include "platform/CCFileStream.h"
namespace cocos2d {
enum class AUDIO_SOURCE_FORMAT : uint16_t

View File

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

View File

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

View File

@ -28,7 +28,6 @@
#pragma once
#include "audio/include/AudioDecoder.h"
#include "platform/PXFileStream.h"
#if !defined(MAKE_FOURCC)
#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;
AUDIO_SOURCE_FORMAT SourceFormat;
uint32_t PcmDataOffset;
cocos2d::PXFileStream Stream;
cocos2d::FileStream Stream;
};

View File

@ -56,28 +56,28 @@ namespace cocos2d {
#if !CC_USE_MPG123
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)
{
return ((PXFileStream*)user_data)->seek(position, SEEK_SET) >= 0 ? 0 : -1;
return ((FileStream*)user_data)->seek(position, SEEK_SET) >= 0 ? 0 : -1;
}
#else
static bool __mp3Inited = false;
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)
{
return ((PXFileStream*)handle)->seek(offset, whence);
return ((FileStream*)handle)->seek(offset, whence);
}
void mpg123_close_r(void* handle) {
((PXFileStream*)handle)->close();
((FileStream*)handle)->close();
}
#endif
bool AudioDecoderMp3::lazyInit()
@ -128,7 +128,7 @@ namespace cocos2d {
#if !CC_USE_MPG123
do
{
if (!_fileStream.open(fullPath))
if (!_fileStream.open(fullPath, FileStream::Mode::READ))
{
ALOGE("Trouble with minimp3(1): %s\n", strerror(errno));
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)
{
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)
{
auto n = ((PXFileStream*)handle)->seek(offset, whence);
auto n = ((FileStream*)handle)->seek(offset, whence);
return n >= 0 ? 0 : -1;
}
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) {
((PXFileStream*)handle)->close();
((FileStream*)handle)->close();
return 0;
}
@ -69,7 +69,7 @@ namespace cocos2d {
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));
return false;

View File

@ -76,7 +76,7 @@ namespace cocos2d {
}
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)
return false;

View File

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

View File

@ -1,5 +1,6 @@
// 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
#include "base/ZipUtils.h"
@ -36,16 +37,16 @@ struct PXIoF {
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) {
case PXFileStream::kModeReadOnly:
case FileStream::Mode::READ:
handle._fd = posix_open(path.c_str(), O_READ_FLAGS);
break;
case PXFileStream::kModeWrite:
case FileStream::Mode::WRITE:
handle._fd = posix_open(path.c_str(), O_WRITE_FLAGS);
break;
case PXFileStream::kModeAppend:
case FileStream::Mode::APPEND:
handle._fd = posix_open(path.c_str(), O_APPEND_FLAGS);
break;
default:
@ -102,16 +103,16 @@ static PXIoF pfs_obb_iof = {
};
#endif
PXFileStream::PXFileStream() : _iof(&pfs_posix_iof)
FileStream::FileStream() : _iof(&pfs_posix_iof)
{
}
PXFileStream::~PXFileStream()
FileStream::~FileStream()
{
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
return pfs_posix_open(path, mode, _handle) != -1;
@ -152,7 +153,7 @@ bool PXFileStream::open(const std::string& path, int mode)
#endif
}
PXFileStream::operator bool() const
FileStream::operator bool() const
{
#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
return _handle._fd != -1;
@ -161,22 +162,22 @@ PXFileStream::operator bool() const
#endif
}
int PXFileStream::close()
int FileStream::close()
{
return _iof->close(_handle);
}
int PXFileStream::seek(long offset, int origin)
int FileStream::seek(long offset, int 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);
}
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);
}

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
#include "platform/CCPlatformConfig.h"
@ -36,18 +37,18 @@ union PXFileHandle {
struct PXIoF;
class CC_DLL PXFileStream {
class CC_DLL FileStream {
public:
PXFileStream();
~PXFileStream();
FileStream();
~FileStream();
enum Mode {
kModeReadOnly,
kModeWrite,
kModeAppend,
enum class Mode {
READ,
WRITE,
APPEND,
};
bool open(const std::string& path, int mode = kModeReadOnly);
bool open(const std::string& path, Mode mode);
int close();
int seek(long offset, int origin);

View File

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