MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / ExtractVIV

Function ExtractVIV

src/Util/Utils.cpp:190–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188 }
189
190 bool ExtractVIV(const std::string &viv_path, const std::string &output_dir) {
191 LOG(INFO) << "Extracting VIV file: " << viv_path << " to " << output_dir;
192 FILE *vivfile, *outfile; // file stream
193 int numberOfFiles; // number of files in viv file
194 char filename[100];
195 int filepos, filesize;
196 char buf[4];
197 int c;
198 int pos;
199 long currentpos;
200 int a, b;
201
202 if(boost::filesystem::exists(output_dir)){
203 LOG(INFO) << "VIV has already been extracted. Skipping.";
204 return true;
205 } else {
206 boost::filesystem::create_directories(output_dir);
207 }
208
209 vivfile = fopen(viv_path.c_str(), "rb");
210
211 if (!vivfile) {
212 LOG(WARNING) << "Error while opening " << viv_path;
213 return false;
214 }
215
216 for (a = 0; a < 4; a++) {
217 buf[a] = fgetc(vivfile);
218 }
219
220 if (memcmp(buf, "BIGF", 4)) {
221 LOG(WARNING) << "Not a valid VIV file (BIGF header missing)";
222 fclose(vivfile);
223 return false;
224 }
225
226 readInt32(vivfile, false); // size of viv file
227
228 numberOfFiles = readInt32(vivfile, false);
229 LOG(INFO) << "VIV contains " << numberOfFiles << " files";
230
231 int startPos = readInt32(vivfile, false); // start position of files
232
233 currentpos = ftell(vivfile);
234
235 for (a = 0; a < numberOfFiles; a++) {
236 if (fseek(vivfile, currentpos, SEEK_SET)) {
237 LOG(WARNING) << "Error while seeking in file.";
238 fclose(vivfile);
239 return false;
240 }
241
242 filepos = readInt32(vivfile, false);
243 filesize = readInt32(vivfile, false);
244
245 pos = 0;
246 c = fgetc(vivfile);
247 while (c != '\0') {

Callers 2

LoadCarMethod · 0.85
LoadCarMethod · 0.85

Calls 1

readInt32Function · 0.85

Tested by

no test coverage detected