diff options
Diffstat (limited to 'Xenogears/main_dump.cpp')
-rw-r--r-- | Xenogears/main_dump.cpp | 148 |
1 files changed, 62 insertions, 86 deletions
diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp index fa61db5..60c15df 100644 --- a/Xenogears/main_dump.cpp +++ b/Xenogears/main_dump.cpp @@ -28,9 +28,10 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> -#include "fileutils.h" #include "cdutils.h" #include "generic.h" +#include "Input.h" +#include "Output.h" unsigned int tourne = 0; @@ -44,48 +45,45 @@ struct t_index_tab { struct t_sequence { unsigned int n; unsigned int sum; - char *prefix; - char *name; + String prefix; + String name; int type; }; -char *title, *iso_filename, *prefix; +String title, iso_filename, prefix; unsigned long iso_size; unsigned int nb_records, nb_seqs = 0; struct t_sequence sequences[1000]; -long check_iso(int f_iso); -void read_files(int f_iso); -void file_dump(int f_iso, unsigned long debut, unsigned long taille, long num, int seq); -int process_def_file(int f_def); +long check_iso(Handle * f_iso); +void read_files(Handle * f_iso); +void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq); +int process_def_file(Handle * f_def); -unsigned char user_data[2352]; +Byte user_data[2352]; int main(int argc, char **argv) { - int f_def, f_iso; + Handle * f_def, * f_iso; verbosity = 3; - fprintf(stderr, + printm(M_BARE, "Xenogears File Extractor by Nicolas \"Pixel\" Noble\n" "Highly based upon the Chrono Cross File Extractor By Yazoo\n\n"); if (argc != 3) { - fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", + printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", argv[0]); exit(-1); } printm(M_STATUS, "Processing file %s...\n", argv[1]); - if ((f_def = open(argv[1], O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open the definition file \"%s\"...\n", argv[1]); - exit(-1); - } + f_def = new Input(argv[1]); if (process_def_file(f_def)) { - close(f_def); + delete f_def; printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); exit(-1); } @@ -93,55 +91,47 @@ int main(int argc, char **argv) iso_filename = argv[2]; printm(M_STATUS, "Begin processing iso file.\n"); - if ((f_iso = open(iso_filename, O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); - exit(-1); - } + f_iso = new Input(iso_filename); if (check_iso(f_iso)) { - printm(M_ERROR, "Invalid iso file for %s\n", title); + printm(M_ERROR, "Invalid iso file for " + title + "\n"); printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); } else { - printm(M_INFO, "Genuine %s iso detected.\n", title); + printm(M_INFO, "Genuine " + title + " iso detected.\n"); } printm(M_STATUS, "Entering files read sequence\n"); read_files(f_iso); - close(f_iso); + delete f_iso; exit(0); } /* * Ugly but working... for now */ -int process_def_file(int h_f_def) +int process_def_file(Handle * f_def) { - char t[1024], *p; + String t; unsigned int n, sum = 0; - FILE * f_def = fdopen(h_f_def, "r"); - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - printm(M_INFO, "Read title: %s\n", t); - title = strdup(t); + *f_def >> t; + printm(M_INFO, "Read title: " + t + "\n"); + title = t; - if (fscanf(f_def, "%lu\n", &iso_size) != 1) - return 1; + *f_def >> t; + iso_size = t.to_int(); printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - printm(M_INFO, "Read global directory prefix: %s\n", t); - prefix = strdup(t); + *f_def >> t; + printm(M_INFO, "Read global directory prefix: " + t + "\n"); + prefix = t; - if (fscanf(f_def, "%u\n", &nb_records) != 1) - return 1; + *f_def >> t; + nb_records = t.to_int(); printm(M_INFO, "Read total of records: %u\n", nb_records); while (1) { - if (fscanf(f_def, "%u\n", &n) != 1) - return 1; + *f_def >> t; + n = t.to_int(); if (!n) { if (sum == nb_records) { printm(M_INFO, "Definition file seems coherent\n"); @@ -154,36 +144,32 @@ int process_def_file(int h_f_def) sum += n; sequences[nb_seqs].n = n; sequences[nb_seqs].sum = sum; - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - sequences[nb_seqs].prefix = strdup(t); - if (fscanf(f_def, "%u\n", &n) != 1) - return 1; + *f_def >> t; + sequences[nb_seqs].prefix = t; + *f_def >> t; + n = t.to_int(); sequences[nb_seqs].type = n; - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - sequences[nb_seqs].name = strdup(t); - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of %s (%s)\n", - nb_seqs, n, sum, t, sequences[nb_seqs].prefix); + *f_def >> t; + sequences[nb_seqs].name = t; + printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t + + " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum); nb_seqs++; } } -long check_iso(int f_iso) +long check_iso(Handle * f_iso) { unsigned long length; - length = filesize(f_iso); - printm(M_INFO, "Filesize of iso file %s is %ld bytes\n", iso_filename, length); + length = f_iso->GetSize(); + printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); if (length != iso_size) { return 1; } return 0; } -void read_files(int f_iso) +void read_files(Handle * f_iso) { t_index_tab index_tab[10000]; unsigned char t[8]; @@ -193,7 +179,7 @@ void read_files(int f_iso) unsigned long indexer; struct t_index_tab *p = (struct t_index_tab *) t; - unsigned char fat[32768]; + Byte fat[32768]; #define INDEXPOS 24 @@ -240,39 +226,29 @@ void read_files(int f_iso) fprintf(stderr, "\n"); } -void file_dump(int f_iso, unsigned long debut, unsigned long taille, long num, int seq) +void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq) { long i; long nbsects; - char nom[1000] = ""; - char *extention = ".out"; - char nom_t[1000] = ""; - int f_out; + String nom; + String extension = ".out"; + String nom_t; + Handle * f_out; char type = sequences[seq].type; char ptitbidule[] = "-\\|/"; - sprintf(nom_t, "%ld", num); + nom_t.set("%04ld", num); - strcat(nom, "./"); + nom = "./" + prefix + "/"; - strcat(nom, prefix); - strcat(nom, "/"); - MKDIR(nom); + MKDIR(nom.to_charp()); - strcat(nom, sequences[seq].prefix); - strcat(nom, "/"); - MKDIR(nom); + nom += sequences[seq].prefix + "/"; + MKDIR(nom.to_charp()); - if (num < 10) - strcat(nom, "0"); - if (num < 100) - strcat(nom, "0"); - if (num < 1000) - strcat(nom, "0"); - strcat(nom, nom_t); + nom += nom_t + extension;; - strcat(nom, extention); - f_out = open(nom, O_WRONLY | O_CREAT | O_TRUNC, 00644); + f_out = new Output(nom); nbsects = taille / sec_sizes[type]; if (taille % sec_sizes[type]) nbsects++; @@ -282,11 +258,11 @@ void file_dump(int f_iso, unsigned long debut, unsigned long taille, long num, i fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); read_sector(f_iso, user_data, type); if (i != (nbsects - 1)) { - write(f_out, user_data, sec_sizes[type]); + f_out->write(user_data, sec_sizes[type]); } else { - write(f_out, user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); + f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); } } - close(f_out); - fprintf(stderr, " (*) Dumped file number %4ld - type \"%s\" \r", num, sequences[seq].name); + delete f_out; + printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); } |