mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
*** empty log message ***
This commit is contained in:
parent
6bdce752d7
commit
b601b49c80
@ -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
|
||||||
|
@ -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,16 +192,18 @@ 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 (!read_version_map(read_stream)) {
|
if (want_server_info) {
|
||||||
downloader_cat.error()
|
if (!read_version_map(read_stream)) {
|
||||||
<< "DownloadDb::read() - read_version_map() failed: "
|
downloader_cat.error()
|
||||||
<< file << endl;
|
<< "DownloadDb::read() - read_version_map() failed: "
|
||||||
|
<< file << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
@ -213,19 +215,21 @@ 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 (!read_version_map(read_stream)) {
|
if (want_server_info) {
|
||||||
downloader_cat.error()
|
if (!read_version_map(read_stream)) {
|
||||||
<< "DownloadDb::read() - read_version_map() failed" << endl;
|
downloader_cat.error()
|
||||||
|
<< "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);
|
||||||
write_version_map(write_stream);
|
if (want_server_info) {
|
||||||
|
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,34 +703,38 @@ 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;
|
||||||
|
|
||||||
// Read off all the file records this multifile has
|
// Only read in the individual file info if you are the server
|
||||||
for (int j = 0; j<mfr->_num_files; j++) {
|
if (want_server_info) {
|
||||||
// The file record header is just one int which
|
|
||||||
// represents the size of the record
|
|
||||||
int fr_header_length = sizeof(PN_int32);
|
|
||||||
|
|
||||||
// Make a little buffer to read the file record header into
|
// Read off all the file records this multifile has
|
||||||
header_buf = new uchar[fr_header_length];
|
for (int j = 0; j<mfr->_num_files; j++) {
|
||||||
|
// The file record header is just one int which
|
||||||
|
// represents the size of the record
|
||||||
|
int fr_header_length = sizeof(PN_int32);
|
||||||
|
|
||||||
// Read the header
|
// Make a little buffer to read the file record header into
|
||||||
read_stream.read((char *)header_buf, fr_header_length);
|
header_buf = new uchar[fr_header_length];
|
||||||
|
|
||||||
// Parse the header
|
// Read the header
|
||||||
int fr_length = parse_record_header(header_buf, fr_header_length);
|
read_stream.read((char *)header_buf, fr_header_length);
|
||||||
delete header_buf;
|
|
||||||
|
// Parse the header
|
||||||
|
int fr_length = parse_record_header(header_buf, fr_header_length);
|
||||||
|
delete header_buf;
|
||||||
|
|
||||||
// Ok, now that we know the size of the mfr, read it in
|
// Ok, now that we know the size of the mfr, read it in
|
||||||
// Make a buffer to read the file record into
|
// Make a buffer to read the file record into
|
||||||
header_buf = new uchar[fr_length];
|
header_buf = new uchar[fr_length];
|
||||||
|
|
||||||
// Read the file record -- do not count the header length twice
|
// Read the file record -- do not count the header length twice
|
||||||
read_stream.read((char *)header_buf, (fr_length - fr_header_length));
|
read_stream.read((char *)header_buf, (fr_length - fr_header_length));
|
||||||
|
|
||||||
// Parse the file recrod
|
// Parse the file recrod
|
||||||
PT(DownloadDb::FileRecord) fr = parse_fr(header_buf, fr_length);
|
PT(DownloadDb::FileRecord) fr = parse_fr(header_buf, fr_length);
|
||||||
|
|
||||||
// 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
|
||||||
@ -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,34 +803,36 @@ 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());
|
||||||
|
|
||||||
// Now iterate over this multifile's files writing them to the stream
|
// Only write out the file information if you are the server
|
||||||
// Iterate over the multifiles writing them to the stream
|
if (want_server_info) {
|
||||||
vector< PT(FileRecord) >::const_iterator j = (*i)->_file_records.begin();
|
// Now iterate over this multifile's files writing them to the stream
|
||||||
for(; j != (*i)->_file_records.end(); ++j) {
|
// Iterate over the multifiles writing them to the stream
|
||||||
// Clear the datagram before we jam a bunch of stuff on it
|
vector< PT(FileRecord) >::const_iterator j = (*i)->_file_records.begin();
|
||||||
_datagram.clear();
|
for(; j != (*i)->_file_records.end(); ++j) {
|
||||||
|
// Clear the datagram before we jam a bunch of stuff on it
|
||||||
|
_datagram.clear();
|
||||||
|
|
||||||
name_length = (*j)->_name.length();
|
name_length = (*j)->_name.length();
|
||||||
|
|
||||||
// Compute the length of this datagram
|
// Compute the length of this datagram
|
||||||
header_length =
|
header_length =
|
||||||
sizeof(header_length) + // Size of this header length
|
sizeof(header_length) + // Size of this header length
|
||||||
sizeof(name_length) + // Size of the size of the name string
|
sizeof(name_length) + // Size of the size of the name string
|
||||||
(*j)->_name.length(); // Size of the name string
|
(*j)->_name.length(); // Size of the name string
|
||||||
|
|
||||||
// Add the length of this entire datagram
|
// Add the length of this entire datagram
|
||||||
_datagram.add_int32(header_length);
|
_datagram.add_int32(header_length);
|
||||||
|
|
||||||
// Add the length of the name
|
// Add the length of the name
|
||||||
_datagram.add_int32(name_length);
|
_datagram.add_int32(name_length);
|
||||||
// Add the name
|
// Add the name
|
||||||
_datagram.append_data((*j)->_name.c_str(), (*j)->_name.length());
|
_datagram.append_data((*j)->_name.c_str(), (*j)->_name.length());
|
||||||
|
|
||||||
// Now put this datagram on the write stream
|
// Now put this datagram on the 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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user