1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_GroupFileReader.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: 13145 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/snd/snd_GroupFileReader.h>
19
20 namespace nw {
21 namespace snd {
22 namespace internal {
23
24 namespace {
25
26 const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' );
27 const u32 SIGNATURE_FILE_BLOCK = NW_UT_MAKE_SIGWORD( 'F', 'I', 'L', 'E' );
28
29 const u32 SUPPORTED_FILE_VERSION = 0x01000000;
30 const u32 CURRENT_FILE_VERSION = 0x01000000;
31
IsValidFileHeader(const void * groupFile)32 bool IsValidFileHeader( const void* groupFile )
33 {
34 const ut::BinaryFileHeader* header =
35 reinterpret_cast<const ut::BinaryFileHeader*>( groupFile );
36
37 // シグニチャ確認
38 NW_ASSERTMSG( header->signature == GroupFileReader::SIGNATURE_FILE,
39 "invalid file signature. group file is not available." );
40 if ( header->signature != GroupFileReader::SIGNATURE_FILE )
41 {
42 return false;
43 }
44
45 // バージョン確認
46 NW_ASSERTMSG( header->version >= SUPPORTED_FILE_VERSION,
47 "group file is not supported version.\n"
48 "please reconvert file using new version tools.\n"
49 "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
50 SUPPORTED_FILE_VERSION, header->version
51 );
52 if ( header->version < SUPPORTED_FILE_VERSION ) return false;
53
54 NW_ASSERTMSG( header->version <= CURRENT_FILE_VERSION,
55 "group file is not supported version.\n"
56 "please reconvert file using new version tools.\n"
57 "(CURRENT_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
58 CURRENT_FILE_VERSION, header->version
59 );
60 if ( header->version > CURRENT_FILE_VERSION ) return false;
61
62 return true;
63 }
64
65 } // anonymous namespace
66
GroupFileReader(const void * groupFile)67 GroupFileReader::GroupFileReader( const void* groupFile )
68 : m_pInfoBlockBody( NULL ),
69 m_pFileBlockBody( NULL )
70 {
71 NW_NULL_ASSERT( groupFile );
72
73 if ( ! IsValidFileHeader( groupFile ) ) return;
74
75 const GroupFile::FileHeader* header =
76 static_cast<const GroupFile::FileHeader*>( groupFile );
77
78 const GroupFile::InfoBlock* infoBlock = header->GetInfoBlock();
79 const GroupFile::FileBlock* fileBlock = header->GetFileBlock();
80
81 if ( infoBlock == NULL ) return;
82 if ( fileBlock == NULL ) return;
83
84 NW_ASSERT( infoBlock->header.kind == SIGNATURE_INFO_BLOCK );
85 NW_ASSERT( fileBlock->header.kind == SIGNATURE_FILE_BLOCK );
86
87 m_pInfoBlockBody = &infoBlock->body;
88 m_pFileBlockBody = &fileBlock->body;
89 }
90
ReadGroupItemLocationInfo(GroupItemLocationInfo * info,u32 index) const91 bool GroupFileReader::ReadGroupItemLocationInfo(
92 GroupItemLocationInfo* info, u32 index ) const
93 {
94 if ( m_pInfoBlockBody == NULL )
95 {
96 return false;
97 }
98
99 const GroupFile::GroupItemInfo* groupItemInfo = m_pInfoBlockBody->GetGroupItemInfo( index );
100 if ( groupItemInfo == NULL )
101 {
102 return false;
103 }
104
105 info->fileId = groupItemInfo->fileId;
106 info->address = groupItemInfo->GetFileLocation( m_pFileBlockBody );
107 return true;
108 }
109
110 } // namespace nw::snd::internal
111 } // namespace nw::snd
112 } // namespace nw
113
114