Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Archive.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Archive.h
7  AUTHOR: John DiCamillo
8 
9 */
10 
11 #ifndef Archive_h
12 #define Archive_h
13 
14 // +------------------------------------------------------------------+
15 
16 #define VERSION 0x0010
17 #define BLOCK_SIZE 1024
18 #define FILE_BLOCK 1024
19 #define NAMELEN 64
20 
21 // +------------------------------------------------------------------+
22 
23 struct DataHeader
24 {
25  static const char* TYPENAME() { return "DataHeader"; }
26 
27  DWORD version;
28  DWORD nfiles;
29  DWORD dir_blocks;
31  DWORD dir_offset;
32 };
33 
34 struct DataEntry
35 {
36  static const char* TYPENAME() { return "DataEntry"; }
37 
38  char name[NAMELEN];
39  DWORD size_orig;
40  DWORD size_comp;
41  DWORD offset;
42 };
43 
45 {
46 public:
47  static const char* TYPENAME() { return "DataArchive"; }
48 
49  // ctor:
50  DataArchive(const char* name = 0);
51  ~DataArchive();
52 
53  // operations:
54  void LoadDatafile(const char* name);
55  void Insert(const char* name);
56  void Extract(const char* name);
57  void Remove(const char* name);
58  void List();
59 
60  void WriteEntry(int index, BYTE* buf);
61  int FindEntry(const char* req_name);
62  int ExpandEntry(int index, BYTE*& buf, bool null_terminate=false);
63  BYTE* CompressEntry(int index);
64  int InsertEntry(const char* name);
65  void RemoveEntry(int index);
66  DWORD Blocks(DWORD raw_size);
67  DWORD DirBlocks();
68  DWORD FileBlocks(int index);
69  int FindDataBlocks(int blocks_needed);
70  void CreateBlockMap();
71 
72  DWORD NumFiles() { return header.nfiles; }
73  DataEntry* GetFile(int i) { if (i>=0 && i<(int)header.nfiles) return &directory[i]; return 0; }
74 
75  const char* Name() const { return datafile; }
76 
77 private:
78  // persistent data members:
79  DataHeader header;
80  DataEntry* directory;
81  BYTE* dirbuf;
82 
83  // transient members:
84  char datafile[NAMELEN];
85 
86  DWORD* block_map;
87  DWORD nblocks;
88 };
89 
90 #endif Archive_h