*** empty log message ***

This commit is contained in:
Joe Shochet 2001-04-12 18:33:27 +00:00
parent 6bdce752d7
commit b601b49c80
3 changed files with 89 additions and 86 deletions

View File

@ -85,7 +85,7 @@ get_client_multifile_size(string mfname) const {
INLINE void DownloadDb:: INLINE void DownloadDb::
set_client_multifile_size(string mfname, int size) { set_client_multifile_size(string mfname, int size) {
(_client_db.get_multifile_record_named(mfname))->_size = size; (_client_db.get_multifile_record_named(mfname))->_size = size;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
} }
@ -97,7 +97,7 @@ set_client_multifile_size(string mfname, int size) {
INLINE int DownloadDb:: INLINE int DownloadDb::
set_client_multifile_delta_size(string mfname, int size) { set_client_multifile_delta_size(string mfname, int size) {
(_client_db.get_multifile_record_named(mfname))->_size += size; (_client_db.get_multifile_record_named(mfname))->_size += size;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
// Return the new total // Return the new total
return (_client_db.get_multifile_record_named(mfname))->_size; return (_client_db.get_multifile_record_named(mfname))->_size;
} }
@ -134,7 +134,7 @@ set_server_multifile_size(string mfname, int size) {
INLINE void DownloadDb:: INLINE void DownloadDb::
set_client_multifile_incomplete(string mfname) { set_client_multifile_incomplete(string mfname) {
(_client_db.get_multifile_record_named(mfname))->_status = Status_incomplete; (_client_db.get_multifile_record_named(mfname))->_status = Status_incomplete;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -145,7 +145,7 @@ set_client_multifile_incomplete(string mfname) {
INLINE void DownloadDb:: INLINE void DownloadDb::
set_client_multifile_complete(string mfname) { set_client_multifile_complete(string mfname) {
(_client_db.get_multifile_record_named(mfname))->_status = Status_complete; (_client_db.get_multifile_record_named(mfname))->_status = Status_complete;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -156,7 +156,7 @@ set_client_multifile_complete(string mfname) {
INLINE void DownloadDb:: INLINE void DownloadDb::
set_client_multifile_decompressed(string mfname) { set_client_multifile_decompressed(string mfname) {
(_client_db.get_multifile_record_named(mfname))->_status = Status_decompressed; (_client_db.get_multifile_record_named(mfname))->_status = Status_decompressed;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -167,7 +167,7 @@ set_client_multifile_decompressed(string mfname) {
INLINE void DownloadDb:: INLINE void DownloadDb::
set_client_multifile_extracted(string mfname) { set_client_multifile_extracted(string mfname) {
(_client_db.get_multifile_record_named(mfname))->_status = Status_extracted; (_client_db.get_multifile_record_named(mfname))->_status = Status_extracted;
write_db(_client_db._filename, _client_db); write_client_db(_client_db._filename);
} }
@ -190,16 +190,6 @@ get_server_num_files(string mfname) const {
return (_server_db.get_multifile_record_named(mfname))->get_num_files(); return (_server_db.get_multifile_record_named(mfname))->get_num_files();
} }
////////////////////////////////////////////////////////////////////
// Function: DownloadDb::
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE string DownloadDb::
get_client_file_name(string mfname, int index) const {
return (_client_db.get_multifile_record_named(mfname))->get_file_name(index);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DownloadDb:: // Function: DownloadDb::
// Access: Public // Access: Public

View File

@ -22,9 +22,9 @@ PN_uint32 DownloadDb::_magic_number = 0xfeedfeed;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
DownloadDb:: DownloadDb::
DownloadDb(Ramfile &server_file, Filename &client_file) { DownloadDb(Ramfile &server_file, Filename &client_file) {
_client_db = read_db(client_file); _client_db = read_db(client_file, 0);
_client_db._filename = client_file; _client_db._filename = client_file;
_server_db = read_db(server_file); _server_db = read_db(server_file, 1);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -77,7 +77,7 @@ output(ostream &out) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool DownloadDb:: bool DownloadDb::
write_client_db(Filename &file) { write_client_db(Filename &file) {
return write_db(file, _client_db); return write_db(file, _client_db, 0);
} }
@ -88,7 +88,7 @@ write_client_db(Filename &file) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool DownloadDb:: bool DownloadDb::
write_server_db(Filename &file) { write_server_db(Filename &file) {
return write_db(file, _server_db); return write_db(file, _server_db, 1);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -178,7 +178,7 @@ expand_client_multifile(string mfname) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
DownloadDb::Db DownloadDb:: DownloadDb::Db DownloadDb::
read_db(Filename &file) { read_db(Filename &file, bool want_server_info) {
// Open the multifile for reading // Open the multifile for reading
ifstream read_stream; ifstream read_stream;
file.set_binary(); file.set_binary();
@ -192,17 +192,19 @@ read_db(Filename &file) {
return db; return db;
} }
if (!db.read(read_stream)) { if (!db.read(read_stream, want_server_info)) {
downloader_cat.error() downloader_cat.error()
<< "DownloadDb::read() - Read failed: " << "DownloadDb::read() - Read failed: "
<< file << endl; << file << endl;
return db; return db;
} }
if (want_server_info) {
if (!read_version_map(read_stream)) { if (!read_version_map(read_stream)) {
downloader_cat.error() downloader_cat.error()
<< "DownloadDb::read() - read_version_map() failed: " << "DownloadDb::read() - read_version_map() failed: "
<< file << endl; << file << endl;
} }
}
return db; return db;
} }
@ -213,20 +215,22 @@ read_db(Filename &file) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
DownloadDb::Db DownloadDb:: DownloadDb::Db DownloadDb::
read_db(Ramfile &file) { read_db(Ramfile &file, bool want_server_info) {
// Open the multifile for reading // Open the multifile for reading
istringstream read_stream(file._data); istringstream read_stream(file._data);
Db db; Db db;
if (!db.read(read_stream)) { if (!db.read(read_stream, want_server_info)) {
downloader_cat.error() downloader_cat.error()
<< "DownloadDb::read() - Read failed" << endl; << "DownloadDb::read() - Read failed" << endl;
return db; return db;
} }
if (want_server_info) {
if (!read_version_map(read_stream)) { if (!read_version_map(read_stream)) {
downloader_cat.error() downloader_cat.error()
<< "DownloadDb::read() - read_version_map() failed" << endl; << "DownloadDb::read() - read_version_map() failed" << endl;
} }
}
return db; return db;
} }
@ -237,7 +241,7 @@ read_db(Ramfile &file) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool DownloadDb:: bool DownloadDb::
write_db(Filename &file, Db db) { write_db(Filename &file, Db db, bool want_server_info) {
ofstream write_stream; ofstream write_stream;
file.set_binary(); file.set_binary();
if (!file.open_write(write_stream)) { if (!file.open_write(write_stream)) {
@ -250,8 +254,10 @@ write_db(Filename &file, Db db) {
downloader_cat.debug() downloader_cat.debug()
<< "Writing to file: " << file << endl; << "Writing to file: " << file << endl;
db.write(write_stream); db.write(write_stream, want_server_info);
if (want_server_info) {
write_version_map(write_stream); write_version_map(write_stream);
}
write_stream.close(); write_stream.close();
return true; return true;
} }
@ -652,7 +658,7 @@ parse_fr(uchar *start, int size) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool DownloadDb::Db:: bool DownloadDb::Db::
read(istream &read_stream) { read(istream &read_stream, bool want_server_info) {
// Make a little buffer to read the header into // Make a little buffer to read the header into
uchar *header_buf = new uchar[_header_length]; uchar *header_buf = new uchar[_header_length];
@ -697,6 +703,9 @@ read(istream &read_stream) {
PT(DownloadDb::MultifileRecord) mfr = parse_mfr(header_buf, mfr_length); PT(DownloadDb::MultifileRecord) mfr = parse_mfr(header_buf, mfr_length);
delete header_buf; delete header_buf;
// Only read in the individual file info if you are the server
if (want_server_info) {
// Read off all the file records this multifile has // Read off all the file records this multifile has
for (int j = 0; j<mfr->_num_files; j++) { for (int j = 0; j<mfr->_num_files; j++) {
// The file record header is just one int which // The file record header is just one int which
@ -726,6 +735,7 @@ read(istream &read_stream) {
// Add this file record to the current multifilerecord // Add this file record to the current multifilerecord
mfr->add_file_record(fr); mfr->add_file_record(fr);
} }
}
// Add the current multifilerecord to our database // Add the current multifilerecord to our database
add_multifile_record(mfr); add_multifile_record(mfr);
@ -743,7 +753,7 @@ read(istream &read_stream) {
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool DownloadDb::Db:: bool DownloadDb::Db::
write(ofstream &write_stream) { write(ofstream &write_stream, bool want_server_info) {
write_header(write_stream); write_header(write_stream);
// Declare these outside the loop so we do not keep creating // Declare these outside the loop so we do not keep creating
@ -793,6 +803,8 @@ write(ofstream &write_stream) {
string msg = _datagram.get_message(); string msg = _datagram.get_message();
write_stream.write(msg.data(), msg.length()); write_stream.write(msg.data(), msg.length());
// Only write out the file information if you are the server
if (want_server_info) {
// Now iterate over this multifile's files writing them to the stream // Now iterate over this multifile's files writing them to the stream
// Iterate over the multifiles writing them to the stream // Iterate over the multifiles writing them to the stream
vector< PT(FileRecord) >::const_iterator j = (*i)->_file_records.begin(); vector< PT(FileRecord) >::const_iterator j = (*i)->_file_records.begin();
@ -820,7 +832,7 @@ write(ofstream &write_stream) {
string msg = _datagram.get_message(); string msg = _datagram.get_message();
write_stream.write(msg.data(), msg.length()); write_stream.write(msg.data(), msg.length());
} }
}
} }
return true; return true;

View File

@ -92,7 +92,8 @@ PUBLISHED:
INLINE int get_client_num_files(string mfname) const; INLINE int get_client_num_files(string mfname) const;
INLINE int get_server_num_files(string mfname) const; INLINE int get_server_num_files(string mfname) const;
INLINE string get_client_file_name(string mfname, int index) const; // The client does not store the names of all the files anymore
// INLINE string get_client_file_name(string mfname, int index) const;
INLINE string get_server_file_name(string mfname, int index) const; INLINE string get_server_file_name(string mfname, int index) const;
// Queries from the Launcher // Queries from the Launcher
@ -156,8 +157,8 @@ public:
int parse_record_header(uchar *start, int size); int parse_record_header(uchar *start, int size);
PT(MultifileRecord) parse_mfr(uchar *start, int size); PT(MultifileRecord) parse_mfr(uchar *start, int size);
PT(FileRecord) parse_fr(uchar *start, int size); PT(FileRecord) parse_fr(uchar *start, int size);
bool read(istream &read_stream); bool read(istream &read_stream, bool want_server_info);
bool write(ofstream &write_stream); bool write(ofstream &write_stream, bool want_server_info);
Filename _filename; Filename _filename;
MultifileRecords _mfile_records; MultifileRecords _mfile_records;
private: private:
@ -170,12 +171,12 @@ public:
}; };
PUBLISHED: PUBLISHED:
Db read_db(Filename &file); Db read_db(Filename &file, bool want_server_info);
Db read_db(Ramfile &file); Db read_db(Ramfile &file, bool want_server_info);
bool write_db(Filename &file, Db db); bool write_db(Filename &file, Db db, bool want_server_info);
public: public:
// The doenload db stores two databases, one that represents the client's state // The download db stores two databases, one that represents the client's state
// and one that represents the server state // and one that represents the server state
Db _client_db; Db _client_db;
Db _server_db; Db _server_db;