1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     io_RomFileStream.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 
18 #ifndef NW_IO_ROM_FILE_STREAM_H_
19 #define NW_IO_ROM_FILE_STREAM_H_
20 
21 #include <nn/fs.h>
22 #include <nw/io/io_FileStream.h>
23 
24 namespace nw {
25 namespace io {
26 
27 class RomFileStream : public FileStream
28 {
29 public:
30     NW_UT_RUNTIME_TYPEINFO;
31 
32     RomFileStream();
33     RomFileStream( const char* path );
34     // RomFileStream( const wchar_t* path );
35 #ifdef NW_PLATFORM_CTRWIN
36     RomFileStream( const nn::fs::File* openedFile, bool closeEnable = true );
37 #else
38     RomFileStream( nn::fs::FileReader* openedFileReader, bool closeEnable = true );
39 #endif
40     virtual ~RomFileStream();
41 
42     bool Open( const char* path );
43     // bool Open( const wchar_t* path );
44 #ifdef NW_PLATFORM_CTRWIN
45     bool Open( const nn::fs::File* openedFile, bool closeEnable = true );
46 #else
47     bool Open( nn::fs::FileReader* openedFileReader, bool closeEnable = true );
48 #endif
49     virtual void Close();
50     virtual s32 Read( void* buf, u32 length );
51 
52     virtual void Seek( s32 offset, u32 origin );
GetSize()53     virtual u32 GetSize() const { return m_FilePosition.GetFileSize(); }
Tell()54     virtual u32 Tell() const { return m_FilePosition.Tell(); }
55 
CanSeek()56     virtual bool CanSeek()   const { return true; }
CanCancel()57     virtual bool CanCancel() const { return false; } // TODO: CTR_SDK で非同期ロードサポートされたら true
CanRead()58     virtual bool CanRead()   const { return true; }
CanWrite()59     virtual bool CanWrite()  const { return false; }
CanAsync()60     virtual bool CanAsync()  const { return false; } // TODO: CTR_SDK で非同期ロードサポートされたら true
61 
62 protected:
63 
64 private:
65     void Initialize();
66 
67     FilePosition m_FilePosition;
68 
69 #ifdef NW_PLATFORM_CTRWIN
70     nn::fs::File m_File;
71         /* TODO: オープン済みのファイルを nn::fs::FileReader で扱えるようになったら、
72                  完全に nn::fs::FileReader を使う実装に置き換える */
73 #else
74     nn::fs::FileReader m_FileReader;
75     nn::fs::FileReader* m_pOpenedFileReader;
76 #endif
77     bool m_IsAvailable;
78     bool m_CloseOnDestroyFlag;  // true: デストラクト時にファイルをクローズする
79     bool m_CloseEnableFlag;     // true: RomFileStream 内でファイルのクローズを許可
80 
81 };
82 
83 
84 } // namespace nw::io
85 } // namespace nw
86 
87 
88 #endif /* NW_IO_ROM_FILE_STREAM_H_ */
89 
90