Takes an explicit (not game tree related) path to a pak file. Loads the header and directory, adding the files at the beginning of the list so they override previous pack files.
(String packfile)
| 450 | * list so they override previous pack files. |
| 451 | */ |
| 452 | private static pack_t LoadPackFile(String packfile) { |
| 453 | |
| 454 | dpackheader_t header; |
| 455 | Map<String, packfile_t> newfiles; |
| 456 | RandomAccessFile file; |
| 457 | int numpackfiles; |
| 458 | // unsigned checksum; |
| 459 | // |
| 460 | try { |
| 461 | file = new RandomAccessFile(packfile, "r"); |
| 462 | FileChannel fc = file.getChannel(); |
| 463 | ByteBuffer packhandle = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); |
| 464 | packhandle.order(ByteOrder.LITTLE_ENDIAN); |
| 465 | |
| 466 | fc.close(); |
| 467 | |
| 468 | if (packhandle.limit() < 1) |
| 469 | return null; |
| 470 | |
| 471 | header = new dpackheader_t(packhandle.getInt(), packhandle.getInt(), packhandle.getInt()); |
| 472 | |
| 473 | if (header.ident != IDPAKHEADER) |
| 474 | Com.Error(Defines.ERR_FATAL, packfile + " is not a packfile"); |
| 475 | |
| 476 | numpackfiles = header.dirlen / packfile_t.SIZE; |
| 477 | |
| 478 | if (numpackfiles > MAX_FILES_IN_PACK) |
| 479 | Com.Error(Defines.ERR_FATAL, packfile + " has " + numpackfiles + " files"); |
| 480 | |
| 481 | newfiles = new HashMap<>(numpackfiles); |
| 482 | |
| 483 | packhandle.position(header.dirofs); |
| 484 | |
| 485 | // parse the directory |
| 486 | |
| 487 | byte[] name = new byte[packfile_t.NAME_SIZE]; |
| 488 | |
| 489 | for (int i = 0; i < numpackfiles; i++) { |
| 490 | packhandle.get(name); |
| 491 | packfile_t entry = new packfile_t(new String(name).trim(), packhandle.getInt(), packhandle.getInt()); |
| 492 | newfiles.put(entry.name.toLowerCase(), entry); |
| 493 | } |
| 494 | |
| 495 | } catch (IOException e) { |
| 496 | Com.DPrintf("jake2.qcommon.filesystem.FS.LoadPackFile" + e.getMessage() + '\n'); |
| 497 | return null; |
| 498 | } |
| 499 | |
| 500 | pack_t pack = new pack_t(packfile, numpackfiles, newfiles); |
| 501 | pack.handle = file; |
| 502 | |
| 503 | Com.Printf("Added packfile " + packfile + " (" + numpackfiles + " files)\n"); |
| 504 | |
| 505 | return pack; |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * |