diff --git a/cocos/audio/src/AudioDecoderMp3.cpp b/cocos/audio/src/AudioDecoderMp3.cpp index c0a3a02c1b..07b20a3390 100644 --- a/cocos/audio/src/AudioDecoderMp3.cpp +++ b/cocos/audio/src/AudioDecoderMp3.cpp @@ -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; diff --git a/cocos/audio/src/AudioDecoderOgg.cpp b/cocos/audio/src/AudioDecoderOgg.cpp index a99d57a552..7581af0ceb 100644 --- a/cocos/audio/src/AudioDecoderOgg.cpp +++ b/cocos/audio/src/AudioDecoderOgg.cpp @@ -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; diff --git a/cocos/audio/src/AudioDecoderWav.cpp b/cocos/audio/src/AudioDecoderWav.cpp index abbeacbf4b..3501adad58 100644 --- a/cocos/audio/src/AudioDecoderWav.cpp +++ b/cocos/audio/src/AudioDecoderWav.cpp @@ -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; diff --git a/cocos/network/CCDownloader-curl.cpp b/cocos/network/CCDownloader-curl.cpp index edd18fabfb..27276f7445 100644 --- a/cocos/network/CCDownloader-curl.cpp +++ b/cocos/network/CCDownloader-curl.cpp @@ -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; diff --git a/cocos/platform/CCFileStream.cpp b/cocos/platform/CCFileStream.cpp index c3a514522a..b4166cf14f 100644 --- a/cocos/platform/CCFileStream.cpp +++ b/cocos/platform/CCFileStream.cpp @@ -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; diff --git a/cocos/platform/CCFileStream.h b/cocos/platform/CCFileStream.h index 204c311f61..7f817eb213 100644 --- a/cocos/platform/CCFileStream.h +++ b/cocos/platform/CCFileStream.h @@ -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);