Load the packets from the specified file
| 330 | |
| 331 | // Load the packets from the specified file |
| 332 | bool Par2Repairer::LoadPacketsFromFile(std::string filename) |
| 333 | { |
| 334 | // Skip the file if it has already been processed |
| 335 | if (diskFileMap.Find(filename) != 0) |
| 336 | { |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | DiskFile *diskfile = new DiskFile(sout, serr); |
| 341 | |
| 342 | // Open the file |
| 343 | if (!diskfile->Open(filename)) |
| 344 | { |
| 345 | // If we could not open the file, ignore the error and |
| 346 | // proceed to the next file |
| 347 | delete diskfile; |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | if (noiselevel > nlSilent) |
| 352 | { |
| 353 | std::string path; |
| 354 | std::string name; |
| 355 | DiskFile::SplitFilename(filename, path, name); |
| 356 | sout << "Loading \"" << name << "\"." << std::endl; |
| 357 | } |
| 358 | |
| 359 | // How many useable packets have we found |
| 360 | u32 packets = 0; |
| 361 | |
| 362 | // How many recovery packets were there |
| 363 | u32 recoverypackets = 0; |
| 364 | |
| 365 | // How big is the file |
| 366 | u64 filesize = diskfile->FileSize(); |
| 367 | if (filesize > 0) |
| 368 | { |
| 369 | // Allocate a buffer to read data into |
| 370 | // The buffer should be large enough to hold a whole |
| 371 | // critical packet (i.e. file verification, file description, main, |
| 372 | // and creator), but not necessarily a whole recovery packet. |
| 373 | size_t buffersize = (size_t)std::min((u64)1048576, filesize); |
| 374 | u8 *buffer = new u8[buffersize]; |
| 375 | |
| 376 | // Progress indicator |
| 377 | u64 progress = 0; |
| 378 | |
| 379 | // Start at the beginning of the file |
| 380 | u64 offset = 0; |
| 381 | |
| 382 | // Continue as long as there is at least enough for the packet header |
| 383 | while (offset + sizeof(PACKET_HEADER) <= filesize) |
| 384 | { |
| 385 | if (noiselevel > nlQuiet) |
| 386 | { |
| 387 | // Update a progress indicator |
| 388 | u32 oldfraction = (u32)(1000 * progress / filesize); |
| 389 | u32 newfraction = (u32)(1000 * offset / filesize); |