mirror of https://github.com/axmolengine/axmol.git
Refine code style
This commit is contained in:
parent
6ac06d8571
commit
ea1cb45ba3
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ namespace cocos2d { namespace network {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// open file
|
// open file
|
||||||
_fs.open(_tempFileName, FileStream::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(), FileStream::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);
|
||||||
}
|
}
|
||||||
|
@ -902,7 +902,7 @@ public:
|
||||||
if (checkState & kCheckSumStateSucceed) // No need download
|
if (checkState & kCheckSumStateSucceed) // No need download
|
||||||
{
|
{
|
||||||
FileStream 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;
|
||||||
|
|
|
@ -37,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 FileStream::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 FileStream::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 FileStream::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:
|
||||||
|
@ -112,7 +112,7 @@ FileStream::~FileStream()
|
||||||
this->close();
|
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
|
#if CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
|
||||||
return pfs_posix_open(path, mode, _handle) != -1;
|
return pfs_posix_open(path, mode, _handle) != -1;
|
||||||
|
|
|
@ -42,13 +42,13 @@ public:
|
||||||
FileStream();
|
FileStream();
|
||||||
~FileStream();
|
~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);
|
||||||
|
|
Loading…
Reference in New Issue