/*
* Extraction abilities. These work as you expect them to.
*/
-bool pak_extract_one(pak_file_t *pak, const char *file) {
- pak_directory_t *dir = NULL;
- unsigned char *dat = NULL;
+bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) {
+ pak_directory_t *dir = NULL;
+ unsigned char *dat = NULL;
+ char *local = NULL;
FILE *out;
if (!pak_exists(pak, file, &dir)) {
*/
pak_tree_build(file);
+ /* TODO portable path seperators */
+ util_asprintf(&local, "%s/%s", outdir, file);
+
/*
* Now create the file, if this operation fails. Then abort
* It shouldn't fail though.
*/
- if (!(out = fs_file_open(file, "wb"))) {
+ if (!(out = fs_file_open(local, "wb"))) {
mem_d(dat);
return false;
}
+ /* free memory for directory string */
+ mem_d(local);
/* read */
fs_file_seek (pak->handle, dir->pos, SEEK_SET);
if (!fs_dir_make(dir))
return false;
- if (fs_dir_change(dir))
- return false;
-
for (itr = 0; itr < vec_size(pak->directories); itr++) {
- if (!pak_extract_one(pak, pak->directories[itr].name))
+ if (!pak_extract_one(pak, pak->directories[itr].name, dir))
return false;
}
bool extract = true;
char *redirout = (char*)stdout;
char *redirerr = (char*)stderr;
- char *directory = NULL;
char *file = NULL;
char **files = NULL;
pak_file_t *pak = NULL;
continue;
if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false))
continue;
- if (parsecmd("directory", &argc, &argv, &directory, 1, false))
- continue;
if (parsecmd("file", &argc, &argv, &file, 1, false))
continue;
return EXIT_FAILURE;
}
- if (!pak_extract_all(pak, (directory) ? directory : "./")) {
+ if (!pak_extract_all(pak, "./")) {
con_err("failed to extract PAK %s (files may be missing)\n", file);
pak_close(pak);
vec_free(files);
return EXIT_FAILURE;
}
- if (directory && !fs_dir_change(directory)) {
- con_err("failed to change directory %s\n", directory);
- pak_close(pak);
- vec_free(files);
- return EXIT_FAILURE;
- }
-
for (iter = 0; iter < vec_size(files); iter++) {
if (!(pak_insert_one(pak, files[iter]))) {
con_err("failed inserting %s for PAK %s\n", files[iter], file);