Skip to content

Commit 1ee8cdc

Browse files
pseilermmozeiko
authored andcommitted
Added support for listing the output file
Added information about listing parameter in README.md
1 parent d4bda8a commit 1ee8cdc

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ If you don't have zRIF fake license, but just want to unpack files, then omit la
4242

4343
Resulting zip file will not include work.bin. This is useful for patch pkg files.
4444

45+
To get output file name of the zip, use `-l` (must come before pkg file and cannot be used with `-x`):
46+
47+
pkg2zip -l package.pkg
48+
4549
To avoid zipping process and create individual files, use `-x` argument (must come before pkg file):
4650

4751
pkg2zip -x package.pkg [zRIF_STRING]

pkg2zip.c

+48-10
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ typedef enum {
272272
int main(int argc, char* argv[])
273273
{
274274
sys_output_init();
275-
sys_output("pkg2zip v1.8\n");
276275

277276
int zipped = 1;
277+
int listing = 0;
278278
int cso = 0;
279279
const char* pkg_arg = NULL;
280280
const char* zrif_arg = NULL;
@@ -284,6 +284,10 @@ int main(int argc, char* argv[])
284284
{
285285
zipped = 0;
286286
}
287+
else if (strcmp(argv[i], "-l") == 0)
288+
{
289+
listing = 1;
290+
}
287291
else if (strncmp(argv[i], "-c", 2) == 0)
288292
{
289293
if (argv[i][2] != 0)
@@ -305,14 +309,20 @@ int main(int argc, char* argv[])
305309
}
306310
}
307311
}
308-
312+
if (listing == 0)
313+
{
314+
sys_output("pkg2zip v1.8\n");
315+
}
309316
if (pkg_arg == NULL)
310317
{
311318
fprintf(stderr, "ERROR: no pkg file specified\n");
312-
sys_error("Usage: %s [-x] [-c[N]] file.pkg [zRIF]\n", argv[0]);
319+
sys_error("Usage: %s [-x] [-l] [-c[N]] file.pkg [zRIF]\n", argv[0]);
313320
}
314321

315-
sys_output("[*] loading...\n");
322+
if (listing == 0)
323+
{
324+
sys_output("[*] loading...\n");
325+
}
316326

317327
uint64_t pkg_size;
318328
sys_file pkg = sys_open(pkg_arg, &pkg_size);
@@ -496,39 +506,67 @@ int main(int argc, char* argv[])
496506
type_str = content_type == 0xe ? "PSP-Go" : content_type == 0xf ? "PSP-Mini" : "PSP-NeoGeo";
497507
}
498508
snprintf(root, sizeof(root), "%s [%.9s] [%s]%s", title, id, type_str, ext);
499-
sys_output("[*] unpacking %s\n", type_str);
509+
if (listing == 0)
510+
{
511+
sys_output("[*] unpacking %s\n", type_str);
512+
}
500513
}
501514
else if (type == PKG_TYPE_PSX)
502515
{
503516
snprintf(root, sizeof(root), "%s [%.9s] [PSX]%s", title, id, ext);
504-
sys_output("[*] unpacking PSX\n");
517+
if (listing == 0)
518+
{
519+
sys_output("[*] unpacking PSX\n");
520+
}
505521
}
506522
else if (type == PKG_TYPE_VITA_DLC)
507523
{
508524
snprintf(root, sizeof(root), "%s [%.9s] [%s] [DLC-%s]%s", title, id, get_region(id), id2, ext);
509-
sys_output("[*] unpacking Vita DLC\n");
525+
if (listing == 0)
526+
{
527+
sys_output("[*] unpacking Vita DLC\n");
528+
}
510529
}
511530
else if (type == PKG_TYPE_VITA_PATCH)
512531
{
513532
snprintf(root, sizeof(root), "%s [%.9s] [%s] [PATCH] [v%s]%s", title, id, get_region(id), pkg_version, ext);
514-
sys_output("[*] unpacking Vita PATCH\n");
533+
if (listing == 0)
534+
{
535+
sys_output("[*] unpacking Vita PATCH\n");
536+
}
515537
}
516538
else if (type == PKG_TYPE_VITA_PSM)
517539
{
518540
snprintf(root, sizeof(root), "%.9s [%s] [PSM]%s", id, get_region(id), ext);
519-
sys_output("[*] unpacking Vita PSM\n");
541+
if (listing == 0)
542+
{
543+
sys_output("[*] unpacking Vita PSM\n");
544+
}
520545
}
521546
else if (type == PKG_TYPE_VITA_APP)
522547
{
523548
snprintf(root, sizeof(root), "%s [%.9s] [%s]%s", title, id, get_region(id), ext);
524-
sys_output("[*] unpacking Vita APP\n");
549+
if (listing == 0)
550+
{
551+
sys_output("[*] unpacking Vita APP\n");
552+
}
525553
}
526554
else
527555
{
528556
assert(0);
529557
sys_error("ERROR: unsupported type\n");
530558
}
531559

560+
if (listing && zipped)
561+
{
562+
sys_output("%s\n", root);
563+
exit(0);
564+
}
565+
else if (listing || zipped)
566+
{
567+
sys_error("ERROR: Listing option without creating zip is useless\n");
568+
}
569+
532570
if (zipped)
533571
{
534572
sys_output("[*] creating '%s' archive\n", root);

0 commit comments

Comments
 (0)