1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: SmFile.cpp 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 1 $ 14 *---------------------------------------------------------------------------*/ 15 #ifndef SM_FILE_H_ 16 #define SM_FILE_H_ 17 18 #include <nn/fs.h> 19 #include "../include/SmBase.h" 20 21 22 //------------------------------------------------------------------------------ 23 // �t�@�C���̓ǂݍ��݂��s���N���X�ł��B 24 class SmFile 25 { 26 public: 27 // �R���X�g���N�^ 28 SmFile( bool autoFree = false ) m_Buffer(NULL)29 : m_Buffer(NULL), 30 m_Size(0), 31 m_AutoFree( autoFree ), 32 m_Allocator( NULL ){} 33 34 // �f�X�g���N�^ ~SmFile()35 ~SmFile() 36 { 37 if ( m_AutoFree ) 38 { 39 Release(); 40 } 41 } 42 43 // �w�肳�ꂽ�t�@�C����ǂݍ��݂܂��B Read(const wchar_t * fileName,nw::os::IAllocator * allocator)44 bool Read( const wchar_t* fileName, nw::os::IAllocator* allocator ) 45 { 46 NW_ASSERT(m_Buffer == NULL); 47 NW_NULL_ASSERT( allocator ); 48 49 m_Allocator = allocator; 50 51 nn::fs::FileReader fileReader(fileName); 52 if (fileReader.GetSize() <= 0) 53 { 54 return false; 55 } 56 57 this->m_Size = static_cast<u32>(fileReader.GetSize()); 58 this->m_Buffer = static_cast<u8*>(m_Allocator->Alloc(this->m_Size, 128)); 59 if (this->m_Buffer == NULL) 60 { 61 this->m_Size = 0; 62 return false; 63 } 64 65 fileReader.Read(this->m_Buffer, this->m_Size); 66 fileReader.Finalize(); 67 68 return true; 69 } 70 71 // �ǂݍ��t�@�C���̃o�b�t�@���擾���܂��B Buffer()72 u8* Buffer() 73 { 74 return this->m_Buffer; 75 } 76 77 // �ǂݍ��t�@�C���̃T�C�Y���擾���܂��B Size()78 u32 Size() 79 { 80 return this->m_Size; 81 } 82 83 // �m�ۂ�����������������܂� Release()84 void Release() 85 { 86 if ( m_Buffer ) 87 { 88 m_Allocator->Free( m_Buffer ); 89 m_Buffer = NULL; 90 } 91 } 92 93 private: 94 u8* m_Buffer; 95 u32 m_Size; 96 bool m_AutoFree; 97 nw::os::IAllocator* m_Allocator; 98 }; 99 100 101 #endif // SM_FILE_H_ 102