2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Merge pull request #353 from Hoikas/new-launcher

Unified Patcher (Part 2: Nuke eap)
This commit is contained in:
Branan Purvine-Riley
2013-12-12 14:04:43 -08:00
20 changed files with 1164 additions and 2794 deletions

View File

@ -89,6 +89,13 @@ struct pfPatcherWorker : public hsThread
// Any file
kFlagZipped = 1<<3,
// Executable flags
kRedistUpdate = 1<<4,
// Begin internal flags
kLastManifestFlag = 1<<5,
kSelfPatch = 1<<6,
};
std::deque<Request> fRequests;
@ -100,9 +107,12 @@ struct pfPatcherWorker : public hsThread
pfPatcher::CompletionFunc fOnComplete;
pfPatcher::FileDownloadFunc fFileBeginDownload;
pfPatcher::FileDesiredFunc fFileDownloadDesired;
pfPatcher::FileDownloadFunc fFileDownloaded;
pfPatcher::GameCodeDiscoverFunc fGameCodeDiscovered;
pfPatcher::ProgressTickFunc fProgressTick;
pfPatcher::FileDownloadFunc fRedistUpdateDownloaded;
pfPatcher::FileDownloadFunc fSelfPatch;
pfPatcher* fParent;
volatile bool fStarted;
@ -199,6 +209,8 @@ public:
void Begin() { fDLStartTime = hsTimer::GetSysSeconds(); }
plFileName GetFileName() const { return fFilename; }
bool IsRedistUpdate() const { return hsCheckBits(fFlags, pfPatcherWorker::kRedistUpdate); }
bool IsSelfPatch() const { return hsCheckBits(fFlags, pfPatcherWorker::kSelfPatch); }
void Unlink() const { plFileSystem::Unlink(fFilename); }
};
@ -306,6 +318,10 @@ static void IFileThingDownloadCB(ENetError result, void* param, const plFileName
if (IS_NET_SUCCESS(result)) {
PatcherLogGreen("\tDownloaded File '%s'", stream->GetFileName().AsString().c_str());
patcher->WhitelistFile(stream->GetFileName(), true);
if (patcher->fSelfPatch && stream->IsSelfPatch())
patcher->fSelfPatch(stream->GetFileName());
if (patcher->fRedistUpdateDownloaded && stream->IsRedistUpdate())
patcher->fRedistUpdateDownloaded(stream->GetFileName());
patcher->IssueRequest();
} else {
PatcherLogRed("\tDownloaded Failed: File '%s'", stream->GetFileName().AsString().c_str());
@ -454,7 +470,7 @@ hsError pfPatcherWorker::Run()
void pfPatcherWorker::ProcessFile()
{
do {
const NetCliFileManifestEntry& entry = fQueuedFiles.front();
NetCliFileManifestEntry& entry = fQueuedFiles.front();
// eap sucks
plFileName clName = plString::FromWchar(entry.clientName);
@ -474,10 +490,28 @@ void pfPatcherWorker::ProcessFile()
}
}
// If you got here, they're different.
// It's different... but do we want it?
if (fFileDownloadDesired) {
if (!fFileDownloadDesired(clName)) {
PatcherLogRed("\tDeclined '%S'", entry.clientName);
fQueuedFiles.pop_front();
continue;
}
}
// If you got here, they're different and we want it.
PatcherLogYellow("\tEnqueuing '%S'", entry.clientName);
plFileSystem::CreateDir(plFileName(clName).StripFileName());
// If someone registered for SelfPatch notifications, then we should probably
// let them handle the gruntwork... Otherwise, go nuts!
if (fSelfPatch) {
if (clName == plFileSystem::GetCurrentAppPath().GetFileName()) {
clName += ".tmp"; // don't overwrite myself!
entry.flags |= kSelfPatch;
}
}
pfPatcherStream* s = new pfPatcherStream(this, dlName, entry);
s->Open(clName, "wb");
@ -547,6 +581,11 @@ void pfPatcher::OnFileDownloadBegin(FileDownloadFunc cb)
fWorker->fFileBeginDownload = cb;
}
void pfPatcher::OnFileDownloadDesired(FileDesiredFunc cb)
{
fWorker->fFileDownloadDesired = cb;
}
void pfPatcher::OnFileDownloaded(FileDownloadFunc cb)
{
fWorker->fFileDownloaded = cb;
@ -562,6 +601,16 @@ void pfPatcher::OnProgressTick(ProgressTickFunc cb)
fWorker->fProgressTick = cb;
}
void pfPatcher::OnRedistUpdate(FileDownloadFunc cb)
{
fWorker->fRedistUpdateDownloaded = cb;
}
void pfPatcher::OnSelfPatch(FileDownloadFunc cb)
{
fWorker->fSelfPatch = cb;
}
// ===================================================
void pfPatcher::RequestGameCode()

View File

@ -70,6 +70,9 @@ public:
/** Represents a function that takes the status and an optional message on completion. */
typedef std::function<void(ENetError, const plString&)> CompletionFunc;
/** Represents a function that takes (const plFileName&) and approves it. */
typedef std::function<bool(const plFileName&)> FileDesiredFunc;
/** Represents a function that takes (const plFileName&) on an interesting file operation. */
typedef std::function<void(const plFileName&)> FileDownloadFunc;
@ -95,6 +98,12 @@ public:
*/
void OnFileDownloadBegin(FileDownloadFunc cb);
/** Set a callback that will be fired when the patcher wants to download a file. You are
* given the ability to approve or veto the download. With great power comes great responsibility...
* \remarks This will be called from the patcher thread.
*/
void OnFileDownloadDesired(FileDesiredFunc cb);
/** Set a callback that will be fired when the patcher has finished downloading a file from the server.
* \remarks This will be called from the network thread.
*/
@ -112,6 +121,15 @@ public:
*/
void OnProgressTick(ProgressTickFunc cb);
/** Set a callback that will be fired when the patcher downloads an updated redistributable. Such as
* the Visual C++ runtime (vcredist_x86.exe). You are responsible for installing it.
* \remarks This will be called from the network thread.
*/
void OnRedistUpdate(FileDownloadFunc cb);
/** This is called when the current application has been updated. */
void OnSelfPatch(FileDownloadFunc cb);
void RequestGameCode();
void RequestManifest(const plString& mfs);
void RequestManifest(const std::vector<plString>& mfs);