ScummVM API documentation
u6_lib_n.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_FILES_U6LIB_N_H
23 #define NUVIE_FILES_U6LIB_N_H
24 
25 #include "ultima/shared/std/containers.h"
26 #include "common/str.h"
27 #include "common/stream.h"
28 
29 namespace Ultima {
30 namespace Nuvie {
31 
32 class NuvieIO;
33 
34 struct U6LibItem {
35  uint32 offset;
36  uint8 flag;
37  uint32 uncomp_size;
38  uint32 size;
39  Common::String *name;
40  unsigned char *data; // for writing or cache
41 };
42 
43 class U6Lib_n {
44  uint32 filesize; // total size of file
45  uint8 game_type; // there are three types of lib files.
46  uint8 lib_size; // measured in bytes either 2 or 4
47  uint32 num_offsets; // number of items, size of lists
48  U6LibItem *items;
49  NuvieIO *data;
50  bool del_data;
51 
52 public:
53  U6Lib_n();
54  ~U6Lib_n();
55 
56  bool open(const Common::Path &filename, uint8 size, uint8 type = NUVIE_GAME_U6);
57  bool open(NuvieIO *new_data, uint8 size, uint8 type = NUVIE_GAME_U6);
58  void close();
59  bool create(const Common::Path &filename, uint8 size, uint8 type = NUVIE_GAME_U6);
60  uint8 get_game_type() {
61  return game_type;
62  }
63 
64  unsigned char *get_item(uint32 item_number, unsigned char *buf = nullptr); // read
65  void set_item_data(uint32 item_number, unsigned char *src, uint32 src_len);
66 
67  uint32 get_num_items();
68  uint32 get_item_size(uint32 item_number);
69  uint32 get_item_offset(uint32 item_number);
70  const char *get_item_name(uint32 item_number);
71  bool is_compressed(uint32 item_number);
72 
73  void add_item(uint32 offset32, const char *name = nullptr);
74  void write_item(uint32 item_number);
75  void write_items();
76 
77  void load_index(Common::ReadStream *index_f);
78  void write_index();
79  void write_header();
80 
81  void calc_item_offsets();
82 
83 protected:
84  void parse_lib();
85  void calculate_item_sizes();
86  uint32 calculate_item_uncomp_size(U6LibItem *item);
87  uint32 calculate_num_offsets(bool skip4);
88 };
89 
90 #if 0
91 class U6ConverseLib: U6Lib_n {
92 private:
93  uint32 zero_offset_count;
94  Common::String *conversefile;
95 };
96 #endif
97 } // End of namespace Nuvie
98 } // End of namespace Ultima
99 
100 
101 #endif
Definition: str.h:59
Definition: u6_lib_n.h:34
Definition: path.h:52
Definition: detection.h:27
Definition: u6_lib_n.h:43
Definition: stream.h:385
Definition: nuvie_io.h:32