25 #include <sys/types.h>
36 #if BYTE_ORDER == BIG_ENDIAN
37 #define INT_SWAP(x) ( \
39 (((ulong)x) >> 24) | \
40 ((x & 0x0000ff00) << 8) | \
41 ((x & 0x00ff0000) >> 8) \
44 #define INT_SWAP(x) (x)
56 #define BLOCK_SIZE (1024*1024)
60 static int have_index = 0;
61 static int have_header = 0;
63 #define ERR_NO_FP_IN 0
64 #define ERR_NO_FP_OUT 1
65 #define ERR_INVALID_VP 2
66 #define ERR_NO_INDEX 3
67 #define ERR_NO_HEADER 4
68 #define ERR_PATH_TOO_LONG 5
126 printf(
"ERROR: The input file (fp_in) is NULL! Exiting...\n");
129 printf(
"ERROR: The output file (fp_out) is NULL! Exiting...\n");
132 printf(
"ERROR: The specified VP file is invalid! Exiting...\n");
135 printf(
"ERROR: No file index is available! Exiting...\n");
138 printf(
"ERROR: No file header is available! Exiting...\n");
141 printf(
"ERROR: Path to output directory is too long! Exiting...\n");
152 fseek(
fp_in, 0, SEEK_SET);
153 fread(&VP_Header.
id, 1, 4,
fp_in);
163 if ( (VP_Header.
id[0] !=
'V') && (VP_Header.
id[1] !=
'P') && (VP_Header.
id[2] !=
'V') && (VP_Header.
id[3] !=
'P') )
178 else if (!have_header)
188 for ( i = 0; i < VP_Header.
num_files; i++) {
228 VP_FileInfo.push_back(vpinfo);
239 else if (!have_header)
241 else if (!have_index)
244 int status, m_error, nbytes, nbytes_remaining;
248 ubyte have_outdir = 0;
255 printf(
"VP file extractor - version 0.6\n");
259 printf(
"Output directory: \"%s\"\n",
out_dir);
262 printf(
"Extracting: %s...\n", file);
264 for (
size_t i = 0;
i < VP_FileInfo.size();
i++) {
267 if ( (out_len + 1 + strlen(path)) >
MAX_PATH-1 )
286 status = mkdir(path, 0777);
291 if (status && (m_error != EEXIST) ) {
292 printf(
"Cannot mkdir %s: %s\n", VP_FileInfo[
i].file_path, strerror(m_error));
309 if ( (out_len + 1 + strlen(path)) >
MAX_PATH-1 )
317 fp_out = fopen(path2,
"wb");
319 printf(
" %s ... ", path);
322 printf(
"can't create file!\n");
326 nbytes_remaining = VP_FileInfo[
i].file_size;
328 while ( nbytes_remaining > 0 ) {
333 nbytes_remaining -= nbytes;
350 float one_k = 1024.0f;
351 float one_m = 1048576.0f;
361 printf(
"VP file extractor - version 0.6\n");
363 printf(
"%s:\n", file);
366 printf(
" Name Size Offset Date/Time Path\n");
367 printf(
"-------------------------------------------------------------------------------\n");
368 for (
size_t i = 0;
i < VP_FileInfo.size();
i++) {
369 plat_time = VP_FileInfo[
i].write_time;
370 strftime(out_time, 32,
"%F %H:%M", localtime(&plat_time));
372 if (VP_FileInfo[
i].file_size > (
int)one_m) {
380 int len = strlen( VP_FileInfo[
i].file_name );
381 printf(
"%s %*.1f%c %10i %18s %3s%s\n", VP_FileInfo[
i].file_name, 33 - len, (
float)VP_FileInfo[
i].file_size/div_by, m, VP_FileInfo[
i].
offset, out_time,
DIR_SEPARATOR_STR, VP_FileInfo[
i].file_path);
389 printf(
"Total files: %i\n", (
int)VP_FileInfo.size());
400 printf(
"Total size: %.1f%c\n", (
float)VP_Header.
index_offset/div_by, m);
407 printf(
"VP file extractor - version 0.6\n");
409 printf(
"Usage: cfileextractor [-x | -l] [-L] [-o <dir>] <vp_filename>\n");
411 printf(
" Commands (only one at the time):\n");
412 printf(
" -x | --extract Extract all files into current directory.\n");
413 printf(
" -l | --list List all files in VP archive.\n");
414 printf(
" -h | --help Show this help text.\n");
416 printf(
" Options:\n");
417 printf(
" -L | --lowercase Force all filenames to be lower case.\n");
418 printf(
" -o <dir> Extract files to <dir> instead of current directory.\n");
419 printf(
" NOTE: No spaces allowed, enclose path in \" \" if needed.\n");
421 printf(
" (No command specified will list all files in the VP archive.)\n");
431 int main(
int argc,
char *argv[])
433 int extract = 0, lc = 0, list = 0;
440 if (!strcmp(argv[1],
"-h") || !strcmp(argv[1],
"--help")) {
446 fp_in = fopen(argv[argc-1],
"rb");
457 for (
int i = 1;
i < argc-1;
i++) {
458 if (!strcmp(argv[
i],
"-x") || !strcmp(argv[i],
"--extract")) {
464 }
else if (!strcmp(argv[i],
"-L") || !strcmp(argv[i],
"--lowercase")) {
466 }
else if (!strcmp(argv[i],
"-l") || !strcmp(argv[i],
"--list")) {
472 }
else if ( !strcmp(argv[i],
"-o") && (i+1 < argc) && (argv[i+1][0] !=
'-') ) {
#define DIR_SEPARATOR_CHAR
char file_path[CF_MAX_PATHNAME_LENGTH]
#define CF_MAX_PATHNAME_LENGTH
int _mkdir(const char *path)
#define DIR_SEPARATOR_STR
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
GLsizei const GLchar ** path
#define CF_MAX_FILENAME_LENGTH
char file_name[CF_MAX_FILENAME_LENGTH]