[sylverant] r758 committed - Fix a couple of things related to naming of files that are extracted f...

1 view
Skip to first unread message

sylv...@googlecode.com

unread,
Nov 20, 2014, 11:01:09 PM11/20/14
to sylverant-...@googlegroups.com
Revision: 758
Author: blue...@gmail.com
Date: Fri Nov 21 04:00:56 2014 UTC
Log: Fix a couple of things related to naming of files that are
extracted from an AFS archive:

1. Per request, make all extracted files have a .bin extension.
2. Extract to the current directory, not the directory of the .afs file.

https://code.google.com/p/sylverant/source/detail?r=758

Modified:
/trunk/pso_tools/pso_artool/afs.c

=======================================
--- /trunk/pso_tools/pso_artool/afs.c Wed Nov 19 19:43:59 2014 UTC
+++ /trunk/pso_tools/pso_artool/afs.c Fri Nov 21 04:00:56 2014 UTC
@@ -33,6 +33,7 @@
#ifndef _WIN32
#include <unistd.h>
#include <inttypes.h>
+#include <libgen.h>
#endif

static uint8_t xbuf[512];
@@ -54,6 +55,11 @@
long wpos;
};

+#ifdef _WIN32
+/* In windows_compat.c */
+char *basename(char *input);
+#endif
+
static int digits(uint32_t n) {
int r = 1;
while(n /= 10) ++r;
@@ -322,16 +328,16 @@
size_t len = strlen(fn);
FILE *ofp;
#ifndef _WIN32
- char ofn[len + 12];
+ char ofn[len + 20];
#else
char ofn[256];
#endif

/* Open the output file. */
#ifndef _WIN32
- snprintf(ofn, len + 12, "%s.%0*" PRIu32, fn, dg, i);
+ snprintf(ofn, len + 20, "%s.%0*" PRIu32 ".bin", fn, dg, i);
#else
- sprintf_s(ofn, 256, "%s.%0*d", fn, dg, i);
+ sprintf_s(ofn, 256, "%s.%0*d.bin", fn, dg, i);
#endif

if(!(ofp = fopen(ofn, "wb"))) {
@@ -949,5 +955,19 @@
}

int extract_afs(const char *fn) {
- return scan_afs(fn, &extract_file, (void *)fn);
+ char *fnc, *bn;
+ int rv;
+
+ /* Figure out the basename of the file. */
+ if(!(fnc = strdup(fn)))
+ return -1;
+
+ if(!(bn = basename(fnc))) {
+ free(fnc);
+ return -2;
+ }
+
+ rv = scan_afs(fn, &extract_file, (void *)bn);
+ free(fnc);
+ return rv;
}
Reply all
Reply to author
Forward
0 new messages