/*---------------------------------------------------------------------------* Project: NintendoWare File: snd_GroupFileReader.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. 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. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include namespace nw { namespace snd { namespace internal { namespace { const u32 SIGNATURE_INFO_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'O' ); const u32 SIGNATURE_FILE_BLOCK = NW_UT_MAKE_SIGWORD( 'F', 'I', 'L', 'E' ); const u32 SIGNATURE_INFOEX_BLOCK = NW_UT_MAKE_SIGWORD( 'I', 'N', 'F', 'X' ); const u32 SUPPORTED_FILE_VERSION = 0x01000000; const u32 CURRENT_FILE_VERSION = 0x01010000; bool IsValidFileHeader( const void* groupFile ) { const ut::BinaryFileHeader* header = reinterpret_cast( groupFile ); // シグニチャ確認 NW_ASSERTMSG( header->signature == GroupFileReader::SIGNATURE_FILE, "invalid file signature. group file is not available." ); if ( header->signature != GroupFileReader::SIGNATURE_FILE ) { return false; } // バージョン確認 NW_ASSERTMSG( header->version >= SUPPORTED_FILE_VERSION, "group file is not supported version.\n" "please reconvert file using new version tools.\n" "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n", SUPPORTED_FILE_VERSION, header->version ); if ( header->version < SUPPORTED_FILE_VERSION ) return false; NW_ASSERTMSG( header->version <= CURRENT_FILE_VERSION, "group file is not supported version.\n" "please reconvert file using new version tools.\n" "(CURRENT_FILE_VERSION:0x%08x >= your version:0x%08x)\n", CURRENT_FILE_VERSION, header->version ); if ( header->version > CURRENT_FILE_VERSION ) return false; return true; } } // anonymous namespace GroupFileReader::GroupFileReader( const void* groupFile ) : m_pInfoBlockBody( NULL ), m_pFileBlockBody( NULL ), m_pInfoExBlockBody( NULL ) { NW_NULL_ASSERT( groupFile ); if ( ! IsValidFileHeader( groupFile ) ) return; const GroupFile::FileHeader* header = static_cast( groupFile ); const GroupFile::InfoBlock* infoBlock = header->GetInfoBlock(); const GroupFile::FileBlock* fileBlock = header->GetFileBlock(); const GroupFile::InfoExBlock* infoExBlock = header->GetInfoExBlock(); if ( infoBlock == NULL ) return; if ( fileBlock == NULL ) return; NW_ASSERT( infoBlock->header.kind == SIGNATURE_INFO_BLOCK ); NW_ASSERT( fileBlock->header.kind == SIGNATURE_FILE_BLOCK ); m_pInfoBlockBody = &(infoBlock->body); m_pFileBlockBody = &(fileBlock->body); // バイナリバージョンが 1.0.0.0 のときは InfoExBlock が含まれない if ( infoExBlock != NULL ) { NW_ASSERT( infoExBlock->header.kind == SIGNATURE_INFOEX_BLOCK ); m_pInfoExBlockBody = &(infoExBlock->body); } } bool GroupFileReader::ReadGroupItemLocationInfo( GroupItemLocationInfo* out, u32 index ) const { if ( m_pInfoBlockBody == NULL ) { return false; } const GroupFile::GroupItemInfo* groupItemInfo = m_pInfoBlockBody->GetGroupItemInfo( index ); if ( groupItemInfo == NULL ) { return false; } out->fileId = groupItemInfo->fileId; out->address = groupItemInfo->GetFileLocation( m_pFileBlockBody ); return true; } u32 GroupFileReader::GetGroupItemExCount() const { if ( m_pInfoExBlockBody == NULL ) { return 0; } return m_pInfoExBlockBody->GetGroupItemInfoExCount(); } bool GroupFileReader::ReadGroupItemInfoEx( GroupFile::GroupItemInfoEx* out, u32 index ) const { if ( m_pInfoExBlockBody == NULL ) { return false; } const GroupFile::GroupItemInfoEx* groupItemInfoEx = m_pInfoExBlockBody->GetGroupItemInfoEx( index ); if ( groupItemInfoEx == NULL ) { return false; } *out = *groupItemInfoEx; // 構造体のコピー return true; } } // namespace nw::snd::internal } // namespace nw::snd } // namespace nw