summaryrefslogtreecommitdiff
path: root/Xenogears/reinsert.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Xenogears/reinsert.cpp')
-rw-r--r--Xenogears/reinsert.cpp86
1 files changed, 48 insertions, 38 deletions
diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp
index 440e444..da23033 100644
--- a/Xenogears/reinsert.cpp
+++ b/Xenogears/reinsert.cpp
@@ -6,8 +6,21 @@
#include "generic.h"
#include "Input.h"
#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso_r(0), f_iso_w(0), f_in(0), cdutil(0), slus_index(-1), force(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso_r;
+ delete f_iso_w;
+ delete f_in;
+}
+private:
-unsigned int tourne = 0;
+unsigned int tourne;
struct t_index_tab {
unsigned long address;
@@ -26,26 +39,23 @@ struct t_sequence {
String title, iso_filename, prefix, in_filename;
unsigned long iso_size;
-unsigned int nb_records, nb_seqs = 0;
+unsigned int nb_records, nb_seqs;
struct t_sequence sequences[1000];
+Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
+cdutils * cdutil;
-int slus_index = -1, force = 0;
-
-long check_iso(Handle * f_iso);
-void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex);
-int process_def_file(Handle * f_def);
+int slus_index, force;
unsigned char user_data[2352];
-void usage(char ** argv) {
+void usage() throw (GeneralException) {
printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n",
argv[0]);
- exit(-1);
+ throw Exit(-1);
}
-int main(int argc, char **argv)
+virtual int startup() throw (GeneralException)
{
- Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
int fileindex;
verbosity = 1;
@@ -53,12 +63,12 @@ int main(int argc, char **argv)
printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n");
if ((argc != 5) && (argc != 6)) {
- usage(argv);
+ usage();
}
if (argc == 6) {
if (strcmp(argv[5], "-f")) {
- usage(argv);
+ usage();
} else {
force = 1;
}
@@ -69,9 +79,8 @@ int main(int argc, char **argv)
f_def = new Input(argv[1]);
if (process_def_file(f_def)) {
- delete f_def;
printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
- exit(-1);
+ throw Exit(-1);
}
iso_filename = argv[2];
@@ -81,10 +90,12 @@ int main(int argc, char **argv)
f_iso_w = new Output(iso_filename, 0, 0);
f_iso_w->seek(0, SEEK_SET);
- if (check_iso(f_iso_r)) {
+ cdutil = new cdutils(f_iso_r, f_iso_w);
+
+ if (check_iso()) {
printm(M_ERROR, "Invalid iso file for " + title + "\n");
printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
- exit(-1);
+ throw Exit(-1);
} else {
printm(M_INFO, "Genuine " + title + " iso detected.\n");
}
@@ -94,10 +105,8 @@ int main(int argc, char **argv)
f_in = new Input(in_filename);
printm(M_STATUS, "Entering files write sequence\n");
- write_files(f_iso_r, f_iso_w, f_in, fileindex);
- delete f_iso_r;
- delete f_iso_w;
- exit(0);
+ write_files(fileindex);
+ return 0;
}
/*
@@ -152,11 +161,11 @@ int process_def_file(Handle * f_def)
}
}
-long check_iso(Handle * f_iso)
+long check_iso()
{
unsigned long length;
- length = f_iso->GetSize();
+ length = f_iso_r->GetSize();
printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
if (length != iso_size) {
return 1;
@@ -166,31 +175,31 @@ long check_iso(Handle * f_iso)
#define INDEXPOS 24
-void rewrite_fat(Handle * f_iso_r, Handle * f_iso_w, Byte * new_fat) {
+void rewrite_fat(Byte * new_fat) {
unsigned char old_fat[34816];
int i;
- sector_seek(f_iso_w, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
printm(M_INFO, "Writing fat sector %lu\n", i);
- write_sector(f_iso_r, f_iso_w, &new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ cdutil->write_sector(&new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
}
- sector_seek(f_iso_r, slus_index + 1);
+ cdutil->sector_seek(slus_index + 1);
for (i = slus_index + 1; i < (slus_index + 18); i++) {
printm(M_INFO, "Reading SLUS sector %lu\n", i);
- read_sector(f_iso_r, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ cdutil->read_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
}
bcopy((char *) new_fat, (char *) old_fat + 4, 32768);
- sector_seek(f_iso_w, slus_index + 1);
+ cdutil->sector_seek(slus_index + 1);
for (i = slus_index + 1; i < (slus_index + 18); i++) {
printm(M_INFO, "Writing SLUS sector %lu\n", i);
- write_sector(f_iso_r, f_iso_w, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ cdutil->write_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
}
}
-void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex)
+void write_files(int fileindex) throw (GeneralException)
{
t_index_tab index_tab[10000];
unsigned char t[8];
@@ -203,10 +212,10 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
long old_file_size, new_file_size, old_nb_sects, new_nb_sects;
unsigned char fat[32768];
- sector_seek(f_iso_r, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
printm(M_INFO, "Reading fat sector %lu\n", i);
- read_sector(f_iso_r, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
}
indexer = 0;
@@ -236,7 +245,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (sequences[seq].prefix == "SLUS") {
if (slus_index >= 0) {
printm(M_ERROR, "Two SLUS files defined\n");
- exit(-1);
+ throw Exit(-1);
}
slus_index = index_tab[i].address;
}
@@ -244,7 +253,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (slus_index < 0) {
printm(M_ERROR, "No SLUS file defined\n");
- exit(-1);
+ throw Exit(-1);
}
printm(M_INFO, "SLUS file found at sector %6i\n", slus_index);
@@ -266,7 +275,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (new_nb_sects > old_nb_sects) {
printm(M_ERROR, "New file too big.\n");
if (!force) {
- exit(-1);
+ throw Exit(-1);
}
}
@@ -275,7 +284,8 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address);
- write_file(f_iso_r, f_iso_w, f_in, index_tab[fileindex].type, index_tab[fileindex].address);
+ cdutil->write_file(f_in, index_tab[fileindex].type, index_tab[fileindex].address);
*((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size;
- rewrite_fat(f_iso_r, f_iso_w, fat);
+ rewrite_fat(fat);
}
+CODE_ENDS