Refine code style

This commit is contained in:
halx99 2020-08-27 10:19:21 +08:00
parent 6ac06d8571
commit ea1cb45ba3
6 changed files with 16 additions and 16 deletions

View File

@ -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

@ -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

@ -151,7 +151,7 @@ namespace cocos2d { namespace network {
}
}
// open file
_fs.open(_tempFileName, FileStream::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(), FileStream::kModeWrite);
_fsMd5.open(_checksumFileName.c_str(), FileStream::Mode::WRITE);
if (_fsMd5.seek(0, SEEK_END) != sizeof(md5_state_s)) {
md5_init(&_md5State);
}
@ -902,7 +902,7 @@ public:
if (checkState & kCheckSumStateSucceed) // No need download
{
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.bytesReceived = task.progressInfo.totalBytesExpected;
task.progressInfo.totalBytesReceived = task.progressInfo.totalBytesExpected;

View File

@ -37,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 FileStream::kModeReadOnly:
case FileStream::Mode::READ:
handle._fd = posix_open(path.c_str(), O_READ_FLAGS);
break;
case FileStream::kModeWrite:
case FileStream::Mode::WRITE:
handle._fd = posix_open(path.c_str(), O_WRITE_FLAGS);
break;
case FileStream::kModeAppend:
case FileStream::Mode::APPEND:
handle._fd = posix_open(path.c_str(), O_APPEND_FLAGS);
break;
default:
@ -112,7 +112,7 @@ FileStream::~FileStream()
this->close();
}
bool FileStream::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;

View File

@ -42,13 +42,13 @@ public:
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);