mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Reroute plResPatcher
This commit is contained in:
@ -18,5 +18,7 @@ set(plAgeLoader_HEADERS
|
||||
|
||||
add_library(plAgeLoader STATIC ${plAgeLoader_SOURCES} ${plAgeLoader_HEADERS})
|
||||
|
||||
target_link_libraries(plAgeLoader pfPatcher)
|
||||
|
||||
source_group("Source Files" FILES ${plAgeLoader_SOURCES})
|
||||
source_group("Header Files" FILES ${plAgeLoader_HEADERS})
|
||||
|
@ -69,15 +69,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "plResMgr/plRegistryNode.h"
|
||||
#include "plResMgr/plResManager.h"
|
||||
#include "plFile/plEncryptedStream.h"
|
||||
#include "plProgressMgr/plProgressMgr.h"
|
||||
|
||||
/// TEMP HACK TO LOAD CONSOLE INIT FILES ON AGE LOAD
|
||||
#include "plMessage/plConsoleMsg.h"
|
||||
#include "plMessage/plLoadAvatarMsg.h"
|
||||
#include "plMessage/plAgeLoadedMsg.h"
|
||||
|
||||
|
||||
extern bool gDataServerLocal;
|
||||
|
||||
// static
|
||||
plAgeLoader* plAgeLoader::fInstance=nil;
|
||||
|
||||
@ -119,6 +117,7 @@ void plAgeLoader::Init()
|
||||
RegisterAs( kAgeLoader_KEY );
|
||||
plgDispatch::Dispatch()->RegisterForExactType(plInitialAgeStateLoadedMsg::Index(), GetKey());
|
||||
plgDispatch::Dispatch()->RegisterForExactType(plClientMsg::Index(), GetKey());
|
||||
plgDispatch::Dispatch()->RegisterForExactType(plResPatcherMsg::Index(), GetKey());
|
||||
}
|
||||
|
||||
//
|
||||
@ -156,7 +155,12 @@ bool plAgeLoader::MsgReceive(plMessage* msg)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// sadface thread protection
|
||||
if (plResPatcherMsg::ConvertNoRef(msg)) {
|
||||
delete plResPatcher::GetInstance()->fProgress;
|
||||
plResPatcher::GetInstance()->fProgress = nullptr;
|
||||
}
|
||||
|
||||
return plReceiver::MsgReceive(msg);
|
||||
}
|
||||
|
||||
@ -173,14 +177,7 @@ bool plAgeLoader::LoadAge(const char ageName[])
|
||||
//============================================================================
|
||||
void plAgeLoader::UpdateAge(const char ageName[])
|
||||
{
|
||||
if (gDataServerLocal)
|
||||
// We have to send this msg ourselves since we're not actually updating
|
||||
plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg);
|
||||
else
|
||||
{
|
||||
plResPatcher::GetInstance()->RequestManifest(ageName);
|
||||
plResPatcher::GetInstance()->Start();
|
||||
}
|
||||
plResPatcher::GetInstance()->Update(ageName);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -42,153 +42,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
|
||||
#include "plResPatcher.h"
|
||||
#include "hsResMgr.h"
|
||||
#include "plgDispatch.h"
|
||||
|
||||
#include "plAgeLoader/plAgeLoader.h"
|
||||
#include "plCompression/plZlibStream.h"
|
||||
#include "pnEncryption/plChecksum.h"
|
||||
#include "plMessage/plResPatcherMsg.h"
|
||||
#include "pnNetBase/pnNbError.h"
|
||||
#include "plNetGameLib/plNetGameLib.h"
|
||||
#include "pfPatcher/pfPatcher.h"
|
||||
#include "plProgressMgr/plProgressMgr.h"
|
||||
#include "plResMgr/plResManager.h"
|
||||
#include "plStatusLog/plStatusLog.h"
|
||||
|
||||
extern bool gDataServerLocal;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class plResDownloadStream : public plZlibStream
|
||||
{
|
||||
plOperationProgress* fProgress;
|
||||
plFileName fFilename;
|
||||
bool fIsZipped;
|
||||
|
||||
public:
|
||||
plResDownloadStream(plOperationProgress* prog, const plFileName& reqFile)
|
||||
: fProgress(prog)
|
||||
{
|
||||
fIsZipped = reqFile.GetFileExt().CompareI("gz") == 0;
|
||||
}
|
||||
|
||||
virtual bool Open(const plFileName& filename, const char* mode)
|
||||
{
|
||||
fFilename = filename;
|
||||
return plZlibStream::Open(filename, mode);
|
||||
}
|
||||
|
||||
virtual uint32_t Write(uint32_t count, const void* buf)
|
||||
{
|
||||
fProgress->Increment((float)count);
|
||||
if (fIsZipped)
|
||||
return plZlibStream::Write(count, buf);
|
||||
else
|
||||
return fOutput->Write(count, buf);
|
||||
}
|
||||
|
||||
plFileName GetFileName() const { return fFilename; }
|
||||
bool IsZipped() const { return fIsZipped; }
|
||||
void Unlink() const { plFileSystem::Unlink(fFilename); }
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void FileDownloaded(
|
||||
ENetError result,
|
||||
void* param,
|
||||
const plFileName & filename,
|
||||
hsStream* writer)
|
||||
{
|
||||
plResPatcher* patcher = (plResPatcher*)param;
|
||||
plFileName file = filename;
|
||||
if (((plResDownloadStream*)writer)->IsZipped())
|
||||
file = file.StripFileExt(); // Kill off .gz
|
||||
writer->Close();
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case kNetSuccess:
|
||||
{
|
||||
PatcherLog(kStatus, " Download Complete: %s", file.AsString().c_str());
|
||||
|
||||
// If this is a PRP, then we need to add it to the ResManager
|
||||
plFileName clientPath = static_cast<plResDownloadStream*>(writer)->GetFileName();
|
||||
if (clientPath.GetFileExt().CompareI("prp") == 0)
|
||||
{
|
||||
plResManager* clientResMgr = static_cast<plResManager*>(hsgResMgr::ResMgr());
|
||||
clientResMgr->AddSinglePage(clientPath);
|
||||
}
|
||||
|
||||
// Continue down the warpath
|
||||
patcher->IssueRequest();
|
||||
delete writer;
|
||||
return;
|
||||
}
|
||||
case kNetErrFileNotFound:
|
||||
PatcherLog(kError, " Download Failed: %s not found", file.AsString().c_str());
|
||||
break;
|
||||
default:
|
||||
char* error = hsWStringToString(NetErrorToString(result));
|
||||
PatcherLog(kError, " Download Failed: %s", error);
|
||||
delete[] error;
|
||||
break;
|
||||
}
|
||||
|
||||
// Failure case
|
||||
static_cast<plResDownloadStream*>(writer)->Unlink();
|
||||
patcher->Finish(false);
|
||||
delete writer;
|
||||
}
|
||||
|
||||
static void ManifestDownloaded(
|
||||
ENetError result,
|
||||
void* param,
|
||||
const wchar_t group[],
|
||||
const NetCliFileManifestEntry manifest[],
|
||||
uint32_t entryCount)
|
||||
{
|
||||
plResPatcher* patcher = (plResPatcher*)param;
|
||||
plString name = plString::FromWchar(group);
|
||||
if (IS_NET_SUCCESS(result))
|
||||
PatcherLog(kInfo, " Downloaded manifest %s", name.c_str());
|
||||
else {
|
||||
PatcherLog(kError, " Failed to download manifest %s", name.c_str());
|
||||
patcher->Finish(false);
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < entryCount; ++i)
|
||||
{
|
||||
const NetCliFileManifestEntry mfs = manifest[i];
|
||||
plFileName fileName = plString::FromWchar(mfs.clientName);
|
||||
plFileName downloadName = plString::FromWchar(mfs.downloadName);
|
||||
|
||||
// See if the files are the same
|
||||
// 1. Check file size before we do time consuming md5 operations
|
||||
// 2. Do wasteful md5. We should consider implementing a CRC instead.
|
||||
if (plFileInfo(fileName).FileSize() == mfs.fileSize)
|
||||
{
|
||||
plMD5Checksum cliMD5(fileName);
|
||||
plMD5Checksum srvMD5;
|
||||
srvMD5.SetFromHexString(plString::FromWchar(mfs.md5, 32).c_str());
|
||||
|
||||
if (cliMD5 == srvMD5)
|
||||
continue;
|
||||
else
|
||||
PatcherLog(kInfo, " Enqueueing %s: MD5 Checksums Differ", fileName.AsString().c_str());
|
||||
} else
|
||||
PatcherLog(kInfo, " Enqueueing %s: File Sizes Differ", fileName.AsString().c_str());
|
||||
|
||||
// If we're still here, then we need to update the file.
|
||||
float size = mfs.zipSize ? (float)mfs.zipSize : (float)mfs.fileSize;
|
||||
patcher->GetProgress()->SetLength(size + patcher->GetProgress()->GetMax());
|
||||
patcher->RequestFile(downloadName, fileName);
|
||||
}
|
||||
|
||||
patcher->IssueRequest();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static char* sLastError = nil;
|
||||
plResPatcher* plResPatcher::fInstance = nil;
|
||||
plResPatcher* plResPatcher::fInstance = nullptr;
|
||||
|
||||
plResPatcher* plResPatcher::GetInstance()
|
||||
{
|
||||
@ -199,134 +65,102 @@ plResPatcher* plResPatcher::GetInstance()
|
||||
|
||||
void plResPatcher::Shutdown()
|
||||
{
|
||||
// Better not call this while we're patching
|
||||
delete fInstance;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
plResPatcher::plResPatcher()
|
||||
: fPatching(false), fProgress(nil) { }
|
||||
|
||||
plResPatcher::~plResPatcher()
|
||||
void plResPatcher::OnCompletion(ENetError result, const plString& status)
|
||||
{
|
||||
if (fProgress)
|
||||
delete fProgress;
|
||||
plString error = plString::Null;
|
||||
if (IS_NET_ERROR(result))
|
||||
error = plString::Format("Update Failed: %S\n%s", NetErrorAsString(result), status.c_str());
|
||||
plgDispatch::Dispatch()->MsgQueue(new plResPatcherMsg(IS_NET_SUCCESS(result), error));
|
||||
}
|
||||
|
||||
void plResPatcher::IssueRequest()
|
||||
void plResPatcher::OnFileDownloadBegin(const plFileName& file)
|
||||
{
|
||||
if (!fPatching) return;
|
||||
if (fRequests.empty())
|
||||
// Wheee!
|
||||
Finish();
|
||||
else {
|
||||
Request req = fRequests.front();
|
||||
fRequests.pop();
|
||||
fProgress->SetTitle(plString::Format("Downloading %s...", file.GetFileName().c_str()));
|
||||
|
||||
plString title;
|
||||
if (req.fType == kManifest)
|
||||
{
|
||||
PatcherLog(kMajorStatus, " Downloading manifest... %s", req.fFile.AsString().c_str());
|
||||
title = plString::Format("Checking %s for updates...", req.fFile.AsString().c_str());
|
||||
NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.AsString().ToWchar());
|
||||
} else if (req.fType == kFile) {
|
||||
PatcherLog(kMajorStatus, " Downloading file... %s", req.fFriendlyName.AsString().c_str());
|
||||
title = plString::Format("Downloading... %s", req.fFriendlyName.GetFileName().c_str());
|
||||
|
||||
// If this is a PRP, we need to unload it from the ResManager
|
||||
|
||||
if (req.fFriendlyName.GetFileExt().CompareI("prp") == 0)
|
||||
((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(req.fFriendlyName);
|
||||
|
||||
plFileSystem::CreateDir(req.fFriendlyName.StripFileName(), true);
|
||||
plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile);
|
||||
if (stream->Open(req.fFriendlyName, "wb"))
|
||||
NetCliFileDownloadRequest(req.fFile, stream, FileDownloaded, this);
|
||||
else {
|
||||
PatcherLog(kError, " Unable to create file %s", req.fFriendlyName.AsString().c_str());
|
||||
Finish(false);
|
||||
}
|
||||
}
|
||||
|
||||
fProgress->SetTitle(title);
|
||||
if (file.GetFileExt().CompareI("prp") == 0) {
|
||||
plResManager* mgr = static_cast<plResManager*>(hsgResMgr::ResMgr());
|
||||
if (mgr)
|
||||
mgr->RemoveSinglePage(file);
|
||||
}
|
||||
}
|
||||
|
||||
void plResPatcher::Finish(bool success)
|
||||
void plResPatcher::OnFileDownloaded(const plFileName& file)
|
||||
{
|
||||
while (fRequests.size())
|
||||
fRequests.pop();
|
||||
|
||||
fPatching = false;
|
||||
if (success)
|
||||
PatcherLog(kHeader, "--- Patch Completed Successfully ---");
|
||||
else
|
||||
{
|
||||
PatcherLog(kHeader, "--- Patch Killed by Error ---");
|
||||
if (fProgress)
|
||||
fProgress->SetAborting();
|
||||
if (file.GetFileExt().CompareI("prp") == 0) {
|
||||
plResManager* mgr = static_cast<plResManager*>(hsgResMgr::ResMgr());
|
||||
if (mgr)
|
||||
mgr->AddSinglePage(file);
|
||||
}
|
||||
delete fProgress; fProgress = nil;
|
||||
|
||||
plResPatcherMsg* pMsg = new plResPatcherMsg(success, sLastError);
|
||||
delete[] sLastError; sLastError = nil;
|
||||
pMsg->Send(); // whoosh... off it goes
|
||||
}
|
||||
|
||||
void plResPatcher::RequestFile(const plFileName& srvName, const plFileName& cliName)
|
||||
void plResPatcher::OnProgressTick(uint64_t dl, uint64_t total, const plString& msg)
|
||||
{
|
||||
fRequests.push(Request(srvName, kFile, cliName));
|
||||
if (dl && total) {
|
||||
fProgress->SetLength(total);
|
||||
fProgress->SetHowMuch(dl);
|
||||
}
|
||||
|
||||
plString status = plString::Format("%s / %s",
|
||||
plFileSystem::ConvertFileSize(dl).c_str(),
|
||||
plFileSystem::ConvertFileSize(total).c_str()
|
||||
);
|
||||
|
||||
fProgress->SetStatusText(status);
|
||||
fProgress->SetInfoText(msg);
|
||||
}
|
||||
|
||||
void plResPatcher::RequestManifest(const plString& age)
|
||||
pfPatcher* plResPatcher::CreatePatcher()
|
||||
{
|
||||
fRequests.push(Request(age, kManifest));
|
||||
pfPatcher* patcher = new pfPatcher;
|
||||
patcher->OnCompletion(std::bind(&plResPatcher::OnCompletion, this, std::placeholders::_1, std::placeholders::_2));
|
||||
patcher->OnFileDownloadBegin(std::bind(&plResPatcher::OnFileDownloadBegin, this, std::placeholders::_1));
|
||||
patcher->OnFileDownloaded(std::bind(&plResPatcher::OnFileDownloaded, this, std::placeholders::_1));
|
||||
patcher->OnProgressTick(std::bind(&plResPatcher::OnProgressTick, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
return patcher;
|
||||
}
|
||||
|
||||
void plResPatcher::Start()
|
||||
void plResPatcher::InitProgress()
|
||||
{
|
||||
hsAssert(!fPatching, "Too many calls to plResPatcher::Start");
|
||||
fPatching = true;
|
||||
PatcherLog(kHeader, "--- Patch Started (%i requests) ---", fRequests.size());
|
||||
fProgress = plProgressMgr::GetInstance()->RegisterOperation(0.0, "Checking for updates...",
|
||||
plProgressMgr::kUpdateText, false, true);
|
||||
IssueRequest();
|
||||
// this is deleted in plAgeLoader::MsgReceive for thread safety
|
||||
fProgress = plProgressMgr::GetInstance()->RegisterOperation(0.f, nullptr, plProgressMgr::kUpdateText);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PatcherLog(PatcherLogType type, const char* format, ...)
|
||||
plResPatcher::plResPatcher()
|
||||
: fProgress(nullptr) { }
|
||||
|
||||
plResPatcher::~plResPatcher()
|
||||
{
|
||||
uint32_t color = 0;
|
||||
switch (type)
|
||||
{
|
||||
case kHeader: color = plStatusLog::kWhite; break;
|
||||
case kInfo: color = plStatusLog::kBlue; break;
|
||||
case kMajorStatus: color = plStatusLog::kYellow; break;
|
||||
case kStatus: color = plStatusLog::kGreen; break;
|
||||
case kError: color = plStatusLog::kRed; break;
|
||||
}
|
||||
|
||||
static plStatusLog* gStatusLog = nil;
|
||||
if (!gStatusLog)
|
||||
{
|
||||
gStatusLog = plStatusLogMgr::GetInstance().CreateStatusLog(
|
||||
20,
|
||||
"patcher.log",
|
||||
plStatusLog::kFilledBackground | plStatusLog::kAlignToTop | plStatusLog::kDeleteForMe);
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
if (type == kError)
|
||||
{
|
||||
sLastError = new char[1024]; // Deleted by Finish(false)
|
||||
vsnprintf(sLastError, 1024, format, args);
|
||||
gStatusLog->AddLine(sLastError, color);
|
||||
} else
|
||||
gStatusLog->AddLineV(color, format, args);
|
||||
|
||||
va_end(args);
|
||||
delete fProgress;
|
||||
}
|
||||
|
||||
void plResPatcher::Update(const std::vector<plString>& manifests)
|
||||
{
|
||||
if (gDataServerLocal)
|
||||
plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg());
|
||||
else {
|
||||
InitProgress();
|
||||
pfPatcher* patcher = CreatePatcher();
|
||||
patcher->RequestManifest(manifests);
|
||||
patcher->Start(); // whoosh... off it goes
|
||||
}
|
||||
}
|
||||
|
||||
void plResPatcher::Update(const plString& manifest)
|
||||
{
|
||||
if (gDataServerLocal)
|
||||
plgDispatch::Dispatch()->MsgSend(new plResPatcherMsg());
|
||||
else {
|
||||
InitProgress();
|
||||
pfPatcher* patcher = CreatePatcher();
|
||||
patcher->RequestManifest(manifest);
|
||||
patcher->Start(); // whoosh... off it goes
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,57 +39,47 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
|
||||
#ifndef plResPatcher_h_inc
|
||||
#define plResPatcher_h_inc
|
||||
|
||||
#include "HeadSpin.h"
|
||||
#include "plFileSystem.h"
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include "pnNetBase/pnNbError.h"
|
||||
#include <vector>
|
||||
|
||||
class plOperationProgress;
|
||||
class plString;
|
||||
|
||||
/**
|
||||
* Plasma Resource Patcher
|
||||
* This is a thin wrapper around \sa pfPatcher that ensures updates are propagated to the rest of the engine.
|
||||
*/
|
||||
class plResPatcher
|
||||
{
|
||||
enum { kManifest, kFile };
|
||||
struct Request
|
||||
{
|
||||
plFileName fFile;
|
||||
plFileName fFriendlyName;
|
||||
uint8_t fType;
|
||||
plOperationProgress* fProgress;
|
||||
static plResPatcher* fInstance;
|
||||
|
||||
Request(const plFileName& file, uint8_t type, const plFileName& friendly = "")
|
||||
: fFile(file), fFriendlyName(friendly), fType(type) { }
|
||||
};
|
||||
friend class plAgeLoader;
|
||||
|
||||
static plResPatcher* fInstance;
|
||||
std::queue<Request> fRequests;
|
||||
plOperationProgress* fProgress;
|
||||
bool fPatching;
|
||||
void OnCompletion(ENetError, const plString& msg);
|
||||
void OnFileDownloadBegin(const plFileName& file);
|
||||
void OnFileDownloaded(const plFileName& file);
|
||||
void OnProgressTick(uint64_t dl, uint64_t total, const plString& msg);
|
||||
|
||||
plResPatcher();
|
||||
~plResPatcher();
|
||||
class pfPatcher* CreatePatcher();
|
||||
void InitProgress();
|
||||
|
||||
public:
|
||||
static plResPatcher* GetInstance();
|
||||
static void Shutdown();
|
||||
|
||||
plOperationProgress* GetProgress() { return fProgress; }
|
||||
public:
|
||||
plResPatcher();
|
||||
~plResPatcher();
|
||||
|
||||
void Finish(bool success = true);
|
||||
void IssueRequest();
|
||||
void RequestFile(const plFileName& file, const plFileName& friendlyName);
|
||||
void RequestManifest(const plString& age);
|
||||
void Start();
|
||||
void Update(const std::vector<plString>& manifests);
|
||||
void Update(const plString& manifest);
|
||||
};
|
||||
|
||||
enum PatcherLogType
|
||||
{
|
||||
kHeader,
|
||||
kInfo,
|
||||
kMajorStatus,
|
||||
kStatus,
|
||||
kError,
|
||||
};
|
||||
void PatcherLog(PatcherLogType type, const char* format, ...);
|
||||
|
||||
#endif // _plResPatcher_h
|
||||
|
Reference in New Issue
Block a user