summaryrefslogtreecommitdiff
path: root/VP/main_dump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'VP/main_dump.cpp')
-rw-r--r--VP/main_dump.cpp140
1 files changed, 54 insertions, 86 deletions
diff --git a/VP/main_dump.cpp b/VP/main_dump.cpp
index 21b5201..0845e1a 100644
--- a/VP/main_dump.cpp
+++ b/VP/main_dump.cpp
@@ -28,9 +28,11 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include "fileutils.h"
#include "cdutils.h"
#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "String.h"
unsigned int tourne = 0;
@@ -44,26 +46,26 @@ 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(FILE * f_iso);
-void read_files(FILE * f_iso);
-void file_dump(FILE * f_iso, unsigned long debut, unsigned long taille, long num, int seq);
-int process_def_file(FILE * 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];
int main(int argc, char **argv)
{
- FILE * f_def, * f_iso;
+ Handle * f_def, * f_iso;
verbosity = M_STATUS;
@@ -79,13 +81,10 @@ int main(int argc, char **argv)
printm(M_STATUS, "Processing file %s...\n", argv[1]);
- if (!(f_def = fopen(argv[1], "r"))) {
- 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)) {
- fclose(f_def);
+ delete f_def;
printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
exit(-1);
}
@@ -93,54 +92,45 @@ int main(int argc, char **argv)
iso_filename = argv[2];
printm(M_STATUS, "Begin processing iso file.\n");
- if (!(f_iso = fopen(iso_filename, "r"))) {
- 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);
- fclose(f_iso);
+ delete f_iso;
exit(0);
}
/*
* Ugly but working... for now
*/
-int process_def_file(FILE * f_def)
+int process_def_file(Handle * f_def)
{
- char t[1024], *p;
+ String t;
unsigned int n, sum = 0;
- 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 >> title;
+ printm(M_INFO, "Read title: " + title + "\n");
- 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 >> prefix;
+ printm(M_INFO, "Read global directory prefix: " + prefix + "\n");
- 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");
@@ -153,36 +143,29 @@ int process_def_file(FILE * 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;
- 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 >> sequences[nb_seqs].prefix;
+ *f_def >> t;
+ sequences[nb_seqs].type = t.to_int();
+ *f_def >> sequences[nb_seqs].name;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n",
+ nb_seqs, n, sum);
nb_seqs++;
}
}
-long check_iso(FILE * 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(FILE * f_iso)
+void read_files(Handle * f_iso)
{
t_index_tab index_tab[10000];
unsigned long i;
@@ -228,7 +211,7 @@ void read_files(FILE * f_iso)
}
}
printm(M_STATUS, "Index file generation complete.\n\n");
- index_tab[indexer].address = filesize(f_iso) / 2352;
+ index_tab[indexer].address = f_iso->GetSize() / 2352;
for (i = 0; i < nb_records; i++) {
if (sequences[seq].sum == i)
@@ -250,39 +233,24 @@ void read_files(FILE * f_iso)
fprintf(stderr, "\n");
}
-void file_dump(FILE * 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;
+ Handle * f_out;
char type = sequences[seq].type;
char ptitbidule[] = "-\\|/";
- sprintf(nom_t, "%ld", num);
-
- strcat(nom, "./");
+ nom = "./" + prefix + "/";
+ MKDIR(nom.to_charp());
- strcat(nom, prefix);
- strcat(nom, "/");
- MKDIR(nom);
-
- strcat(nom, sequences[seq].prefix);
- strcat(nom, "/");
- MKDIR(nom);
-
- if (num < 10)
- strcat(nom, "0");
- if (num < 100)
- strcat(nom, "0");
- if (num < 1000)
- strcat(nom, "0");
- strcat(nom, nom_t);
+ nom += sequences[seq].prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += String("%04ld.out", num);
- 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++;
@@ -292,11 +260,11 @@ void file_dump(FILE * f_iso, unsigned long debut, unsigned long taille, long num
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);
}