ScummVM API documentation
sys_file.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 M4_FILEIO_SYS_FILE_H
23 #define M4_FILEIO_SYS_FILE_H
24 
25 #include "common/file.h"
26 #include "m4/fileio/fileio.h"
27 #include "m4/mem/reloc.h"
28 
29 namespace M4 {
30 
31 struct Hash_Record {
32  Common::String filename;
33  byte hagfile;
34  byte disks;
35  uint32 offset;
36  uint32 size;
37 };
38 
39 struct Hag_Statics {
40  bool hag_flag = false;
41  bool first_read_flag = false;
42  Common::Path hash_file;
43  Hag_Name_Record *hag_name_list = nullptr;
44  Hag_Record *hag_file_list = nullptr;
45 };
46 
47 class SysFile {
48 private:
49  Common::Stream *_fp = nullptr;
50  FileMode fmode;
51  AccessMode mode = UNOPENED;
52  int hag_success = 0;
53  bool show_error_flag = true;
54  Hag_Record *curr_hag_record = nullptr;
55  Hash_Record curr_hash_record;
56  uint32 last_head_pos = 0;
57 
58 private:
59  void open_read();
60  void open_write();
61  void open_read_low_level();
62  bool open_hash_file();
63  Common::String get_last_string(const Common::String &src);
64 
68  uint32 key_to_hash_address(const Common::String &src, uint32 hash_table_size);
69 
76  int hash_search(const Common::String &fname, Hash_Record *current_hash_record_ptr, Hag_Record *curr_hag_record, uint32 hash_address,
77  Common::SeekableReadStream *hashfp, uint32 hash_table_size, bool show_error_flag);
78 
83  Common::Stream *open_by_first_char();
84 
85  bool get_local_name_from_hagfile(Common::String &local_name, byte hagfile);
86 
87  Common::SeekableReadStream *rs() const;
88 
89 public:
90  Common::String filename;
91 
92 public:
93  SysFile(const Common::String &fname, FileMode myfmode = BINARY);
94 
98  bool exists();
99 
103  uint32 size();
104 
108  uint32 get_pos();
109 
113  bool seek(uint32 pos);
114 
118  bool seek_ahead(int32 amount);
119 
123  uint32 read(MemHandle bufferHandle);
124  int32 read(MemHandle bufferHandle, int32 n);
125 
129  uint32 readUint32LE();
130  int32 readSint32LE() {
131  return (int32)readUint32LE();
132  }
133 
137  void close();
138 };
139 
140 void sysfile_init(bool in_hag_mode);
141 void sysfile_shutdown();
142 
143 } // namespace M4
144 
145 #endif
Definition: fileio.h:43
Definition: str.h:59
Definition: path.h:52
Definition: stream.h:745
Definition: fileio.h:49
Definition: sys_file.h:39
Definition: database.h:28
Definition: stream.h:48
Definition: sys_file.h:47
Definition: sys_file.h:31