当前位置: 首页>>代码示例>>C++>>正文


C++ FileSystem::CheckAccess方法代码示例

本文整理汇总了C++中FileSystem::CheckAccess方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::CheckAccess方法的具体用法?C++ FileSystem::CheckAccess怎么用?C++ FileSystem::CheckAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem的用法示例。


在下文中一共展示了FileSystem::CheckAccess方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SaveJPG

bool Image::SaveJPG(const String & fileName, int quality)
{
    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    if (fileSystem && !fileSystem->CheckAccess(GetPath(fileName)))
    {
        LOGERROR("Access denied to " + fileName);
        return false;
    }
    
    if (IsCompressed())
    {
        LOGERROR("Can not save compressed image to JPG");
        return false;
    }
    
    if (data_)
        return jo_write_jpg(fileName.CString(), data_.Get(), width_, height_, components_, quality) != 0;
    else
        return false;
}
开发者ID:PeteX,项目名称:Urho3D,代码行数:20,代码来源:Image.cpp

示例2: Open

bool File::Open(const String& fileName, FileMode mode)
{
    Close();

    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    if (fileSystem && !fileSystem->CheckAccess(GetPath(fileName)))
    {
        LOGERROR("Access denied to " + fileName);
        return false;
    }

    #ifdef ANDROID
    if (fileName.StartsWith("/apk/"))
    {
        if (mode != FILE_READ)
        {
            LOGERROR("Only read mode is supported for asset files");
            return false;
        }

        assetHandle_ = SDL_RWFromFile(fileName.Substring(5).CString(), "rb");
        if (!assetHandle_)
        {
            LOGERROR("Could not open asset file " + fileName);
            return false;
        }
        else
        {
            fileName_ = fileName;
            mode_ = mode;
            position_ = 0;
            offset_ = 0;
            checksum_ = 0;
            size_ = assetHandle_->hidden.androidio.size;
            readBuffer_ = new unsigned char[READ_BUFFER_SIZE];
            readBufferOffset_ = 0;
            readBufferSize_ = 0;
            return true;
        }
    }
    #endif

    if (fileName.Empty())
    {
        LOGERROR("Could not open file with empty name");
        return false;
    }
    
    #ifdef WIN32
    handle_ = _wfopen(GetWideNativePath(fileName).CString(), openMode[mode]);
    #else
    handle_ = fopen(GetNativePath(fileName).CString(), openMode[mode]);
    #endif

    if (!handle_)
    {
        LOGERROR("Could not open file " + fileName);
        return false;
    }

    fileName_ = fileName;
    mode_ = mode;
    position_ = 0;
    offset_ = 0;
    checksum_ = 0;
    compressed_ = false;

    fseek((FILE*)handle_, 0, SEEK_END);
    size_ = ftell((FILE*)handle_);
    fseek((FILE*)handle_, 0, SEEK_SET);
    return true;
}
开发者ID:PeteX,项目名称:Urho3D,代码行数:72,代码来源:File.cpp

示例3: OpenInternal

bool File::OpenInternal(const String& fileName, FileMode mode, bool fromPackage)
{
    Close();

    compressed_ = false;
    readSyncNeeded_ = false;
    writeSyncNeeded_ = false;

    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    if (fileSystem && !fileSystem->CheckAccess(GetPath(fileName)))
    {
        ATOMIC_LOGERRORF("Access denied to %s", fileName.CString());
        return false;
    }

    if (fileName.Empty())
    {
        ATOMIC_LOGERROR("Could not open file with empty name");
        return false;
    }

#ifdef __ANDROID__
    if (ATOMIC_IS_ASSET(fileName))
    {
        if (mode != FILE_READ)
        {
            ATOMIC_LOGERROR("Only read mode is supported for Android asset files");
            return false;
        }

        assetHandle_ = SDL_RWFromFile(ATOMIC_ASSET(fileName), "rb");
        if (!assetHandle_)
        {
            ATOMIC_LOGERRORF("Could not open Android asset file %s", fileName.CString());
            return false;
        }
        else
        {
            fileName_ = fileName;
            mode_ = mode;
            position_ = 0;
            if (!fromPackage)
            {
                size_ = SDL_RWsize(assetHandle_);
                offset_ = 0;
            }
            checksum_ = 0;
            return true;
        }
    }
#endif

#ifdef _WIN32
    handle_ = _wfopen(GetWideNativePath(fileName).CString(), openMode[mode]);
#else
    handle_ = fopen(GetNativePath(fileName).CString(), openMode[mode]);
#endif

    // If file did not exist in readwrite mode, retry with write-update mode
    if (mode == FILE_READWRITE && !handle_)
    {
#ifdef _WIN32
        handle_ = _wfopen(GetWideNativePath(fileName).CString(), openMode[mode + 1]);
#else
        handle_ = fopen(GetNativePath(fileName).CString(), openMode[mode + 1]);
#endif
    }

    if (!handle_)
    {
        ATOMIC_LOGERRORF("Could not open file %s", fileName.CString());
        return false;
    }

    if (!fromPackage)
    {
        fseek((FILE*)handle_, 0, SEEK_END);
        long size = ftell((FILE*)handle_);
        fseek((FILE*)handle_, 0, SEEK_SET);
        if (size > M_MAX_UNSIGNED)
        {
            ATOMIC_LOGERRORF("Could not open file %s which is larger than 4GB", fileName.CString());
            Close();
            size_ = 0;
            return false;
        }
        size_ = (unsigned)size;
        offset_ = 0;
    }

    fileName_ = fileName;
    mode_ = mode;
    position_ = 0;
    checksum_ = 0;

    return true;
}
开发者ID:EternalXY,项目名称:AtomicGameEngine,代码行数:97,代码来源:File.cpp


注:本文中的FileSystem::CheckAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。