diff --git a/cocos/base/CCUserDefault.cpp b/cocos/base/CCUserDefault.cpp index 86afaa81c8..3561bc54e4 100644 --- a/cocos/base/CCUserDefault.cpp +++ b/cocos/base/CCUserDefault.cpp @@ -51,29 +51,7 @@ THE SOFTWARE. #include "yasio/obstream.hpp" #include "yasio/detail/sz.hpp" -#if defined(_WIN32) -#define O_READ_FLAGS O_BINARY | O_RDONLY, S_IREAD -#define O_WRITE_FLAGS O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD -#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD -#define posix_open ::_open -#define posix_close ::_close -#define posix_lseek ::_lseek -#define posix_read ::_read -#define posix_write ::_write -#define posix_fd2fh(fd) reinterpret_cast(_get_osfhandle(fd)) -#define posix_fsetsize(fd, size) ::_chsize(fd, size) -#else -#define O_READ_FLAGS O_RDONLY, S_IRUSR -#define O_WRITE_FLAGS O_CREAT | O_RDWR, S_IRWXU -#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR, S_IRWXU -#define posix_open ::open -#define posix_close ::close -#define posix_lseek ::lseek -#define posix_read ::read -#define posix_write ::write -#define posix_fd2fh(fd) (fd) -#define posix_fsetsize(fd, size) ::ftruncate(fd, size), ::lseek(fd, 0, SEEK_SET) -#endif +#include "CCFileStream.h" #define USER_DEFAULT_PLAIN_MODE 0 @@ -168,7 +146,7 @@ bool UserDefault::getBoolForKey(const char* pKey, bool defaultValue) { auto it = this->_values.find(pKey); if (it != this->_values.end()) - return it->second == "1"; + return it->second == "true"; return defaultValue; } @@ -381,7 +359,7 @@ void UserDefault::init() #if !USER_DEFAULT_PLAIN_MODE // construct file mapping - _fd = posix_open(_filePath.c_str(), O_WRITE_FLAGS); + _fd = posix_open(_filePath.c_str(), O_OVERLAP_FLAGS); if (_fd == -1) { log("[Warnning] UserDefault::init open storage file '%s' failed!", _filePath.c_str()); return; diff --git a/cocos/platform/CCFileStream.cpp b/cocos/platform/CCFileStream.cpp index 627617cbdd..d3f06a5dff 100644 --- a/cocos/platform/CCFileStream.cpp +++ b/cocos/platform/CCFileStream.cpp @@ -9,26 +9,6 @@ #include #include -#if defined(_WIN32) -#define O_READ_FLAGS O_BINARY | O_RDONLY, S_IREAD -#define O_WRITE_FLAGS O_CREAT | O_RDWR | O_BINARY | O_TRUNC, S_IWRITE | S_IREAD -#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD -#define posix_open ::_open -#define posix_close ::_close -#define posix_lseek ::_lseek -#define posix_read ::_read -#define posix_write ::_write -#else -#define O_READ_FLAGS O_RDONLY, S_IRUSR -#define O_WRITE_FLAGS O_CREAT | O_RDWR | O_TRUNC, S_IRWXU -#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR, S_IRWXU -#define posix_open ::open -#define posix_close ::close -#define posix_lseek ::lseek -#define posix_read ::read -#define posix_write ::write -#endif - NS_CC_BEGIN struct PXIoF { diff --git a/cocos/platform/CCFileStream.h b/cocos/platform/CCFileStream.h index e165c9414e..3d5afa6b45 100644 --- a/cocos/platform/CCFileStream.h +++ b/cocos/platform/CCFileStream.h @@ -24,6 +24,36 @@ #include "base/ZipUtils.h" #endif +#if defined(_WIN32) +#define O_READ_FLAGS O_BINARY | O_RDONLY, S_IREAD +#define O_WRITE_FLAGS O_CREAT | O_RDWR | O_BINARY | O_TRUNC, S_IWRITE | S_IREAD +#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD + +#define O_OVERLAP_FLAGS O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD + +#define posix_open ::_open +#define posix_close ::_close +#define posix_lseek ::_lseek +#define posix_read ::_read +#define posix_write ::_write +#define posix_fd2fh(fd) reinterpret_cast(_get_osfhandle(fd)) +#define posix_fsetsize(fd, size) ::_chsize(fd, size) +#else +#define O_READ_FLAGS O_RDONLY, S_IRUSR +#define O_WRITE_FLAGS O_CREAT | O_RDWR | O_TRUNC, S_IRWXU +#define O_APPEND_FLAGS O_APPEND | O_CREAT | O_RDWR, S_IRWXU + +#define O_OVERLAP_FLAGS O_CREAT | O_RDWR, S_IRWXU + +#define posix_open ::open +#define posix_close ::close +#define posix_lseek ::lseek +#define posix_read ::read +#define posix_write ::write +#define posix_fd2fh(fd) (fd) +#define posix_fsetsize(fd, size) ::ftruncate(fd, size), ::lseek(fd, 0, SEEK_SET) +#endif + NS_CC_BEGIN struct UnzFileStream;