/*---------------------------------------------------------------------------* Project: Horizon File: fs_FileBase.h Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 25872 $ *---------------------------------------------------------------------------*/ #ifndef NN_FS_CTR_MPCORE_FS_FILEBASE_H_ #define NN_FS_CTR_MPCORE_FS_FILEBASE_H_ #include #include #include #include #include #include #include #include #include #include "fs_UserFileSystem.h" namespace nn { namespace fs { namespace detail { class FileBaseImpl : private nn::util::NonCopyable, private nn::fs::CTR::MPCore::detail::UserFileSystem { protected: FileBaseImpl() : m_P(0) {} Result TryOpenImpl(const wchar_t* path, bit32 mode) { return TryOpenFile(&m_P, path, mode); } Result TryOpenImpl(const wchar_t* path, bit32 mode, nn::fs::PathMark pathMark) { NN_UNUSED_VAR( pathMark); return TryOpenFile(&m_P, path, mode); } void Finalize() { UserFileSystem::CloseFile(m_P); this->m_P = 0; } ~FileBaseImpl() { Finalize(); } Result TryRead(s32* pOut, s64 offset, void* buffer, size_t size) { return UserFileSystem::TryReadFile(pOut, m_P, offset, buffer, size); } Result TryWrite(s32* pOut, s64 offset, const void* buffer, size_t size) { return UserFileSystem::TryWriteFile(pOut, m_P, offset, buffer, size); } Result TryGetSize(s64* pOut) const { return UserFileSystem::TryGetFileSize(pOut, m_P); } Result TrySetSize(s64 size) { return UserFileSystem::TrySetFileSize(m_P, size); } public: Result DuplicateHandle(Handle* pOut, s64 offset, s64 length) { return UserFileSystem::DuplicateHandleForFile(pOut, m_P, offset, length); } void OpenDirect(Handle handle) { UserFileSystem::OpenDirect(&m_P, handle); } void CloseDirect() { UserFileSystem::CloseDirect(m_P); } Handle GetHandle() { return UserFileSystem::GetFileHandle(m_P); } void DetachHandle() { return UserFileSystem::DetachHandle(m_P); } Result TryInitializeRaw(ArchiveHandle handle, const nn::fs::CTR::MPCore::Path& path, bit32 mode) { return UserFileSystem::TryOpenFileRaw(&m_P, handle, path, mode); } Result TryInitializeRawDirectly(bit32 archiveType, const nn::fs::CTR::MPCore::Path& archivePath, const nn::fs::CTR::MPCore::Path& path, bit32 mode) { return UserFileSystem::TryOpenFileRawDirectly(&m_P, archiveType, archivePath, path, mode); } bool IsValid() { return GetHandle().IsValid(); } private: void* m_P; bool IsInitialized() const { return m_P != 0; } }; }}} #endif