diff --git a/include/QF/pakfile.h b/include/QF/pakfile.h index 442f8f8be..d172f302d 100644 --- a/include/QF/pakfile.h +++ b/include/QF/pakfile.h @@ -52,6 +52,7 @@ typedef struct pack_s { pack_t *pack_new (const char *name); void pack_del (pack_t *pack); +void pack_rehash (pack_t *pack); pack_t *pack_open (const char *name); void pack_close (pack_t *pack); pack_t *pack_create (const char *name); diff --git a/libs/util/pakfile.c b/libs/util/pakfile.c index 22e01c5e0..ffb53edfe 100644 --- a/libs/util/pakfile.c +++ b/libs/util/pakfile.c @@ -88,6 +88,16 @@ pack_del (pack_t *pack) free (pack); } +void +pack_rehash (pack_t *pack) +{ + int i; + + for (i = 0; i < pack->numfiles; i++) { + Hash_Add (pack->file_hash, &pack->files[i]); + } +} + pack_t * pack_open (const char *name) { diff --git a/tools/pak/pak.c b/tools/pak/pak.c index 276beb2ab..12e3dc010 100644 --- a/tools/pak/pak.c +++ b/tools/pak/pak.c @@ -151,7 +151,8 @@ int main (int argc, char **argv) { pack_t *pack; - int i; + int i, j, rehash = 0; + dpackfile_t *pf; this_program = argv[0]; @@ -172,9 +173,35 @@ main (int argc, char **argv) return 1; } for (i = 0; i < pack->numfiles; i++) { - if (options.verbosity > 0) - printf ("%s\n", pack->files[i].name); - pack_extract (pack, &pack->files[i]); + pf = &pack->files[i]; + for (j = 0; j < PAK_PATH_LENGTH; j++) { + if (!pf->name[j]) + break; + if (pf->name[j] == '\\') { + pf->name[j] = '/'; + rehash = 1; + } + } + if (optind == argc) { + if (options.verbosity > 0) + printf ("%s\n", pf->name); + pack_extract (pack, pf); + } + } + if (optind < argc) { + if (rehash) + pack_rehash (pack); + while (optind < argc) { + pf = pack_find_file (pack, argv[optind]); + if (!pf) { + fprintf (stderr, "could not file %s\n", argv[optind]); + continue; + } + if (options.verbosity > 0) + printf ("%s\n", pf->name); + pack_extract (pack, pf); + optind++; + } } pack_close (pack); break;