aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/common/RootHandler.h
blob: a53cc4c24059d5e2ace3b784b43c2b18eec15882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*****************************************************************************/
/* RootHandler.h                          Copyright (c) Ladislav Zezula 2015 */
/*---------------------------------------------------------------------------*/
/* Interface for root handlers                                               */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -------                                              */
/* 09.03.15  1.00  Lad  Created                                              */
/*****************************************************************************/

#ifndef __ROOT_HANDLER_H__
#define __ROOT_HANDLER_H__

//-----------------------------------------------------------------------------
// Defines

#define CASC_MNDX_ROOT_SIGNATURE        0x58444E4D  // 'MNDX'
#define CASC_TVFS_ROOT_SIGNATURE        0x53465654  // 'TVFS'
#define CASC_DIABLO3_ROOT_SIGNATURE     0x8007D0C4
#define CASC_WOW_ROOT_SIGNATURE         0x4D465354  // 'TSFM', since WoW build 30080 (8.2.0)

#define DUMP_LEVEL_ROOT_FILE                     1  // Dump root file
#define DUMP_LEVEL_ENCODING_FILE                 2  // Dump root file + encoding file
#define DUMP_LEVEL_INDEX_ENTRIES                 3  // Dump root file + encoding file + index entries

//-----------------------------------------------------------------------------
// Class for generic root handler

struct TRootHandler
{
    public:

    TRootHandler()
    {
        dwFeatures = 0;
    }

    virtual ~TRootHandler()
    {}

    // Inserts new file name to the root handler
    // szFileName - Pointer to the file name
    // pCKeyEntry - Pointer to the CASC_CKEY_ENTRY for the file
    virtual int Insert(const char * /* szFileName */, PCASC_CKEY_ENTRY /* pCKeyEntry */)
    {
        return ERROR_NOT_SUPPORTED;
    }

    // Searches the file by file name
    // hs         - Pointer to the storage structure
    // szFileName - Pointer to the file name
    virtual PCASC_CKEY_ENTRY GetFile(struct TCascStorage * /* hs */, const char * /* szFileName */)
    {
        return NULL;
    }

    // Searches the file by file data id
    // hs         - Pointer to the storage structure
    // FileDataId - File data id
    virtual PCASC_CKEY_ENTRY GetFile(struct TCascStorage * /* hs */, DWORD /* FileDataId */)
    {
        return NULL;
    }

    // Searches the file by file name
    // nFileIndex - Index to the table
    // szFileName - Pointer to the file name
    virtual PCASC_CKEY_ENTRY GetFile(size_t /* nFileIndex */, char * /* szFileName */, size_t /* ccFileName */)
    {
        return NULL;
    }

    // Performs find-next-file operation
    // pSearch   - Pointer to the initialized search structure
    // pFindData - Pointer to output structure that will contain the information
    virtual PCASC_CKEY_ENTRY Search(struct TCascSearch * /* pSearch */, struct _CASC_FIND_DATA * /* pFindData */)
    {
        return NULL;
    }

    // Returns advanced info from the root file entry.
    // pCKeyEntry - CKey/EKey, depending on which type the root handler provides
    // pFileInfo - Pointer to CASC_FILE_FULL_INFO structure
    virtual bool GetInfo(PCASC_CKEY_ENTRY /* pCKeyEntry */, struct _CASC_FILE_FULL_INFO * /* pFileInfo */)
    {
        return false;
    }

    // Copies all items from the given root handler to the new one
    virtual size_t Copy(TRootHandler * /* pRoot */)
    {
        return 0;
    }

    // Returns the maximum file index
    virtual size_t GetMaxFileIndex()
    {
        return 0;
    }

    // Returns the list of features
    DWORD GetFeatures()
    {
        return dwFeatures;
    }

    protected:

    DWORD dwFeatures;                               // CASC features. See CASC_FEATURE_XXX
};

//-----------------------------------------------------------------------------
// Class for root handler that has basic mapping of FileName -> CASC_FILE_NODE

struct TFileTreeRoot : public TRootHandler
{
    TFileTreeRoot(DWORD FileTreeFlags);
    virtual ~TFileTreeRoot();

    int Insert(const char * szFileName, PCASC_CKEY_ENTRY pCKeyEntry);

    PCASC_CKEY_ENTRY GetFile(struct TCascStorage * hs, const char * szFileName);
    PCASC_CKEY_ENTRY GetFile(struct TCascStorage * hs, DWORD FileDataId);
    PCASC_CKEY_ENTRY GetFile(size_t nFileIndex, char * /* szFileName */, size_t /* ccFileName */);
    PCASC_CKEY_ENTRY Search(struct TCascSearch * pSearch, struct _CASC_FIND_DATA * pFindData);
    bool GetInfo(PCASC_CKEY_ENTRY pCKeyEntry, struct _CASC_FILE_FULL_INFO * pFileInfo);
    size_t Copy(TRootHandler * pRoot);
    size_t GetMaxFileIndex();

    protected:

    CASC_FILE_TREE FileTree;
};

#endif  // __ROOT_HANDLER_H__