From 5b755a10195cfc2f4f775b1e2fc852801eafce04 Mon Sep 17 00:00:00 2001 From: Mike Goslin Date: Tue, 10 Oct 2000 22:07:45 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/downloadertools/multify.cxx | 19 ++++++++++++++----- panda/src/express/multifile.cxx | 21 +++++++++++---------- panda/src/express/multifile.h | 6 +++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/panda/src/downloadertools/multify.cxx b/panda/src/downloadertools/multify.cxx index 308464e59f..40153a24d6 100644 --- a/panda/src/downloadertools/multify.cxx +++ b/panda/src/downloadertools/multify.cxx @@ -19,7 +19,8 @@ main(int argc, char *argv[]) { extern char *optarg; extern int optind; - int flag = getopt(argc, argv, "x:c:v"); + int flag = getopt(argc, argv, "xcvr:"); + Filename rel_path; while (flag != EOF) { switch (flag) { case 'x': @@ -30,16 +31,24 @@ main(int argc, char *argv[]) { case 'v': verbose = true; break; + case 'r': + rel_path = optarg; + break; default: cerr << "Unhandled switch: " << flag << endl; break; } - flag = getopt(argc, argv, "x:c:v"); + flag = getopt(argc, argv, "xcvr:"); } argc -= (optind - 1); argv += (optind - 1); - Filename dest_file = argv[0]; + if (argc <= 1) { + cerr << "Usage: multify -[x,c|v] ..." << endl; + return 0; + } + + Filename dest_file = argv[1]; dest_file.set_binary(); if (verbose == true) { @@ -52,7 +61,7 @@ main(int argc, char *argv[]) { Multifile mfile; if (extract == false) { - for (int i = 1; i < argc; i++) { + for (int i = 2; i < argc; i++) { Filename in_file = argv[i]; in_file.set_binary(); mfile.add(in_file); @@ -62,7 +71,7 @@ main(int argc, char *argv[]) { cerr << "Failed to write: " << dest_file << endl; } else { mfile.read(dest_file); - mfile.extract_all(); + mfile.extract_all(rel_path); } return 1; diff --git a/panda/src/express/multifile.cxx b/panda/src/express/multifile.cxx index 438339b820..23fb14dbe1 100644 --- a/panda/src/express/multifile.cxx +++ b/panda/src/express/multifile.cxx @@ -233,19 +233,20 @@ read_from_multifile(ifstream &read_stream) { // Description: Writes to a individual file //////////////////////////////////////////////////////////////////// bool Multifile::Memfile:: -write(void) { +write(const Filename &rel_path) { ofstream write_stream; - _name.set_binary(); - _name.make_dir(); - if (!_name.open_write(write_stream)) { + Filename name = rel_path.get_fullpath() + _name.get_fullpath(); + name.set_binary(); + name.make_dir(); + if (!name.open_write(write_stream)) { express_cat.error() << "Multifile::Memfile::write() - Failed to open output file: " - << _name << endl; + << name << endl; return false; } express_cat.debug() - << "Writing to file: " << _name << endl; + << "Writing to file: " << name << endl; write_stream.write(_buffer, _buffer_length); return true; @@ -607,11 +608,11 @@ reset(void) { // Description: //////////////////////////////////////////////////////////////////// bool Multifile:: -extract(const Filename &name) { +extract(const Filename &name, const Filename &rel_path) { MemfileList::iterator found; found = find_if(_files.begin(), _files.end(), MemfileMatch(name)); if (found != _files.end()) { - (*found)->write(); + (*found)->write(rel_path); return true; } return false; @@ -623,11 +624,11 @@ extract(const Filename &name) { // Description: //////////////////////////////////////////////////////////////////// void Multifile:: -extract_all(void) { +extract_all(const Filename &rel_path) { express_cat.debug() << "Multifile::extract_all() - Extracting all files" << endl; MemfileList::iterator i; for (i = _files.begin(); i != _files.end(); ++i) - (*i)->write(); + (*i)->write(rel_path); } diff --git a/panda/src/express/multifile.h b/panda/src/express/multifile.h index bf1e794379..5cb43dc34d 100644 --- a/panda/src/express/multifile.h +++ b/panda/src/express/multifile.h @@ -45,8 +45,8 @@ public: bool write(Filename name); bool write(char *&start, int &size); bool write_extract(char *&start, int &size); - bool extract(const Filename &name); - void extract_all(void); + bool extract(const Filename &name, const Filename &rel_path = ""); + void extract_all(const Filename &rel_path = ""); void reset(void); bool parse_header(char *&start, int &size); @@ -64,7 +64,7 @@ private: bool read(const Filename &name); bool read_from_multifile(ifstream &read_stream); - bool write(void); + bool write(const Filename &rel_path); void write_to_multifile(ofstream &write_stream); bool write(char *&start, int &size); void reset(void);