mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
*** empty log message ***
This commit is contained in:
parent
7d6592d26b
commit
9ad657075e
@ -3,6 +3,8 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "config_downloader.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Decompressor::get_progress
|
// Function: Decompressor::get_progress
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -10,6 +12,12 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE float Decompressor::
|
INLINE float Decompressor::
|
||||||
get_progress(void) const {
|
get_progress(void) const {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.warning()
|
||||||
|
<< "Decompressor::get_progress() - Decompression has not been "
|
||||||
|
<< "initiated" << endl;
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
nassertr(_source_file_length > 0, 0.0);
|
nassertr(_source_file_length > 0, 0.0);
|
||||||
return ((float)_total_bytes_read / (float)_source_file_length);
|
return ((float)_total_bytes_read / (float)_source_file_length);
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ Decompressor(PT(Buffer) buffer) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void Decompressor::
|
void Decompressor::
|
||||||
init(PT(Buffer) buffer) {
|
init(PT(Buffer) buffer) {
|
||||||
|
_initiated = false;
|
||||||
nassertv(!buffer.is_null());
|
nassertv(!buffer.is_null());
|
||||||
_half_buffer_length = buffer->get_length()/2;
|
_half_buffer_length = buffer->get_length()/2;
|
||||||
_buffer = buffer;
|
_buffer = buffer;
|
||||||
@ -68,6 +69,8 @@ init(PT(Buffer) buffer) {
|
|||||||
Decompressor::
|
Decompressor::
|
||||||
~Decompressor(void) {
|
~Decompressor(void) {
|
||||||
_temp_file_name.unlink();
|
_temp_file_name.unlink();
|
||||||
|
if (_initiated == true)
|
||||||
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -98,6 +101,13 @@ initiate(Filename &source_file) {
|
|||||||
int Decompressor::
|
int Decompressor::
|
||||||
initiate(Filename &source_file, Filename &dest_file) {
|
initiate(Filename &source_file, Filename &dest_file) {
|
||||||
|
|
||||||
|
if (_initiated == true) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Decompressor::run() - Decompression has already been initiated"
|
||||||
|
<< endl;
|
||||||
|
return DS_error;
|
||||||
|
}
|
||||||
|
|
||||||
// Open source file
|
// Open source file
|
||||||
_source_file = source_file;
|
_source_file = source_file;
|
||||||
_source_file.set_binary();
|
_source_file.set_binary();
|
||||||
@ -134,7 +144,31 @@ initiate(Filename &source_file, Filename &dest_file) {
|
|||||||
_total_bytes_read = 0;
|
_total_bytes_read = 0;
|
||||||
_read_all_input = false;
|
_read_all_input = false;
|
||||||
_source_buffer_length;
|
_source_buffer_length;
|
||||||
return 1;
|
_initiated = true;
|
||||||
|
_decompressor = new ZDecompressor();
|
||||||
|
return DS_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Decompressor::cleanup
|
||||||
|
// Access: Private
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void Decompressor::
|
||||||
|
cleanup(void) {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Decompressor::cleanup() - Decompression has not been "
|
||||||
|
<< "initiated" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_initiated = false;
|
||||||
|
delete _decompressor;
|
||||||
|
_decompressor = NULL;
|
||||||
|
_read_stream.close();
|
||||||
|
_write_stream.close();
|
||||||
|
_source_file.unlink();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -144,8 +178,11 @@ initiate(Filename &source_file, Filename &dest_file) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int Decompressor::
|
int Decompressor::
|
||||||
run(void) {
|
run(void) {
|
||||||
if (_decompressor == NULL) {
|
if (_initiated == false) {
|
||||||
_decompressor = new ZDecompressor();
|
downloader_cat.error()
|
||||||
|
<< "Decompressor::run() - Decompression has not been initiated"
|
||||||
|
<< endl;
|
||||||
|
return DS_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if there is anything left in the source file
|
// See if there is anything left in the source file
|
||||||
@ -180,11 +217,7 @@ run(void) {
|
|||||||
return DS_error_zlib;
|
return DS_error_zlib;
|
||||||
if ((int)_decompressor->get_total_in() == _source_file_length &&
|
if ((int)_decompressor->get_total_in() == _source_file_length &&
|
||||||
avail_out == dest_buffer_length) {
|
avail_out == dest_buffer_length) {
|
||||||
_read_stream.close();
|
cleanup();
|
||||||
_write_stream.close();
|
|
||||||
_source_file.unlink();
|
|
||||||
delete _decompressor;
|
|
||||||
_decompressor = NULL;
|
|
||||||
return DS_success;
|
return DS_success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@ PUBLISHED:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init(PT(Buffer) buffer);
|
void init(PT(Buffer) buffer);
|
||||||
|
void cleanup(void);
|
||||||
|
|
||||||
|
bool _initiated;
|
||||||
PT(Buffer) _buffer;
|
PT(Buffer) _buffer;
|
||||||
int _half_buffer_length;
|
int _half_buffer_length;
|
||||||
Filename _temp_file_name;
|
Filename _temp_file_name;
|
||||||
|
@ -85,6 +85,12 @@ get_disk_write_frequency(void) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE int Downloader::
|
INLINE int Downloader::
|
||||||
get_bytes_written(void) const {
|
get_bytes_written(void) const {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.warning()
|
||||||
|
<< "Downloader::get_bytes_per_second() - Download has not been "
|
||||||
|
<< "initiated" << endl;
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
nassertr(_current_status != NULL, 0);
|
nassertr(_current_status != NULL, 0);
|
||||||
return _current_status->_total_bytes_written;
|
return _current_status->_total_bytes_written;
|
||||||
}
|
}
|
||||||
@ -96,6 +102,12 @@ get_bytes_written(void) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE float Downloader::
|
INLINE float Downloader::
|
||||||
get_bytes_per_second(void) const {
|
get_bytes_per_second(void) const {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.warning()
|
||||||
|
<< "Downloader::get_bytes_per_second() - Download has not been "
|
||||||
|
<< "initiated" << endl;
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
nassertr(_tlast - _tfirst > 0.0, 0.0);
|
nassertr(_tlast - _tfirst > 0.0, 0.0);
|
||||||
nassertr(_current_status != NULL, 0.0);
|
nassertr(_current_status != NULL, 0.0);
|
||||||
return (float)((double)_current_status->_total_bytes / (_tlast - _tfirst));
|
return (float)((double)_current_status->_total_bytes / (_tlast - _tfirst));
|
||||||
|
@ -63,6 +63,7 @@ Downloader(void) {
|
|||||||
_tfirst = 0.0;
|
_tfirst = 0.0;
|
||||||
_tlast = 0.0;
|
_tlast = 0.0;
|
||||||
_got_any_data = false;
|
_got_any_data = false;
|
||||||
|
_initiated = false;
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
WSAData mydata;
|
WSAData mydata;
|
||||||
@ -85,8 +86,8 @@ Downloader::
|
|||||||
if (_connected)
|
if (_connected)
|
||||||
disconnect_from_server();
|
disconnect_from_server();
|
||||||
_buffer.clear();
|
_buffer.clear();
|
||||||
if (_current_status != NULL)
|
if (_initiated == true)
|
||||||
delete _current_status;
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -287,6 +288,13 @@ initiate(const string &file_name, Filename file_dest,
|
|||||||
int first_byte, int last_byte, int total_bytes,
|
int first_byte, int last_byte, int total_bytes,
|
||||||
bool partial_content) {
|
bool partial_content) {
|
||||||
|
|
||||||
|
if (_initiated == true) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Downloader::initiate() - Download has already been initiated"
|
||||||
|
<< endl;
|
||||||
|
return DS_error;
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
if (connect_to_server() == false)
|
if (connect_to_server() == false)
|
||||||
return DS_error_connect;
|
return DS_error_connect;
|
||||||
@ -340,8 +348,6 @@ initiate(const string &file_name, Filename file_dest,
|
|||||||
return DS_error_connect;
|
return DS_error_connect;
|
||||||
|
|
||||||
// Create a download status to maintain download progress information
|
// Create a download status to maintain download progress information
|
||||||
if (_current_status != NULL)
|
|
||||||
delete _current_status;
|
|
||||||
_current_status = new DownloadStatus(_buffer->_buffer,
|
_current_status = new DownloadStatus(_buffer->_buffer,
|
||||||
first_byte, last_byte, total_bytes,
|
first_byte, last_byte, total_bytes,
|
||||||
partial_content);
|
partial_content);
|
||||||
@ -349,10 +355,32 @@ initiate(const string &file_name, Filename file_dest,
|
|||||||
_tfirst = 0.0;
|
_tfirst = 0.0;
|
||||||
_tlast = 0.0;
|
_tlast = 0.0;
|
||||||
_got_any_data = false;
|
_got_any_data = false;
|
||||||
|
_initiated = true;
|
||||||
return DS_success;
|
return DS_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Downloader::cleanup
|
||||||
|
// Access: Private
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void Downloader::
|
||||||
|
cleanup(void) {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Downloader::cleanup() - Download has not been initiated"
|
||||||
|
<< endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The "Connection: close" line tells the server to close the
|
||||||
|
// connection when the download is complete
|
||||||
|
_connected = false;
|
||||||
|
_dest_stream.close();
|
||||||
|
delete _current_status;
|
||||||
|
_initiated = false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Downloader::run
|
// Function: Downloader::run
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -360,9 +388,10 @@ initiate(const string &file_name, Filename file_dest,
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int Downloader::
|
int Downloader::
|
||||||
run(void) {
|
run(void) {
|
||||||
if (_current_status == NULL) {
|
if (_initiated == false) {
|
||||||
downloader_cat.error()
|
downloader_cat.error()
|
||||||
<< "Downloader::run() - Did not call initiate() first" << endl;
|
<< "Downloader::run() - Download has not been initiated"
|
||||||
|
<< endl;
|
||||||
return DS_error;
|
return DS_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +455,8 @@ run(void) {
|
|||||||
fret = fast_receive(_socket, _current_status, _receive_size);
|
fret = fast_receive(_socket, _current_status, _receive_size);
|
||||||
if (fret == FR_eof || fret < 0)
|
if (fret == FR_eof || fret < 0)
|
||||||
break;
|
break;
|
||||||
|
else if (fret == FR_success)
|
||||||
|
_got_any_data = true;
|
||||||
}
|
}
|
||||||
_tlast = _clock.get_real_time();
|
_tlast = _clock.get_real_time();
|
||||||
|
|
||||||
@ -436,10 +467,7 @@ run(void) {
|
|||||||
if (write_to_disk(_current_status) == false)
|
if (write_to_disk(_current_status) == false)
|
||||||
return DS_error_write;
|
return DS_error_write;
|
||||||
}
|
}
|
||||||
_dest_stream.close();
|
cleanup();
|
||||||
// The "Connection: close" line tells the server to close the
|
|
||||||
// connection when the download is complete
|
|
||||||
_connected = false;
|
|
||||||
return DS_success;
|
return DS_success;
|
||||||
} else {
|
} else {
|
||||||
if (downloader_cat.is_debug())
|
if (downloader_cat.is_debug())
|
||||||
|
@ -91,12 +91,15 @@ private:
|
|||||||
bool parse_header(DownloadStatus *status);
|
bool parse_header(DownloadStatus *status);
|
||||||
bool write_to_disk(DownloadStatus *status);
|
bool write_to_disk(DownloadStatus *status);
|
||||||
|
|
||||||
|
void cleanup(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _connected;
|
bool _connected;
|
||||||
int _socket;
|
int _socket;
|
||||||
string _server_name;
|
string _server_name;
|
||||||
struct sockaddr_in _sin;
|
struct sockaddr_in _sin;
|
||||||
|
|
||||||
|
bool _initiated;
|
||||||
PT(Buffer) _buffer;
|
PT(Buffer) _buffer;
|
||||||
int _disk_write_frequency;
|
int _disk_write_frequency;
|
||||||
float _frequency;
|
float _frequency;
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "config_downloader.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Extractor::get_progress
|
// Function: Extractor::get_progress
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -10,6 +12,12 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE float Extractor::
|
INLINE float Extractor::
|
||||||
get_progress(void) const {
|
get_progress(void) const {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.warning()
|
||||||
|
<< "Extractor::get_progress() - Extraction has not been initiated"
|
||||||
|
<< endl;
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
nassertr(_source_file_length > 0, 0.0);
|
nassertr(_source_file_length > 0, 0.0);
|
||||||
return ((float)_total_bytes_read / (float)_source_file_length);
|
return ((float)_total_bytes_read / (float)_source_file_length);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ Extractor(PT(Buffer) buffer) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void Extractor::
|
void Extractor::
|
||||||
init(PT(Buffer) buffer) {
|
init(PT(Buffer) buffer) {
|
||||||
|
_initiated = false;
|
||||||
nassertv(!buffer.is_null());
|
nassertv(!buffer.is_null());
|
||||||
_buffer = buffer;
|
_buffer = buffer;
|
||||||
_mfile = NULL;
|
_mfile = NULL;
|
||||||
@ -55,8 +56,8 @@ init(PT(Buffer) buffer) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
Extractor::
|
Extractor::
|
||||||
~Extractor(void) {
|
~Extractor(void) {
|
||||||
if (_mfile != NULL)
|
if (_initiated == true)
|
||||||
delete _mfile;
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -67,6 +68,13 @@ Extractor::
|
|||||||
int Extractor::
|
int Extractor::
|
||||||
initiate(Filename &source_file, const Filename &rel_path) {
|
initiate(Filename &source_file, const Filename &rel_path) {
|
||||||
|
|
||||||
|
if (_initiated == true) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Extractor::initiate() - Extraction has already been initiated"
|
||||||
|
<< endl;
|
||||||
|
return ES_error;
|
||||||
|
}
|
||||||
|
|
||||||
// Open source file
|
// Open source file
|
||||||
_source_file = source_file;
|
_source_file = source_file;
|
||||||
_source_file.set_binary();
|
_source_file.set_binary();
|
||||||
@ -87,9 +95,32 @@ initiate(Filename &source_file, const Filename &rel_path) {
|
|||||||
_total_bytes_read = 0;
|
_total_bytes_read = 0;
|
||||||
_read_all_input = false;
|
_read_all_input = false;
|
||||||
_handled_all_input = false;
|
_handled_all_input = false;
|
||||||
|
_mfile = new Multifile();
|
||||||
|
_initiated = true;
|
||||||
return ES_success;
|
return ES_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Extractor::cleanup
|
||||||
|
// Access: Private
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void Extractor::
|
||||||
|
cleanup(void) {
|
||||||
|
if (_initiated == false) {
|
||||||
|
downloader_cat.error()
|
||||||
|
<< "Extractor::cleanup() - Extraction has not been initiated"
|
||||||
|
<< endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _mfile;
|
||||||
|
_mfile = NULL;
|
||||||
|
_read_stream.close();
|
||||||
|
_source_file.unlink();
|
||||||
|
_initiated = false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Extractor::run
|
// Function: Extractor::run
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -97,8 +128,12 @@ initiate(Filename &source_file, const Filename &rel_path) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int Extractor::
|
int Extractor::
|
||||||
run(void) {
|
run(void) {
|
||||||
if (_mfile == NULL)
|
if (_initiated == false) {
|
||||||
_mfile = new Multifile;
|
downloader_cat.error()
|
||||||
|
<< "Extractor::run() - Extraction has not been initiated"
|
||||||
|
<< endl;
|
||||||
|
return ES_error;
|
||||||
|
}
|
||||||
|
|
||||||
// See if there is anything left in the source file
|
// See if there is anything left in the source file
|
||||||
if (_read_all_input == false) {
|
if (_read_all_input == false) {
|
||||||
@ -116,10 +151,7 @@ run(void) {
|
|||||||
|
|
||||||
// Write to the out file
|
// Write to the out file
|
||||||
if (_mfile->write(buffer_start, buffer_size, _rel_path) == true) {
|
if (_mfile->write(buffer_start, buffer_size, _rel_path) == true) {
|
||||||
_read_stream.close();
|
cleanup();
|
||||||
_source_file.unlink();
|
|
||||||
delete _mfile;
|
|
||||||
_mfile = NULL;
|
|
||||||
return ES_success;
|
return ES_success;
|
||||||
}
|
}
|
||||||
return ES_ok;
|
return ES_ok;
|
||||||
|
@ -41,7 +41,9 @@ PUBLISHED:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init(PT(Buffer) buffer);
|
void init(PT(Buffer) buffer);
|
||||||
|
void cleanup(void);
|
||||||
|
|
||||||
|
bool _initiated;
|
||||||
PT(Buffer) _buffer;
|
PT(Buffer) _buffer;
|
||||||
|
|
||||||
ifstream _read_stream;
|
ifstream _read_stream;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user