1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_Arc.h
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: 14502 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_LYT_ARC_H_
17 #define NW_LYT_ARC_H_
18 
19 #if defined(_MSC_VER) && _MSC_VER >= 1500
20 #pragma once
21 #endif
22 
23 #include <nn/types.h>
24 
25 namespace nw
26 {
27 namespace lyt
28 {
29 
30 typedef struct
31 {
32     u32             signature;              //!< ファイルシグネチャ
33     u16             byteOrder;              //!< バイトオーダーマーク
34     u16             headerSize;             //!< ヘッダサイズ
35     u32             version;                //!< ファイルバージョン
36     u32             fileSize;               //!< ファイルサイズ
37     s32             fstStart;				//!< エントリテーブル部の開始位置
38     s32             fstSize;				//!< エントリテーブル部のサイズ
39     s32             fileStart;				//!< ファイルデータ部の開始位置
40 
41 } ARCHeader;
42 
43 const u32       DARCH_SIGNATURE         = 0x63726164;   // 'darc'
44 const u16       DARCH_BYTE_ORDER_MARK   = 0xFEFF;
45 const u32       DARCH_VERSION           = 0x01000000;
46 
47 typedef struct
48 {
49     void*       archiveStartAddr;
50     void*       FSTStart;
51     void*       fileStart;
52     u32         entryNum;
53     wchar_t*    FSTStringStart;
54     u32         FSTLength;
55     u32         currDir;
56 
57 } ARCHandle;
58 
59 typedef struct
60 {
61     ARCHandle*  handle;
62     u32         startOffset;
63     u32         length;
64 
65 } ARCFileInfo;
66 
67 typedef struct
68 {
69     ARCHandle*  handle;
70     u32         entryNum;
71     u32         location;
72     u32         next;
73 } ARCDir;
74 
75 typedef struct
76 {
77     ARCHandle*  handle;
78     u32         entryNum;
79     bool        isDir;
80     wchar_t*    name;
81 } ARCDirEntry;
82 
83 
84 bool  ARCInitHandle(void* arcStart, ARCHandle* handle);
85 bool  ARCOpen(ARCHandle* handle, const wchar_t* fileName, ARCFileInfo* af);
86 bool  ARCFastOpen(ARCHandle* handle, s32 entrynum, ARCFileInfo* af);
87 s32   ARCConvertPathToEntrynum(ARCHandle* handle, const wchar_t* pathPtr);
88 bool  ARCEntrynumIsDir( const ARCHandle * handle, s32 entrynum );
89 void* ARCGetStartAddrInMem(ARCFileInfo* af);
90 u32   ARCGetStartOffset(ARCFileInfo* af);
91 u32   ARCGetLength(ARCFileInfo* af);
92 bool  ARCClose(ARCFileInfo* af);
93 
94 bool  ARCChangeDir(ARCHandle* handle, const wchar_t* dirName);
95 bool  ARCGetCurrentDir(ARCHandle* handle, wchar_t* path, u32 maxlen);
96 
97 bool  ARCOpenDir(ARCHandle* handle, const wchar_t* dirName, ARCDir* dir);
98 bool  ARCReadDir(ARCDir* dir, ARCDirEntry* dirent);
99 bool  ARCCloseDir(ARCDir* dir);
100 
101 /*---------------------------------------------------------------------------*
102   Description:  Returns the current location associated with the directory
103 
104   Arguments:    dir         Pre-opened ARCDir* structure
105 
106   Returns:      current location
107  *---------------------------------------------------------------------------*/
108 #define ARCTellDir(dir)             ((dir)->location)
109 
110 /*---------------------------------------------------------------------------*
111   Description:  Sets the position of the next ARCReadDir on the directory
112 
113   Arguments:    dir         Pre-opened ARCDir* structure
114                 loc         location to set
115 
116   Returns:      None
117  *---------------------------------------------------------------------------*/
118 #define ARCSeekDir(dir, loc)        ((dir)->location = loc)
119 
120 /*---------------------------------------------------------------------------*
121   Description:  Resets the position of the directory to the beginning
122 
123   Arguments:    dir         Pre-opened ARCDir* structure
124 
125   Returns:      None
126  *---------------------------------------------------------------------------*/
127 #define ARCRewindDir(dir)           ((dir)->location = (dir)->entryNum + 1)
128 
129 #define ARCGetDirEntryName(dirent)  ((dirent)->name)
130 #define ARCDirEntryIsDir(dirent)    ((dirent)->isDir)
131 
132 } // namespace lyt
133 } // namespace nw
134 
135 #endif //  NW_LYT_ARC_H_
136