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