|
@@ -9,42 +9,19 @@
|
|
|
#include "patcher.h"
|
|
#include "patcher.h"
|
|
|
#include "config_downloader.h"
|
|
#include "config_downloader.h"
|
|
|
|
|
|
|
|
-#include <event.h>
|
|
|
|
|
-#include <pt_Event.h>
|
|
|
|
|
-#include <throw_event.h>
|
|
|
|
|
-#include <eventParameter.h>
|
|
|
|
|
#include <filename.h>
|
|
#include <filename.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Defines
|
|
// Defines
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-// Class : PatcherToken
|
|
|
|
|
-// Description : Holds a request for the patcher.
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-class PatcherToken : public ReferenceCount {
|
|
|
|
|
-public:
|
|
|
|
|
- INLINE PatcherToken(uint id, const Filename &patch,
|
|
|
|
|
- const Filename &infile, const string &event_name) {
|
|
|
|
|
- _id = id;
|
|
|
|
|
- _patch = patch;
|
|
|
|
|
- _infile = infile;
|
|
|
|
|
- _event_name = event_name;
|
|
|
|
|
- }
|
|
|
|
|
- int _id;
|
|
|
|
|
- Filename _patch;
|
|
|
|
|
- Filename _infile;
|
|
|
|
|
- string _event_name;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: Patcher::Constructor
|
|
// Function: Patcher::Constructor
|
|
|
// Access: Public
|
|
// Access: Public
|
|
|
// Description:
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
Patcher::
|
|
Patcher::
|
|
|
-Patcher(void) : AsyncUtility() {
|
|
|
|
|
|
|
+Patcher(void) {
|
|
|
PT(Buffer) buffer = new Buffer(patcher_buffer_size);
|
|
PT(Buffer) buffer = new Buffer(patcher_buffer_size);
|
|
|
init(buffer);
|
|
init(buffer);
|
|
|
}
|
|
}
|
|
@@ -55,7 +32,7 @@ Patcher(void) : AsyncUtility() {
|
|
|
// Description:
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
Patcher::
|
|
Patcher::
|
|
|
-Patcher(PT(Buffer) buffer) : AsyncUtility() {
|
|
|
|
|
|
|
+Patcher(PT(Buffer) buffer) {
|
|
|
init(buffer);
|
|
init(buffer);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -67,7 +44,6 @@ Patcher(PT(Buffer) buffer) : AsyncUtility() {
|
|
|
void Patcher::
|
|
void Patcher::
|
|
|
init(PT(Buffer) buffer) {
|
|
init(PT(Buffer) buffer) {
|
|
|
nassertv(!buffer.is_null());
|
|
nassertv(!buffer.is_null());
|
|
|
- _token_board = new PatcherTokenBoard;
|
|
|
|
|
_buffer = buffer;
|
|
_buffer = buffer;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -78,121 +54,27 @@ init(PT(Buffer) buffer) {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
Patcher::
|
|
Patcher::
|
|
|
~Patcher(void) {
|
|
~Patcher(void) {
|
|
|
- destroy_thread();
|
|
|
|
|
-
|
|
|
|
|
- delete _token_board;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: Patcher::request_patch
|
|
|
|
|
|
|
+// Function: Patcher::initiate
|
|
|
// Access: Public
|
|
// Access: Public
|
|
|
// Description:
|
|
// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
int Patcher::
|
|
int Patcher::
|
|
|
-request_patch(const Filename &patch, const Filename &infile,
|
|
|
|
|
- const string &event_name) {
|
|
|
|
|
- PT(PatcherToken) tok;
|
|
|
|
|
- if (_threads_enabled) {
|
|
|
|
|
-
|
|
|
|
|
- // Make sure we actually are threaded
|
|
|
|
|
- if (!_threaded) {
|
|
|
|
|
- downloader_cat.info()
|
|
|
|
|
- << "Patcher::request_patch() - create_thread() was "
|
|
|
|
|
- << "never called! Calling it now..." << endl;
|
|
|
|
|
- create_thread();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // We need to grab the lock in order to signal the condition variable
|
|
|
|
|
-#ifdef HAVE_IPC
|
|
|
|
|
- _lock.lock();
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
- if (_token_board->_waiting.is_full()) {
|
|
|
|
|
- downloader_cat.error()
|
|
|
|
|
- << "Patcher::request_patch() - Too many pending requests\n";
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (downloader_cat.is_debug()) {
|
|
|
|
|
- downloader_cat.debug()
|
|
|
|
|
- << "Patch requested for file: " << infile << endl;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- tok = new PatcherToken(_next_token++, patch, infile, event_name);
|
|
|
|
|
- _token_board->_waiting.insert(tok);
|
|
|
|
|
-
|
|
|
|
|
-#ifdef HAVE_IPC
|
|
|
|
|
- _request_cond->signal();
|
|
|
|
|
- _lock.unlock();
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- // If we're not running asynchronously, process the load request
|
|
|
|
|
- // directly now.
|
|
|
|
|
- if (_token_board->_waiting.is_full()) {
|
|
|
|
|
- downloader_cat.error()
|
|
|
|
|
- << "Patcher::request_patch() - Too many pending requests\n";
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
- if (downloader_cat.is_debug()) {
|
|
|
|
|
- downloader_cat.debug()
|
|
|
|
|
- << "Patch requested for file: " << infile << endl;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- tok = new PatcherToken(_next_token++, patch, infile, event_name);
|
|
|
|
|
- _token_board->_waiting.insert(tok);
|
|
|
|
|
- process_request();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return tok->_id;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-// Function: Patcher::process_request
|
|
|
|
|
-// Access: Private
|
|
|
|
|
-// Description: Serves any requests on the token board, moving them
|
|
|
|
|
-// to the done queue.
|
|
|
|
|
-////////////////////////////////////////////////////////////////////
|
|
|
|
|
-bool Patcher::
|
|
|
|
|
-process_request() {
|
|
|
|
|
- if (_shutdown) {
|
|
|
|
|
- if (downloader_cat.is_debug())
|
|
|
|
|
- downloader_cat.debug()
|
|
|
|
|
- << "Patcher shutting down...\n";
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If there is actually a request token - process it
|
|
|
|
|
- while (!_token_board->_waiting.is_empty()) {
|
|
|
|
|
- PT(PatcherToken) tok = _token_board->_waiting.extract();
|
|
|
|
|
- if (patch(tok->_patch, tok->_infile)) {
|
|
|
|
|
- _token_board->_done.insert(tok);
|
|
|
|
|
-
|
|
|
|
|
- // Throw a "done" event now.
|
|
|
|
|
- if (!tok->_event_name.empty()) {
|
|
|
|
|
- PT_Event done = new Event(tok->_event_name);
|
|
|
|
|
- done->add_parameter(EventParameter((int)tok->_id));
|
|
|
|
|
- throw_event(done);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (downloader_cat.is_debug()) {
|
|
|
|
|
- downloader_cat.debug()
|
|
|
|
|
- << "Patcher::process_request() - patching complete for "
|
|
|
|
|
- << tok->_infile << "\n";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+initiate(Filename &patch, Filename &infile) {
|
|
|
|
|
+ Patchfile pfile(_buffer);
|
|
|
|
|
+ if (pfile.apply(patch, infile) == true)
|
|
|
|
|
+ return PS_success;
|
|
|
|
|
+ return PS_error;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-// Function: Patcher::patch
|
|
|
|
|
|
|
+// Function: Patcher::run
|
|
|
// Access: Public
|
|
// Access: Public
|
|
|
-// Description:
|
|
|
|
|
|
|
+// Description:
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-bool Patcher::
|
|
|
|
|
-patch(Filename &patch, Filename &infile) {
|
|
|
|
|
- Patchfile pfile(_buffer);
|
|
|
|
|
- return pfile.apply(patch, infile);
|
|
|
|
|
|
|
+int Patcher::
|
|
|
|
|
+run(void) {
|
|
|
|
|
+ return PS_success;
|
|
|
}
|
|
}
|