mirror of https://github.com/axmolengine/axmol.git
parent
805390e9d7
commit
f98b776dc0
|
@ -51,8 +51,6 @@ THE SOFTWARE.
|
|||
|
||||
#include "pugixml/pugixml.hpp"
|
||||
|
||||
#define DECLARE_GUARD (void)0
|
||||
|
||||
#include "base/filesystem.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -535,14 +533,12 @@ bool FileUtils::writeBinaryToFile(const void* data, size_t dataSize, std::string
|
|||
|
||||
bool FileUtils::init()
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
_searchPathArray.emplace_back(_defaultResRootPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileUtils::purgeCachedEntries()
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
_fullPathCache.clear();
|
||||
_fullPathCacheDir.clear();
|
||||
}
|
||||
|
@ -663,9 +659,6 @@ std::string FileUtils::getPathForDirectory(std::string_view dir, std::string_vie
|
|||
|
||||
std::string FileUtils::fullPathForFilename(std::string_view filename) const
|
||||
{
|
||||
|
||||
DECLARE_GUARD;
|
||||
|
||||
if (filename.empty())
|
||||
{
|
||||
return "";
|
||||
|
@ -714,8 +707,6 @@ std::string FileUtils::fullPathForFilename(std::string_view filename) const
|
|||
|
||||
std::string FileUtils::fullPathForDirectory(std::string_view dir) const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
|
||||
auto result = std::string();
|
||||
|
||||
if (dir.empty())
|
||||
|
@ -777,31 +768,26 @@ std::string FileUtils::fullPathFromRelativeFile(std::string_view filename, std::
|
|||
|
||||
const std::vector<std::string>& FileUtils::getSearchPaths() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return _searchPathArray;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& FileUtils::getOriginalSearchPaths() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return _originalSearchPaths;
|
||||
}
|
||||
|
||||
void FileUtils::setWritablePath(std::string_view writablePath)
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
_writablePath = writablePath;
|
||||
}
|
||||
|
||||
const std::string& FileUtils::getDefaultResourceRootPath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return _defaultResRootPath;
|
||||
}
|
||||
|
||||
void FileUtils::setDefaultResourceRootPath(std::string_view path)
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
if (_defaultResRootPath != path)
|
||||
{
|
||||
_fullPathCache.clear();
|
||||
|
@ -819,7 +805,6 @@ void FileUtils::setDefaultResourceRootPath(std::string_view path)
|
|||
|
||||
void FileUtils::setSearchPaths(const std::vector<std::string>& searchPaths)
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
bool existDefaultRootPath = false;
|
||||
_originalSearchPaths = searchPaths;
|
||||
|
||||
|
@ -857,7 +842,6 @@ void FileUtils::setSearchPaths(const std::vector<std::string>& searchPaths)
|
|||
|
||||
void FileUtils::addSearchPath(std::string_view searchpath, const bool front)
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
std::string path;
|
||||
if (!isAbsolutePath(searchpath))
|
||||
path = _defaultResRootPath;
|
||||
|
@ -957,8 +941,6 @@ bool FileUtils::isDirectoryExist(std::string_view dirPath) const
|
|||
{
|
||||
AXASSERT(!dirPath.empty(), "Invalid path");
|
||||
|
||||
DECLARE_GUARD;
|
||||
|
||||
if (isAbsolutePath(dirPath))
|
||||
{
|
||||
return isDirectoryExistInternal(dirPath);
|
||||
|
|
|
@ -836,11 +836,6 @@ protected:
|
|||
virtual std::string getFullPathForFilenameWithinDirectory(std::string_view directory,
|
||||
std::string_view filename) const;
|
||||
|
||||
/**
|
||||
* mutex used to protect fields.
|
||||
*/
|
||||
mutable std::recursive_mutex _mutex;
|
||||
|
||||
/**
|
||||
* The vector contains search paths.
|
||||
* The lower index of the element in this vector, the higher priority for this search path.
|
||||
|
|
|
@ -46,8 +46,6 @@ THE SOFTWARE.
|
|||
|
||||
// #define AX_USE_ANDROID_EXTERNAL_FILES_DIR 1
|
||||
|
||||
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
||||
|
||||
namespace ax
|
||||
{
|
||||
|
||||
|
@ -93,8 +91,6 @@ FileUtilsAndroid::~FileUtilsAndroid()
|
|||
|
||||
bool FileUtilsAndroid::init()
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
|
||||
_defaultResRootPath = ASSETS_FOLDER_NAME;
|
||||
|
||||
std::string assetsPath(getApkPath());
|
||||
|
@ -108,9 +104,6 @@ bool FileUtilsAndroid::init()
|
|||
|
||||
bool FileUtilsAndroid::isFileExistInternal(std::string_view strFilePath) const
|
||||
{
|
||||
|
||||
DECLARE_GUARD;
|
||||
|
||||
if (strFilePath.empty())
|
||||
{
|
||||
return false;
|
||||
|
@ -210,7 +203,6 @@ bool FileUtilsAndroid::isDirectoryExistInternal(std::string_view dirPath) const
|
|||
|
||||
bool FileUtilsAndroid::isAbsolutePath(std::string_view strPath) const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
// On Android, there are two situations for full path.
|
||||
// 1) Files in APK, e.g. assets/path/path/file.png
|
||||
// 2) Files not in APK, e.g. /data/data/org.axmol.hellocpp/cache/path/path/file.png, or
|
||||
|
@ -220,7 +212,6 @@ bool FileUtilsAndroid::isAbsolutePath(std::string_view strPath) const
|
|||
|
||||
int64_t FileUtilsAndroid::getFileSize(std::string_view filepath) const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
int64_t size = FileUtils::getFileSize(filepath);
|
||||
if (size != -1)
|
||||
{
|
||||
|
@ -326,7 +317,6 @@ std::string FileUtilsAndroid::getNativeWritableAbsolutePath() const
|
|||
|
||||
}
|
||||
|
||||
#undef DECLARE_GUARD
|
||||
#undef ASSETS_FOLDER_NAME_LENGTH
|
||||
#undef ASSETS_FOLDER_NAME
|
||||
#undef LOGD
|
||||
|
|
|
@ -37,8 +37,6 @@ THE SOFTWARE.
|
|||
#include "base/Director.h"
|
||||
#include "platform/FileUtils.h"
|
||||
|
||||
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
||||
|
||||
namespace ax
|
||||
{
|
||||
|
||||
|
@ -100,13 +98,11 @@ FileUtils* FileUtils::getInstance()
|
|||
|
||||
std::string FileUtilsApple::getWritablePath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return getNativeWritableAbsolutePath();
|
||||
}
|
||||
|
||||
std::string FileUtilsApple::getNativeWritableAbsolutePath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
if (_writablePath.length())
|
||||
{
|
||||
return _writablePath;
|
||||
|
@ -228,33 +224,42 @@ std::string FileUtilsApple::getPathForDirectory(std::string_view dir,
|
|||
std::string FileUtilsApple::getFullPathForFilenameWithinDirectory(std::string_view directory,
|
||||
std::string_view filename) const
|
||||
{
|
||||
auto fullPath = std::string();
|
||||
std::string ret;
|
||||
|
||||
// Build full path for the file
|
||||
if (directory[0] != '/')
|
||||
{
|
||||
NSString* path = [pimpl_->getBundle() pathForResource:[[NSString alloc] initWithBytes:filename.data() length:filename.size() encoding:NSUTF8StringEncoding]
|
||||
ofType:nil
|
||||
inDirectory:[[NSString alloc] initWithBytes:directory.data() length:directory.size() encoding:NSUTF8StringEncoding]];
|
||||
if (path != nil)
|
||||
{
|
||||
fullPath = [path UTF8String];
|
||||
}
|
||||
if (filename.empty())
|
||||
return ret;
|
||||
|
||||
if (!directory.empty() && directory[0] == '/') {
|
||||
size_t pathSize = directory.size() + filename.size();
|
||||
if (directory.back() != '/')
|
||||
++pathSize;
|
||||
ret.reserve(pathSize);
|
||||
ret += directory;
|
||||
ret += filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
fullPath = directory;
|
||||
fullPath += filename;
|
||||
{ // Build full path for the file
|
||||
NSString* path = nil;
|
||||
if (!directory.empty()) {
|
||||
path = [pimpl_->getBundle() pathForResource:[[NSString alloc] initWithBytes:filename.data() length:filename.size() encoding:NSUTF8StringEncoding]
|
||||
ofType:nil
|
||||
inDirectory:[[NSString alloc] initWithBytes:directory.data() length:directory.size() encoding:NSUTF8StringEncoding]];
|
||||
} else {
|
||||
path = [pimpl_->getBundle() pathForResource:[[NSString alloc] initWithBytes:filename.data() length:filename.size() encoding:NSUTF8StringEncoding]
|
||||
ofType:nil];
|
||||
}
|
||||
if (path != nil)
|
||||
ret = [path UTF8String];
|
||||
}
|
||||
|
||||
// Check if there's a file at path
|
||||
BOOL isDir = NO;
|
||||
if (![s_fileManager fileExistsAtPath:[NSString stringWithUTF8String:fullPath.c_str()] isDirectory:&isDir] || isDir)
|
||||
if (![s_fileManager fileExistsAtPath:[NSString stringWithUTF8String:ret.c_str()] isDirectory:&isDir] || isDir)
|
||||
{
|
||||
fullPath.clear();
|
||||
ret.clear();
|
||||
}
|
||||
|
||||
return fullPath;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FileUtilsApple::createDirectories(std::string_view path) const
|
||||
|
|
|
@ -36,8 +36,6 @@ THE SOFTWARE.
|
|||
|
||||
using namespace std;
|
||||
|
||||
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
||||
|
||||
namespace ax
|
||||
{
|
||||
|
||||
|
@ -73,8 +71,6 @@ FileUtilsLinux::FileUtilsLinux() {}
|
|||
|
||||
bool FileUtilsLinux::init()
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
|
||||
// application path
|
||||
if (s_exeDir.empty()) {
|
||||
s_exeDir = _checkPath("/proc/self/exe");
|
||||
|
@ -123,7 +119,6 @@ bool FileUtilsLinux::init()
|
|||
|
||||
string FileUtilsLinux::getWritablePath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return getNativeWritableAbsolutePath();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ THE SOFTWARE.
|
|||
|
||||
#include "ntcvt/ntcvt.hpp"
|
||||
|
||||
#define DECLARE_GUARD (void)0 // std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
|
||||
|
||||
namespace ax
|
||||
{
|
||||
|
||||
|
@ -164,13 +162,11 @@ int64_t FileUtilsWin32::getFileSize(std::string_view filepath) const
|
|||
|
||||
std::string FileUtilsWin32::getWritablePath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
return getNativeWritableAbsolutePath();
|
||||
}
|
||||
|
||||
std::string FileUtilsWin32::getNativeWritableAbsolutePath() const
|
||||
{
|
||||
DECLARE_GUARD;
|
||||
if (_writablePath.length())
|
||||
{
|
||||
return _writablePath;
|
||||
|
|
Loading…
Reference in New Issue