make extractor report more linear progress

This commit is contained in:
David Rose 2002-10-19 16:13:20 +00:00
parent f3d2ac3103
commit 3371fb5391
2 changed files with 17 additions and 23 deletions

View File

@ -89,6 +89,7 @@ reset() {
} }
_requests.clear(); _requests.clear();
_requests_total_length = 0;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -105,6 +106,7 @@ request_subfile(const Filename &subfile_name) {
return false; return false;
} }
_requests.push_back(index); _requests.push_back(index);
_requests_total_length += _multifile.get_subfile_length(index);
return true; return true;
} }
@ -117,9 +119,11 @@ request_subfile(const Filename &subfile_name) {
int Extractor:: int Extractor::
request_all_subfiles() { request_all_subfiles() {
_requests.clear(); _requests.clear();
_requests_total_length = 0;
int num_subfiles = _multifile.get_num_subfiles(); int num_subfiles = _multifile.get_num_subfiles();
for (int i = 0; i < num_subfiles; i++) { for (int i = 0; i < num_subfiles; i++) {
_requests.push_back(i); _requests.push_back(i);
_requests_total_length += _multifile.get_subfile_length(i);
} }
return num_subfiles; return num_subfiles;
} }
@ -145,6 +149,7 @@ step() {
_subfile_index = 0; _subfile_index = 0;
_subfile_pos = 0; _subfile_pos = 0;
_subfile_length = 0; _subfile_length = 0;
_total_bytes_extracted = 0;
_read = (istream *)NULL; _read = (istream *)NULL;
_initiated = true; _initiated = true;
} }
@ -209,6 +214,7 @@ step() {
return EU_error_abort; return EU_error_abort;
} }
_subfile_pos += max_bytes; _subfile_pos += max_bytes;
_total_bytes_extracted += max_bytes;
} }
return EU_ok; return EU_ok;
@ -225,27 +231,11 @@ get_progress() const {
if (!_initiated) { if (!_initiated) {
return 0.0f; return 0.0f;
} }
if (_requests_total_length == 0) {
float progress_through_file; return 1.0f;
if (_read == (istream *)NULL) {
// Time to open the next subfile.
progress_through_file = 0.0f;
} else if (_subfile_pos >= _subfile_length) {
// Time to close this subfile.
progress_through_file = 1.0f;
} else {
// In the middle of processing a subfile.
progress_through_file = (float)_subfile_pos / (float)_subfile_length;
} }
float progress_through_list = return (float)_total_bytes_extracted / (float)_requests_total_length;
(((float)_request_index + progress_through_file) /
(float)(_requests.size()));
return progress_through_list;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -32,10 +32,12 @@
// //
// It is designed to limit its use of system resources // It is designed to limit its use of system resources
// and run unobtrusively in the background. After // and run unobtrusively in the background. After
// initiate(), each call to run() extracts another small // specifying the files you wish to extract via repeated
// portion of the Multifile. Call run() repeatedly // calls to request_subfile(), begin the process by
// whenever you have spare cycles until run() returns // calling run() repeatedly. Each call to run()
// EU_success. // extracts another small portion of the Multifile.
// Call run() whenever you have spare cycles until run()
// returns EU_success.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS Extractor { class EXPCL_PANDAEXPRESS Extractor {
PUBLISHED: PUBLISHED:
@ -63,6 +65,7 @@ private:
typedef pvector<int> Requests; typedef pvector<int> Requests;
Requests _requests; Requests _requests;
size_t _requests_total_length;
bool _initiated; bool _initiated;
@ -71,6 +74,7 @@ private:
int _subfile_index; int _subfile_index;
size_t _subfile_pos; size_t _subfile_pos;
size_t _subfile_length; size_t _subfile_length;
size_t _total_bytes_extracted;
istream *_read; istream *_read;
ofstream _write; ofstream _write;
Filename _subfile_filename; Filename _subfile_filename;