MCPcopy Create free account
hub / github.com/Segs/Segs / loadPigg

Function loadPigg

Projects/CoX/Utilities/MapViewer/src/PiggTools.cpp:99–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99bool loadPigg(const QString &fname,PiggFile &pigg)
100{
101 QFile src_fl(fname);
102 if(!src_fl.open(QFile::ReadOnly))
103 return false;
104 pigg.fname = fname;
105 if(false==readPOD(src_fl,pigg.hdr)) {
106 qDebug() << "file too short";
107 return false;
108 }
109 if(pigg.hdr.pigg_magic!=0x123) {
110 qDebug() << "Bad juju!";
111 return false;
112 }
113 if (pigg.hdr.version > 2)
114 {
115 qDebug() << "File" <<fname<< "has bad pigg version"<<pigg.hdr.version;
116 return false;
117 }
118 if (pigg.hdr.header_size != 0x10)
119 src_fl.seek(src_fl.pos()+pigg.hdr.header_size - 0x10);
120 pigg.headers.resize(pigg.hdr.num_entries);
121 assert(pigg.hdr.used_header_bytes==0x30);
122 for(PiggInternalHeader &in_hdr : pigg.headers ) {
123 readPOD(src_fl,in_hdr);
124 }
125 int idx=0;
126 for(PiggInternalHeader &in_hdr : pigg.headers )
127 {
128 if (in_hdr.flag != 0x3456)
129 {
130 qDebug() << "Bad flag on fileheader #"<<idx;
131 return false;
132 }
133 uint32_t internal_fsize = in_hdr.packed_size ? in_hdr.packed_size : in_hdr.size;
134 if (in_hdr.offset + internal_fsize - 1 > src_fl.size())
135 {
136 qDebug() << "File larger than available pigg data - probably corrupt .pigg file! #"<<idx;
137 return false;
138 }
139 if (in_hdr.name_id < 0)
140 {
141 qDebug() << "Name id is invalid in #"<<idx;
142 return false;
143 }
144 ++idx;
145 }
146 loadDataTable(src_fl,pigg.strings_table);
147 Pigg_DataTable headers_table; // 'headers' table is not used/needed during file listing/extraction operations
148 loadDataTable(src_fl,headers_table);
149 if (pigg.strings_table.datapool_flag != 0x6789)
150 {
151 qDebug() << "Bad string table magic";
152 return false;
153 }
154 if (headers_table.datapool_flag != 0x9ABC) {
155 qDebug() << "Bad headers table magic";
156 return false;

Callers 1

unpackPiggFileFunction · 0.70

Calls 5

readPODFunction · 0.70
loadDataTableFunction · 0.70
openMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected