1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: lyt_ArcUtil.cpp
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: 31311 $
16 *---------------------------------------------------------------------------*/
17
18 #include "precompiled.h"
19
20 #include <nw/lyt/lyt_ArcUtil.h>
21
22 #ifdef NW_PLATFORM_CTR
23 #define _wcsicmp std::wcscasecmp
24 #endif
25
26 namespace nw
27 {
28 namespace lyt
29 {
30
31 bool
OpenResourceDir(ARCHandle * pArcHandle,const wchar_t * pRootDir,ResType resType,ARCDir * pDir)32 ArcUtil::OpenResourceDir(
33 ARCHandle* pArcHandle,
34 const wchar_t* pRootDir,
35 ResType resType,
36 ARCDir* pDir)
37 {
38 NW_NULL_ASSERT(pArcHandle);
39 NW_NULL_ASSERT(pDir);
40 NW_ASSERT(resType != 0);
41
42 bool result;
43
44 result = ARCChangeDir(pArcHandle, pRootDir);
45 if (!result)
46 {
47 return result;
48 }
49
50 wchar_t dirName[5];
51
52 // リソースタイプからディレクトリ名を生成。
53 dirName[0] = u8(resType >> 24);
54 dirName[1] = u8(resType >> 16);
55 dirName[2] = u8(resType >> 8);
56 dirName[3] = u8(resType >> 0);
57 dirName[4] = 0;
58
59 result = ARCOpenDir(pArcHandle, dirName, pDir);
60
61 return result;
62 }
63
64 bool
ReadResourceDir(ARCDir * pDir,const wchar_t * pExtStr,u32 extLen,ARCDirEntry * pDirEnt)65 ArcUtil::ReadResourceDir(
66 ARCDir* pDir,
67 const wchar_t* pExtStr,
68 u32 extLen,
69 ARCDirEntry* pDirEnt)
70 {
71 NW_NULL_ASSERT(pDir);
72 NW_NULL_ASSERT(pExtStr);
73 NW_ASSERT(extLen > 0);
74 NW_NULL_ASSERT(pDirEnt);
75
76 while (ARCReadDir(pDir, pDirEnt))
77 {
78 size_t nameLen = std::wcslen(pDirEnt->name);
79 if (nameLen <= extLen)
80 {
81 continue;
82 }
83
84 if (0 != _wcsicmp(pDirEnt->name + nameLen - extLen, pExtStr))
85 {
86 continue;
87 }
88
89 return true;
90 }
91
92 return false;
93 }
94
95 } // namespace nw::lyt
96 } // namespace nw
97