mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Implement new pfSecurePreloader
- Fetches a "SecurePreloader" manifest from the FileSrv, allowing gzipped python packages - Save data to the disk for future game launches. We only update if we detect what we loaded into memory doesn't match what the server has. - Falls back to downloading Python\*.pak and SDL\*.pak from the AuthSrv if the "SecurePreloader" manifest is not found.
This commit is contained in:
@ -317,10 +317,9 @@ hsBool plClient::Shutdown()
|
|||||||
plAgeLoader::SetInstance(nil);
|
plAgeLoader::SetInstance(nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pfSecurePreloader::IsInstanced())
|
if (pfSecurePreloader::GetInstance())
|
||||||
{
|
{
|
||||||
pfSecurePreloader::GetInstance()->Shutdown();
|
pfSecurePreloader::GetInstance()->Shutdown(); // will unregister itself
|
||||||
// pfSecurePreloader handles its own fixed key unregistration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fInputManager)
|
if (fInputManager)
|
||||||
@ -2517,6 +2516,8 @@ void plClient::ICompleteInit () {
|
|||||||
void plClient::IHandlePreloaderMsg (plPreloaderMsg * msg) {
|
void plClient::IHandlePreloaderMsg (plPreloaderMsg * msg) {
|
||||||
|
|
||||||
plgDispatch::Dispatch()->UnRegisterForExactType(plPreloaderMsg::Index(), GetKey());
|
plgDispatch::Dispatch()->UnRegisterForExactType(plPreloaderMsg::Index(), GetKey());
|
||||||
|
if (pfSecurePreloader* sp = pfSecurePreloader::GetInstance())
|
||||||
|
sp->Shutdown();
|
||||||
|
|
||||||
if (!msg->fSuccess) {
|
if (!msg->fSuccess) {
|
||||||
char str[1024];
|
char str[1024];
|
||||||
@ -2555,7 +2556,5 @@ void plClient::IHandleNetCommAuthMsg (plNetCommAuthMsg * msg) {
|
|||||||
plgDispatch::Dispatch()->RegisterForExactType(plPreloaderMsg::Index(), GetKey());
|
plgDispatch::Dispatch()->RegisterForExactType(plPreloaderMsg::Index(), GetKey());
|
||||||
|
|
||||||
// Precache our secure files
|
// Precache our secure files
|
||||||
pfSecurePreloader::GetInstance()->RequestFileGroup(L"Python", L"pak");
|
|
||||||
pfSecurePreloader::GetInstance()->RequestFileGroup(L"SDL", L"sdl");
|
|
||||||
pfSecurePreloader::GetInstance()->Start();
|
pfSecurePreloader::GetInstance()->Start();
|
||||||
}
|
}
|
||||||
|
@ -39,608 +39,401 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
Mead, WA 99021
|
Mead, WA 99021
|
||||||
|
|
||||||
*==LICENSE==*/
|
*==LICENSE==*/
|
||||||
#include "hsSTLStream.h"
|
|
||||||
#include "hsResMgr.h"
|
|
||||||
#include "plgDispatch.h"
|
|
||||||
#include "pnUtils/pnUtils.h"
|
|
||||||
#include "pnNetBase/pnNetBase.h"
|
|
||||||
#include "pnAsyncCore/pnAsyncCore.h"
|
|
||||||
#include "pnNetCli/pnNetCli.h"
|
|
||||||
#include "plNetGameLib/plNetGameLib.h"
|
|
||||||
#include "plFile/plFileUtils.h"
|
|
||||||
#include "plFile/plStreamSource.h"
|
|
||||||
#include "plNetCommon/plNetCommon.h"
|
|
||||||
#include "plProgressMgr/plProgressMgr.h"
|
|
||||||
#include "plMessage/plPreloaderMsg.h"
|
|
||||||
#include "plMessage/plNetCommMsgs.h"
|
|
||||||
#include "pfSecurePreloader.h"
|
#include "pfSecurePreloader.h"
|
||||||
|
|
||||||
#include "plNetClientComm/plNetClientComm.h"
|
#include "hsStream.h"
|
||||||
|
#include "plgDispatch.h"
|
||||||
|
#include "plCompression/plZlibStream.h"
|
||||||
|
#include "plEncryption/plChecksum.h"
|
||||||
|
#include "plFile/plFileUtils.h"
|
||||||
|
#include "plFile/plSecureStream.h"
|
||||||
|
#include "plFile/plStreamSource.h"
|
||||||
|
#include "plMessage/plNetCommMsgs.h"
|
||||||
|
#include "plMessage/plPreloaderMsg.h"
|
||||||
|
#include "plProgressMgr/plProgressMgr.h"
|
||||||
|
|
||||||
extern hsBool gDataServerLocal;
|
extern hsBool gDataServerLocal;
|
||||||
|
pfSecurePreloader* pfSecurePreloader::fInstance = nil;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Max number of concurrent file downloads
|
typedef std::pair<const wchar_t*, const wchar_t*> WcharPair;
|
||||||
static const unsigned kMaxConcurrency = 1;
|
|
||||||
|
|
||||||
pfSecurePreloader * pfSecurePreloader::fInstance;
|
struct AuthRequestParams
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Callback routines for the network code
|
|
||||||
|
|
||||||
// Called when a file's info is retrieved from the server
|
|
||||||
static void DefaultFileListRequestCallback(ENetError result, void* param, const NetCliAuthFileInfo infoArr[], unsigned infoCount)
|
|
||||||
{
|
{
|
||||||
bool success = !IS_NET_ERROR(result);
|
pfSecurePreloader* fThis;
|
||||||
|
std::queue<WcharPair> fFileGroups;
|
||||||
std::vector<std::wstring> filenames;
|
|
||||||
std::vector<UInt32> sizes;
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
filenames.reserve(infoCount);
|
|
||||||
sizes.reserve(infoCount);
|
|
||||||
for (unsigned curFile = 0; curFile < infoCount; curFile++)
|
|
||||||
{
|
|
||||||
filenames.push_back(infoArr[curFile].filename);
|
|
||||||
sizes.push_back(infoArr[curFile].filesize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
((pfSecurePreloader*)param)->RequestFinished(filenames, sizes, success);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when a file download is either finished, or failed
|
AuthRequestParams(pfSecurePreloader* parent)
|
||||||
static void DefaultFileRequestCallback(ENetError result, void* param, const wchar filename[], hsStream* stream)
|
: fThis(parent) { }
|
||||||
{
|
|
||||||
// Retry download unless shutting down or file not found
|
|
||||||
switch (result) {
|
|
||||||
case kNetSuccess:
|
|
||||||
((pfSecurePreloader*)param)->FinishedDownload(filename, true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kNetErrFileNotFound:
|
|
||||||
case kNetErrRemoteShutdown:
|
|
||||||
((pfSecurePreloader*)param)->FinishedDownload(filename, false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
stream->Rewind();
|
|
||||||
NetCliAuthFileRequest(
|
|
||||||
filename,
|
|
||||||
stream,
|
|
||||||
&DefaultFileRequestCallback,
|
|
||||||
param
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Our custom stream for writing directly to disk securely, and updating the
|
|
||||||
// progress bar. Does NOT support reading (cause it doesn't need to)
|
|
||||||
class Direct2DiskStream : public hsUNIXStream
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
wchar * fWriteFileName;
|
|
||||||
|
|
||||||
pfSecurePreloader* fPreloader;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Direct2DiskStream(pfSecurePreloader* preloader);
|
|
||||||
~Direct2DiskStream();
|
|
||||||
|
|
||||||
virtual hsBool Open(const char* name, const char* mode = "wb");
|
|
||||||
virtual hsBool Open(const wchar* name, const wchar* mode = L"wb");
|
|
||||||
virtual hsBool Close();
|
|
||||||
virtual UInt32 Read(UInt32 byteCount, void* buffer);
|
|
||||||
virtual UInt32 Write(UInt32 byteCount, const void* buffer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Direct2DiskStream::Direct2DiskStream(pfSecurePreloader* preloader) :
|
void ProcAuthDownloadParams(AuthRequestParams* params);
|
||||||
fWriteFileName(nil),
|
|
||||||
fPreloader(preloader)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Direct2DiskStream::~Direct2DiskStream()
|
void GotAuthSrvManifest(
|
||||||
{
|
ENetError result,
|
||||||
Close();
|
void* param,
|
||||||
}
|
const NetCliAuthFileInfo infoArr[],
|
||||||
|
UInt32 infoCount
|
||||||
hsBool Direct2DiskStream::Open(const char* name, const char* mode)
|
) {
|
||||||
{
|
AuthRequestParams* arp = (AuthRequestParams*)param;
|
||||||
wchar* wName = hsStringToWString(name);
|
if (IS_NET_ERROR(result))
|
||||||
wchar* wMode = hsStringToWString(mode);
|
|
||||||
hsBool ret = Open(wName, wMode);
|
|
||||||
delete [] wName;
|
|
||||||
delete [] wMode;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
hsBool Direct2DiskStream::Open(const wchar* name, const wchar* mode)
|
|
||||||
{
|
|
||||||
if (0 != wcscmp(mode, L"wb")) {
|
|
||||||
hsAssert(0, "Unsupported open mode");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fWriteFileName = TRACKED_NEW(wchar[wcslen(name) + 1]);
|
|
||||||
wcscpy(fWriteFileName, name);
|
|
||||||
|
|
||||||
// LogMsg(kLogPerf, L"Opening disk file %S", fWriteFileName);
|
|
||||||
return hsUNIXStream::Open(name, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
hsBool Direct2DiskStream::Close()
|
|
||||||
{
|
|
||||||
delete [] fWriteFileName;
|
|
||||||
fWriteFileName = nil;
|
|
||||||
return hsUNIXStream::Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 Direct2DiskStream::Read(UInt32 bytes, void* buffer)
|
|
||||||
{
|
|
||||||
hsAssert(0, "not implemented");
|
|
||||||
return 0; // we don't read
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 Direct2DiskStream::Write(UInt32 bytes, const void* buffer)
|
|
||||||
{
|
|
||||||
// LogMsg(kLogPerf, L"Writing %u bytes to disk file %S", bytes, fWriteFileName);
|
|
||||||
fPreloader->UpdateProgressBar(bytes);
|
|
||||||
return hsUNIXStream::Write(bytes, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// secure preloader class implementation
|
|
||||||
|
|
||||||
// closes and deletes all streams
|
|
||||||
void pfSecurePreloader::ICleanupStreams()
|
|
||||||
{
|
|
||||||
if (fD2DStreams.size() > 0)
|
|
||||||
{
|
{
|
||||||
std::map<std::wstring, hsStream*>::iterator curStream;
|
FATAL("Failed to get AuthSrv manifest!");
|
||||||
for (curStream = fD2DStreams.begin(); curStream != fD2DStreams.end(); curStream++)
|
arp->fThis->Terminate();
|
||||||
{
|
delete arp;
|
||||||
curStream->second->Close();
|
} else {
|
||||||
delete curStream->second;
|
arp->fThis->PreloadManifest(infoArr, infoCount);
|
||||||
curStream->second = nil;
|
ProcAuthDownloadParams(arp);
|
||||||
}
|
|
||||||
fD2DStreams.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// queues a single file to be preloaded (does nothing if already preloaded)
|
void GotFileSrvManifest(
|
||||||
void pfSecurePreloader::RequestSingleFile(std::wstring filename)
|
ENetError result,
|
||||||
{
|
void* param,
|
||||||
fileRequest request;
|
const wchar_t group[],
|
||||||
ZERO(request);
|
const NetCliFileManifestEntry manifest[],
|
||||||
request.fType = fileRequest::kSingleFile;
|
UInt32 entryCount
|
||||||
request.fPath = filename;
|
) {
|
||||||
request.fExt = L"";
|
pfSecurePreloader* sp = (pfSecurePreloader*)param;
|
||||||
|
if (result == kNetErrFileNotFound)
|
||||||
fRequests.push_back(request);
|
{
|
||||||
}
|
AuthRequestParams* params = new AuthRequestParams(sp);
|
||||||
|
params->fFileGroups.push(WcharPair(L"Python", L"pak"));
|
||||||
// queues a group of files to be preloaded (does nothing if already preloaded)
|
params->fFileGroups.push(WcharPair(L"SDL", L"sdl"));
|
||||||
void pfSecurePreloader::RequestFileGroup(std::wstring dir, std::wstring ext)
|
ProcAuthDownloadParams(params);
|
||||||
{
|
return;
|
||||||
fileRequest request;
|
} else if (!entryCount) {
|
||||||
ZERO(request);
|
FATAL("SecurePreloader manifest empty!");
|
||||||
request.fType = fileRequest::kFileList;
|
sp->Terminate();
|
||||||
request.fPath = dir;
|
|
||||||
request.fExt = ext;
|
|
||||||
|
|
||||||
fRequests.push_back(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
// preloads all requested files from the server (does nothing if already preloaded)
|
|
||||||
void pfSecurePreloader::Start()
|
|
||||||
{
|
|
||||||
if (gDataServerLocal) {
|
|
||||||
// using local data, don't do anything
|
|
||||||
plPreloaderMsg * msg = TRACKED_NEW plPreloaderMsg();
|
|
||||||
msg->fSuccess = true;
|
|
||||||
msg->Send();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetCliAuthGetEncryptionKey(fEncryptionKey, 4); // grab the encryption key from the server
|
sp->PreloadManifest(manifest, entryCount);
|
||||||
|
}
|
||||||
|
|
||||||
fNetError = false;
|
void FileDownloaded(
|
||||||
|
ENetError result,
|
||||||
// make sure we are all cleaned up
|
void* param,
|
||||||
ICleanupStreams();
|
const wchar_t filename[],
|
||||||
fTotalDataReceived = 0;
|
hsStream* writer
|
||||||
|
) {
|
||||||
// update the progress bar for downloading
|
pfSecurePreloader* sp = (pfSecurePreloader*)param;
|
||||||
if (!fProgressBar)
|
if (IS_NET_ERROR(result))
|
||||||
fProgressBar = plProgressMgr::GetInstance()->RegisterOperation((hsScalar)(fRequests.size()), "Getting file info...", plProgressMgr::kUpdateText, false, true);
|
|
||||||
|
|
||||||
for (unsigned curRequest = 0; curRequest < fRequests.size(); curRequest++)
|
|
||||||
{
|
{
|
||||||
fNumInfoRequestsRemaining++; // increment the counter
|
FATAL("SecurePreloader download failed");
|
||||||
if (fRequests[curRequest].fType == fileRequest::kSingleFile)
|
sp->Terminate();
|
||||||
{
|
} else {
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
sp->FilePreloaded(filename, writer);
|
||||||
// in internal releases, we can use on-disk files if they exist
|
}
|
||||||
if (plFileUtils::FileExists(fRequests[curRequest].fPath.c_str()))
|
}
|
||||||
{
|
|
||||||
fileInfo info;
|
|
||||||
info.fOriginalNameAndPath = fRequests[curRequest].fPath;
|
|
||||||
info.fSizeInBytes = plFileUtils::GetFileSize(info.fOriginalNameAndPath.c_str());
|
|
||||||
info.fDownloading = false;
|
|
||||||
info.fDownloaded = false;
|
|
||||||
info.fLocal = true;
|
|
||||||
|
|
||||||
// generate garbled name
|
void ProcAuthDownloadParams(AuthRequestParams* params)
|
||||||
wchar_t pathBuffer[MAX_PATH + 1];
|
{
|
||||||
wchar_t filename[arrsize(pathBuffer)];
|
// Request the "manifests" until there are none left, then download the files
|
||||||
GetTempPathW(arrsize(pathBuffer), pathBuffer);
|
if (params->fFileGroups.empty())
|
||||||
GetTempFileNameW(pathBuffer, L"CYN", 0, filename);
|
{
|
||||||
info.fGarbledNameAndPath = filename;
|
params->fThis->PreloadNextFile();
|
||||||
|
delete params;
|
||||||
|
} else {
|
||||||
|
WcharPair wp = params->fFileGroups.front();
|
||||||
|
params->fFileGroups.pop();
|
||||||
|
NetCliAuthFileListRequest(wp.first, wp.second, GotAuthSrvManifest, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fTotalDataDownload += info.fSizeInBytes;
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
fFileInfoMap[info.fOriginalNameAndPath] = info;
|
class pfSecurePreloaderStream : public plZlibStream
|
||||||
}
|
{
|
||||||
// internal client will still request it, even if it exists locally,
|
plOperationProgress* fProgress;
|
||||||
// so that things get updated properly
|
bool fIsZipped;
|
||||||
#endif // PLASMA_EXTERNAL_RELEASE
|
|
||||||
NetCliAuthFileListRequest(
|
public:
|
||||||
fRequests[curRequest].fPath.c_str(),
|
|
||||||
nil,
|
pfSecurePreloaderStream(plOperationProgress* prog, bool zipped)
|
||||||
&DefaultFileListRequestCallback,
|
: fProgress(prog), fIsZipped(zipped), plZlibStream()
|
||||||
(void*)this
|
{
|
||||||
);
|
fOutput = new hsRAMStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~pfSecurePreloaderStream()
|
||||||
|
{
|
||||||
|
delete fOutput;
|
||||||
|
fOutput = nil;
|
||||||
|
plZlibStream::Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
hsBool AtEnd() { return fOutput->AtEnd(); }
|
||||||
|
UInt32 GetEOF() { return fOutput->GetEOF(); }
|
||||||
|
UInt32 GetPosition() const { return fOutput->GetPosition(); }
|
||||||
|
UInt32 GetSizeLeft() const { return fOutput->GetSizeLeft(); }
|
||||||
|
UInt32 Read(UInt32 count, void* buf) { return fOutput->Read(count, buf); }
|
||||||
|
void Rewind() { fOutput->Rewind(); }
|
||||||
|
void SetPosition(UInt32 pos) { fOutput->SetPosition(pos); }
|
||||||
|
void Skip(UInt32 deltaByteCount) { fOutput->Skip(deltaByteCount); }
|
||||||
|
|
||||||
|
UInt32 Write(UInt32 count, const void* buf)
|
||||||
|
{
|
||||||
|
if (fProgress)
|
||||||
|
fProgress->Increment((hsScalar)count);
|
||||||
|
if (fIsZipped)
|
||||||
|
return plZlibStream::Write(count, buf);
|
||||||
else
|
else
|
||||||
{
|
return fOutput->Write(count, buf);
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
}
|
||||||
// in internal releases, we can use on-disk files if they exist
|
};
|
||||||
// Build the search string as "dir\\*.ext"
|
|
||||||
wchar searchStr[MAX_PATH];
|
|
||||||
|
|
||||||
PathAddFilename(searchStr, fRequests[curRequest].fPath.c_str(), L"*", arrsize(searchStr));
|
/////////////////////////////////////////////////////////////////////
|
||||||
PathSetExtension(searchStr, searchStr, fRequests[curRequest].fExt.c_str(), arrsize(searchStr));
|
|
||||||
|
|
||||||
ARRAY(PathFind) paths;
|
pfSecurePreloader::pfSecurePreloader()
|
||||||
PathFindFiles(&paths, searchStr, kPathFlagFile); // find all files that match
|
: fProgress(nil), fLegacyMode(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
// convert it to our little file info array
|
pfSecurePreloader::~pfSecurePreloader()
|
||||||
PathFind* curFile = paths.Ptr();
|
{
|
||||||
PathFind* lastFile = paths.Term();
|
while (fDownloadEntries.size())
|
||||||
while (curFile != lastFile) {
|
{
|
||||||
fileInfo info;
|
free((void*)fDownloadEntries.front());
|
||||||
info.fOriginalNameAndPath = curFile->name;
|
fDownloadEntries.pop();
|
||||||
info.fSizeInBytes = (UInt32)curFile->fileLength;
|
}
|
||||||
info.fDownloading = false;
|
|
||||||
info.fDownloaded = false;
|
|
||||||
info.fLocal = true;
|
|
||||||
|
|
||||||
// generate garbled name
|
while (fManifestEntries.size())
|
||||||
wchar_t pathBuffer[MAX_PATH + 1];
|
{
|
||||||
wchar_t filename[arrsize(pathBuffer)];
|
free((void*)fManifestEntries.front());
|
||||||
GetTempPathW(arrsize(pathBuffer), pathBuffer);
|
fManifestEntries.pop();
|
||||||
GetTempFileNameW(pathBuffer, L"CYN", 0, filename);
|
|
||||||
info.fGarbledNameAndPath = filename;
|
|
||||||
|
|
||||||
fTotalDataDownload += info.fSizeInBytes;
|
|
||||||
|
|
||||||
fFileInfoMap[info.fOriginalNameAndPath] = info;
|
|
||||||
curFile++;
|
|
||||||
}
|
|
||||||
#endif // PLASMA_EXTERNAL_RELEASE
|
|
||||||
|
|
||||||
NetCliAuthFileListRequest(
|
|
||||||
fRequests[curRequest].fPath.c_str(),
|
|
||||||
fRequests[curRequest].fExt.c_str(),
|
|
||||||
&DefaultFileListRequestCallback,
|
|
||||||
(void*)this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// closes all file pointers and cleans up after itself
|
hsRAMStream* pfSecurePreloader::LoadToMemory(const wchar_t* file) const
|
||||||
void pfSecurePreloader::Cleanup()
|
|
||||||
{
|
{
|
||||||
ICleanupStreams();
|
if (!plFileUtils::FileExists(file))
|
||||||
|
return nil;
|
||||||
|
|
||||||
fRequests.clear();
|
hsUNIXStream s;
|
||||||
fFileInfoMap.clear();
|
hsRAMStream* ram = new hsRAMStream;
|
||||||
|
s.Open(file);
|
||||||
fNumInfoRequestsRemaining = 0;
|
|
||||||
fTotalDataDownload = 0;
|
|
||||||
fTotalDataReceived = 0;
|
|
||||||
|
|
||||||
DEL(fProgressBar);
|
|
||||||
fProgressBar = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void pfSecurePreloader::RequestFinished(const std::vector<std::wstring> & filenames, const std::vector<UInt32> & sizes, bool succeeded)
|
|
||||||
{
|
|
||||||
fNetError |= !succeeded;
|
|
||||||
|
|
||||||
if (succeeded)
|
UInt32 loadLen = 1024 * 1024;
|
||||||
{
|
UInt8* buf = new UInt8[loadLen];
|
||||||
unsigned count = 0;
|
while (UInt32 read = s.Read(loadLen, buf))
|
||||||
for (int curFile = 0; curFile < filenames.size(); curFile++)
|
ram->Write(read, buf);
|
||||||
{
|
delete[] buf;
|
||||||
if (fFileInfoMap.find(filenames[curFile]) != fFileInfoMap.end())
|
|
||||||
continue; // if it is a duplicate, ignore it (the duplicate is probably one we found locally)
|
|
||||||
|
|
||||||
fileInfo info;
|
s.Close();
|
||||||
info.fOriginalNameAndPath = filenames[curFile];
|
ram->Rewind();
|
||||||
info.fSizeInBytes = sizes[curFile];
|
return ram;
|
||||||
info.fDownloading = false;
|
|
||||||
info.fDownloaded = false;
|
|
||||||
info.fLocal = false; // if we get here, it was retrieved remotely
|
|
||||||
|
|
||||||
// generate garbled name
|
|
||||||
wchar_t pathBuffer[MAX_PATH + 1];
|
|
||||||
wchar_t filename[arrsize(pathBuffer)];
|
|
||||||
GetTempPathW(arrsize(pathBuffer), pathBuffer);
|
|
||||||
GetTempFileNameW(pathBuffer, L"CYN", 0, filename);
|
|
||||||
info.fGarbledNameAndPath = filename;
|
|
||||||
|
|
||||||
fTotalDataDownload += info.fSizeInBytes;
|
|
||||||
|
|
||||||
fFileInfoMap[info.fOriginalNameAndPath] = info;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
LogMsg(kLogPerf, "Added %u files to secure download queue", count);
|
|
||||||
}
|
|
||||||
if (fProgressBar)
|
|
||||||
fProgressBar->Increment(1.f);
|
|
||||||
|
|
||||||
--fNumInfoRequestsRemaining; // even if we fail, decrement the counter
|
|
||||||
|
|
||||||
if (succeeded) {
|
|
||||||
DEL(fProgressBar);
|
|
||||||
fProgressBar = plProgressMgr::GetInstance()->RegisterOperation((hsScalar)(fTotalDataDownload), "Downloading...", plProgressMgr::kUpdateText, false, true);
|
|
||||||
|
|
||||||
// Issue some file download requests (up to kMaxConcurrency)
|
|
||||||
IIssueDownloadRequests();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
IPreloadComplete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
void pfSecurePreloader::SaveFile(hsStream* file, const wchar_t* name) const
|
||||||
void pfSecurePreloader::IIssueDownloadRequests () {
|
{
|
||||||
|
hsUNIXStream s;
|
||||||
|
s.Open(name, L"wb");
|
||||||
|
UInt32 pos = file->GetPosition();
|
||||||
|
file->Rewind();
|
||||||
|
|
||||||
std::map<std::wstring, fileInfo>::iterator curFile;
|
UInt32 loadLen = 1024 * 1024;
|
||||||
for (curFile = fFileInfoMap.begin(); curFile != fFileInfoMap.end(); curFile++)
|
UInt8* buf = new UInt8[loadLen];
|
||||||
|
while (UInt32 read = file->Read(loadLen, buf))
|
||||||
|
s.Write(read, buf);
|
||||||
|
file->SetPosition(pos);
|
||||||
|
s.Close();
|
||||||
|
delete[] buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pfSecurePreloader::IsZipped(const wchar_t* filename) const
|
||||||
|
{
|
||||||
|
return wcscmp(plFileUtils::GetFileExt(filename), L"gz") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pfSecurePreloader::PreloadNextFile()
|
||||||
|
{
|
||||||
|
if (fManifestEntries.empty())
|
||||||
{
|
{
|
||||||
// Skip files already downloaded or currently downloading
|
Finish();
|
||||||
if (curFile->second.fDownloaded || curFile->second.fDownloading)
|
return;
|
||||||
continue;
|
|
||||||
|
|
||||||
std::wstring filename = curFile->second.fOriginalNameAndPath;
|
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
|
||||||
// in internal releases, we can use on-disk files if they exist
|
|
||||||
if (plFileUtils::FileExists(filename.c_str()))
|
|
||||||
{
|
|
||||||
// don't bother streaming, just make the secure stream using the local file
|
|
||||||
|
|
||||||
// a local key overrides the server-downloaded key
|
|
||||||
UInt32 localKey[4];
|
|
||||||
bool hasLocalKey = plFileUtils::GetSecureEncryptionKey(filename.c_str(), localKey, arrsize(localKey));
|
|
||||||
hsStream* stream = nil;
|
|
||||||
if (hasLocalKey)
|
|
||||||
stream = plSecureStream::OpenSecureFile(filename.c_str(), 0, localKey);
|
|
||||||
else
|
|
||||||
stream = plSecureStream::OpenSecureFile(filename.c_str(), 0, fEncryptionKey);
|
|
||||||
|
|
||||||
// add it to the stream source
|
|
||||||
bool added = plStreamSource::GetInstance()->InsertFile(filename.c_str(), stream);
|
|
||||||
if (!added)
|
|
||||||
DEL(stream); // wasn't added, so nuke our local copy
|
|
||||||
|
|
||||||
// and make sure the vars are set up right
|
|
||||||
curFile->second.fDownloaded = true;
|
|
||||||
curFile->second.fLocal = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
// Enforce concurrency limit
|
|
||||||
if (fNumDownloadRequestsRemaining >= kMaxConcurrency)
|
|
||||||
break;
|
|
||||||
|
|
||||||
curFile->second.fDownloading = true;
|
|
||||||
curFile->second.fDownloaded = false;
|
|
||||||
curFile->second.fLocal = false;
|
|
||||||
|
|
||||||
// create and setup the stream
|
|
||||||
Direct2DiskStream* fileStream = TRACKED_NEW Direct2DiskStream(this);
|
|
||||||
fileStream->Open(curFile->second.fGarbledNameAndPath.c_str(), L"wb");
|
|
||||||
fD2DStreams[filename] = (hsStream*)fileStream;
|
|
||||||
|
|
||||||
// request the file from the server
|
|
||||||
LogMsg(kLogPerf, L"Requesting secure file:%s", filename.c_str());
|
|
||||||
++fNumDownloadRequestsRemaining;
|
|
||||||
NetCliAuthFileRequest(
|
|
||||||
filename.c_str(),
|
|
||||||
(hsStream*)fileStream,
|
|
||||||
&DefaultFileRequestCallback,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wchar_t* filename = fDownloadEntries.front();
|
||||||
|
hsStream* s = new pfSecurePreloaderStream(fProgress, IsZipped(filename));
|
||||||
|
|
||||||
if (!fNumDownloadRequestsRemaining)
|
// Thankfully, both callbacks have the same arguments
|
||||||
IPreloadComplete();
|
if (fLegacyMode)
|
||||||
}
|
NetCliAuthFileRequest(filename, s, FileDownloaded, this);
|
||||||
|
|
||||||
void pfSecurePreloader::UpdateProgressBar(UInt32 bytesReceived)
|
|
||||||
{
|
|
||||||
fTotalDataReceived += bytesReceived;
|
|
||||||
if (fTotalDataReceived > fTotalDataDownload)
|
|
||||||
fTotalDataReceived = fTotalDataDownload; // shouldn't happen... but just in case
|
|
||||||
|
|
||||||
if (fProgressBar)
|
|
||||||
fProgressBar->Increment((hsScalar)bytesReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pfSecurePreloader::FinishedDownload(std::wstring filename, bool succeeded)
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (fFileInfoMap.find(filename) == fFileInfoMap.end())
|
|
||||||
{
|
|
||||||
// file doesn't exist... abort
|
|
||||||
succeeded = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fFileInfoMap[filename].fDownloading = false;
|
|
||||||
|
|
||||||
// close and delete the writer stream (even if we failed)
|
|
||||||
fD2DStreams[filename]->Close();
|
|
||||||
delete fD2DStreams[filename];
|
|
||||||
fD2DStreams.erase(fD2DStreams.find(filename));
|
|
||||||
|
|
||||||
if (succeeded)
|
|
||||||
{
|
|
||||||
// open a secure stream to that file
|
|
||||||
hsStream* stream = plSecureStream::OpenSecureFile(
|
|
||||||
fFileInfoMap[filename].fGarbledNameAndPath.c_str(),
|
|
||||||
plSecureStream::kRequireEncryption | plSecureStream::kDeleteOnExit, // force delete and encryption
|
|
||||||
fEncryptionKey
|
|
||||||
);
|
|
||||||
|
|
||||||
bool addedToSource = plStreamSource::GetInstance()->InsertFile(filename.c_str(), stream);
|
|
||||||
if (!addedToSource)
|
|
||||||
DEL(stream); // cleanup if it wasn't added
|
|
||||||
|
|
||||||
fFileInfoMap[filename].fDownloaded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// file download failed, clean up after it
|
|
||||||
|
|
||||||
// delete the temporary file
|
|
||||||
if (plFileUtils::FileExists(fFileInfoMap[filename].fGarbledNameAndPath.c_str()))
|
|
||||||
plFileUtils::RemoveFile(fFileInfoMap[filename].fGarbledNameAndPath.c_str(), true);
|
|
||||||
|
|
||||||
// and remove it from the info map
|
|
||||||
fFileInfoMap.erase(fFileInfoMap.find(filename));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fNetError |= !succeeded;
|
|
||||||
--fNumDownloadRequestsRemaining;
|
|
||||||
LogMsg(kLogPerf, L"Received secure file:%s, success:%s", filename.c_str(), succeeded ? L"Yep" : L"Nope");
|
|
||||||
|
|
||||||
if (!succeeded)
|
|
||||||
IPreloadComplete();
|
|
||||||
else
|
else
|
||||||
// Issue some file download requests (up to kMaxConcurrency)
|
NetCliFileDownloadRequest(filename, s, FileDownloaded, this);
|
||||||
IIssueDownloadRequests();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
void pfSecurePreloader::Init()
|
||||||
void pfSecurePreloader::INotifyAuthReconnected () {
|
{
|
||||||
|
RegisterAs(kSecurePreloader_KEY);
|
||||||
|
// TODO: If we're going to support reconnects, then let's do it right.
|
||||||
|
// Later...
|
||||||
|
//plgDispatch::Dispatch()->RegisterForExactType(plNetCommAuthConnectedMsg::Index(), GetKey());
|
||||||
|
}
|
||||||
|
|
||||||
// The secure file download network protocol will now just pick up downloading
|
void pfSecurePreloader::Start()
|
||||||
// where it left off before the reconnect, so no need to reset in-progress files.
|
{
|
||||||
|
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||||
|
// Using local data? Move along, move along...
|
||||||
|
if (gDataServerLocal)
|
||||||
|
{
|
||||||
|
Finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NetCliAuthGetEncryptionKey(fEncryptionKey, 4);
|
||||||
|
|
||||||
/*
|
// TODO: Localize
|
||||||
std::map<std::wstring, fileInfo>::iterator curFile;
|
fProgress = plProgressMgr::GetInstance()->RegisterOperation(0.0f, "Checking for Updates", plProgressMgr::kUpdateText, false, true);
|
||||||
for (curFile = fFileInfoMap.begin(); curFile != fFileInfoMap.end(); curFile++) {
|
|
||||||
|
|
||||||
// Reset files that were currently downloading
|
// Now, we need to fetch the "SecurePreloader" manifest from the file server, which will contain the python and SDL files.
|
||||||
if (curFile->second.fDownloading)
|
// We're basically reimplementing plResPatcher here, except preferring to keep everything in memory, then flush to disk
|
||||||
curFile->second.fDownloading = false;
|
// when we're done. If this fails, then we shall download everything from the AuthSrv like in the old days.
|
||||||
|
NetCliFileManifestRequest(GotFileSrvManifest, this, L"SecurePreloader");
|
||||||
|
}
|
||||||
|
|
||||||
|
void pfSecurePreloader::Terminate()
|
||||||
|
{
|
||||||
|
FATAL("pfSecurePreloader failure");
|
||||||
|
|
||||||
|
plPreloaderMsg* msg = new plPreloaderMsg;
|
||||||
|
msg->fSuccess = false;
|
||||||
|
plgDispatch::Dispatch()->MsgSend(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pfSecurePreloader::Finish()
|
||||||
|
{
|
||||||
|
plPreloaderMsg* msg = new plPreloaderMsg;
|
||||||
|
msg->fSuccess = true;
|
||||||
|
plgDispatch::Dispatch()->MsgSend(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pfSecurePreloader::Shutdown()
|
||||||
|
{
|
||||||
|
SetInstance(nil);
|
||||||
|
if (fProgress)
|
||||||
|
{
|
||||||
|
delete fProgress;
|
||||||
|
fProgress = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fNumDownloadRequestsRemaining > 0) {
|
// Takes care of UnReffing us
|
||||||
|
UnRegisterAs(kSecurePreloader_KEY);
|
||||||
LogMsg(kLogPerf, L"pfSecurePreloader: Auth reconnected, resetting in-progress file downloads");
|
|
||||||
|
|
||||||
// Issue some file download requests (up to kMaxConcurrency)
|
|
||||||
IIssueDownloadRequests();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
void pfSecurePreloader::PreloadManifest(const NetCliAuthFileInfo manifestEntries[], UInt32 entryCount)
|
||||||
void pfSecurePreloader::IPreloadComplete () {
|
{
|
||||||
DEL(fProgressBar);
|
UInt32 totalBytes = 0;
|
||||||
fProgressBar = nil;
|
if (fProgress)
|
||||||
|
totalBytes = (UInt32)fProgress->GetMax();
|
||||||
plPreloaderMsg * msg = TRACKED_NEW plPreloaderMsg();
|
fLegacyMode = true;
|
||||||
msg->fSuccess = !fNetError;
|
|
||||||
msg->Send();
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
for (UInt32 i = 0; i < entryCount; ++i)
|
||||||
hsBool pfSecurePreloader::MsgReceive (plMessage * msg) {
|
{
|
||||||
|
const NetCliAuthFileInfo mfs = manifestEntries[i];
|
||||||
|
fDownloadEntries.push(wcsdup(mfs.filename));
|
||||||
|
if (IsZipped(mfs.filename))
|
||||||
|
{
|
||||||
|
wchar_t* name = wcsdup(mfs.filename);
|
||||||
|
plFileUtils::StripExt(name);
|
||||||
|
fManifestEntries.push(name);
|
||||||
|
|
||||||
|
} else
|
||||||
|
fManifestEntries.push(wcsdup(mfs.filename));
|
||||||
|
|
||||||
if (plNetCommAuthConnectedMsg * authMsg = plNetCommAuthConnectedMsg::ConvertNoRef(msg)) {
|
totalBytes += mfs.filesize;
|
||||||
|
|
||||||
INotifyAuthReconnected();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hsKeyedObject::MsgReceive(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
pfSecurePreloader * pfSecurePreloader::GetInstance () {
|
|
||||||
|
|
||||||
if (!fInstance) {
|
|
||||||
|
|
||||||
fInstance = NEWZERO(pfSecurePreloader);
|
|
||||||
fInstance->RegisterAs(kSecurePreloader_KEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fInstance;
|
if (fProgress)
|
||||||
}
|
{
|
||||||
|
fProgress->SetLength((hsScalar)totalBytes);
|
||||||
//============================================================================
|
fProgress->SetTitle("Downloading...");
|
||||||
bool pfSecurePreloader::IsInstanced () {
|
|
||||||
|
|
||||||
return fInstance != nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void pfSecurePreloader::Init () {
|
|
||||||
|
|
||||||
if (!fInitialized) {
|
|
||||||
|
|
||||||
fInitialized = true;
|
|
||||||
plgDispatch::Dispatch()->RegisterForExactType(plNetCommAuthConnectedMsg::Index(), GetKey());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
void pfSecurePreloader::PreloadManifest(const NetCliFileManifestEntry manifestEntries[], UInt32 entryCount)
|
||||||
void pfSecurePreloader::Shutdown () {
|
{
|
||||||
|
UInt32 totalBytes = 0;
|
||||||
|
for (UInt32 i = 0; i < entryCount; ++i)
|
||||||
|
{
|
||||||
|
const NetCliFileManifestEntry mfs = manifestEntries[i];
|
||||||
|
bool fetchMe = true;
|
||||||
|
hsRAMStream* s = nil;
|
||||||
|
|
||||||
if (fInitialized) {
|
if (plFileUtils::FileExists(mfs.clientName))
|
||||||
|
{
|
||||||
fInitialized = false;
|
s = LoadToMemory(mfs.clientName);
|
||||||
plgDispatch::Dispatch()->UnRegisterForExactType(plNetCommAuthConnectedMsg::Index(), GetKey());
|
if (s)
|
||||||
|
{
|
||||||
|
// Damn this
|
||||||
|
const char* md5 = hsWStringToString(mfs.md5);
|
||||||
|
plMD5Checksum srvHash;
|
||||||
|
srvHash.SetFromHexString(md5);
|
||||||
|
delete[] md5;
|
||||||
|
|
||||||
|
// Now actually copare the hashes
|
||||||
|
plMD5Checksum lclHash;
|
||||||
|
lclHash.CalcFromStream(s);
|
||||||
|
fetchMe = (srvHash != lclHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fetchMe)
|
||||||
|
{
|
||||||
|
fManifestEntries.push(wcsdup(mfs.clientName));
|
||||||
|
fDownloadEntries.push(wcsdup(mfs.downloadName));
|
||||||
|
if (IsZipped(mfs.downloadName))
|
||||||
|
totalBytes += mfs.zipSize;
|
||||||
|
else
|
||||||
|
totalBytes += mfs.fileSize;
|
||||||
|
} else {
|
||||||
|
plSecureStream* ss = new plSecureStream(s, fEncryptionKey);
|
||||||
|
plStreamSource::GetInstance()->InsertFile(mfs.clientName, ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s)
|
||||||
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fInstance) {
|
if (totalBytes && fProgress)
|
||||||
|
{
|
||||||
fInstance->UnRegister();
|
fProgress->SetLength((hsScalar)totalBytes);
|
||||||
fInstance = nil;
|
fProgress->SetTitle("Downloading...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method uses only one manifest, so we're good to go now!
|
||||||
|
PreloadNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
void pfSecurePreloader::FilePreloaded(const wchar_t* file, hsStream* stream)
|
||||||
pfSecurePreloader::pfSecurePreloader () {
|
{
|
||||||
|
// Clear out queue
|
||||||
|
fDownloadEntries.pop();
|
||||||
|
const wchar_t* clientName = fManifestEntries.front(); // Stolen by plStreamSource
|
||||||
|
fManifestEntries.pop();
|
||||||
|
|
||||||
|
if (!fLegacyMode) // AuthSrv data caching is useless
|
||||||
|
{
|
||||||
|
plFileUtils::EnsureFilePathExists(clientName);
|
||||||
|
SaveFile(stream, clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
plSecureStream* ss = new plSecureStream(stream, fEncryptionKey);
|
||||||
|
plStreamSource::GetInstance()->InsertFile(clientName, ss);
|
||||||
|
delete stream; // SecureStream holds its own decrypted buffer
|
||||||
|
|
||||||
|
// Continue down the warpath
|
||||||
|
PreloadNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
pfSecurePreloader* pfSecurePreloader::GetInstance()
|
||||||
pfSecurePreloader::~pfSecurePreloader () {
|
{
|
||||||
|
if (!fInstance)
|
||||||
Cleanup();
|
fInstance = new pfSecurePreloader;
|
||||||
|
return fInstance;
|
||||||
}
|
}
|
||||||
|
@ -42,15 +42,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#ifndef __pfSecurePreloader_h__
|
#ifndef __pfSecurePreloader_h__
|
||||||
#define __pfSecurePreloader_h__
|
#define __pfSecurePreloader_h__
|
||||||
|
|
||||||
#include "hsTypes.h"
|
#include "HeadSpin.h"
|
||||||
#include "hsStlUtils.h"
|
|
||||||
#include "hsCritSect.h"
|
|
||||||
#include "hsStream.h"
|
|
||||||
#include "plFile/plSecureStream.h"
|
|
||||||
#include "pnKeyedObject/hsKeyedObject.h"
|
#include "pnKeyedObject/hsKeyedObject.h"
|
||||||
|
#include "plNetGameLib/plNetGameLib.h"
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
class plOperationProgress;
|
class plOperationProgress;
|
||||||
|
class hsRAMStream;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// pfSecurePreloader - a class for handling files we want downloaded from the
|
// pfSecurePreloader - a class for handling files we want downloaded from the
|
||||||
@ -60,75 +58,40 @@ class plOperationProgress;
|
|||||||
class pfSecurePreloader : public hsKeyedObject
|
class pfSecurePreloader : public hsKeyedObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static pfSecurePreloader * fInstance;
|
|
||||||
|
|
||||||
struct fileRequest
|
static pfSecurePreloader* fInstance;
|
||||||
{
|
std::queue<const wchar_t*> fManifestEntries;
|
||||||
enum requestType {kSingleFile, kFileList};
|
std::queue<const wchar_t*> fDownloadEntries;
|
||||||
requestType fType;
|
plOperationProgress* fProgress;
|
||||||
std::wstring fPath; // filename if kSingleFile, path if kFileList
|
UInt32 fEncryptionKey[4];
|
||||||
std::wstring fExt; // blank if kSingleFile, extension if kFileList
|
bool fLegacyMode;
|
||||||
};
|
|
||||||
std::vector<fileRequest> fRequests;
|
|
||||||
|
|
||||||
struct fileInfo
|
hsRAMStream* LoadToMemory(const wchar_t* file) const;
|
||||||
{
|
void SaveFile(hsStream* file, const wchar_t* name) const;
|
||||||
std::wstring fOriginalNameAndPath; // the human-readable name
|
bool IsZipped(const wchar_t* filename) const;
|
||||||
std::wstring fGarbledNameAndPath; // the garbled temp name of the file on disk
|
|
||||||
UInt32 fSizeInBytes; // the total size of the file
|
|
||||||
bool fDownloading; // is this file currently downloading?
|
|
||||||
bool fDownloaded; // is this file completely downloaded?
|
|
||||||
bool fLocal; // is the file a local copy?
|
|
||||||
};
|
|
||||||
std::map<std::wstring, fileInfo> fFileInfoMap; // key is human-readable name
|
|
||||||
std::map<std::wstring, hsStream*> fD2DStreams; // direct-to-disk streams, only used while downloading from the server
|
|
||||||
|
|
||||||
UInt32 fNumInfoRequestsRemaining; // the number of file info requests that are still pending
|
|
||||||
UInt32 fNumDownloadRequestsRemaining; // the number of file download requests that are still pending
|
|
||||||
UInt32 fTotalDataDownload; // the amount of data we need to download, for progress bar tracking
|
|
||||||
UInt32 fTotalDataReceived; // the amount of data we have already preloaded, for progress bar tracking
|
|
||||||
bool fNetError;
|
|
||||||
bool fInitialized;
|
|
||||||
|
|
||||||
UInt32 fEncryptionKey[4]; // encryption key for all the secure files
|
|
||||||
|
|
||||||
plOperationProgress* fProgressBar;
|
|
||||||
|
|
||||||
void IIssueDownloadRequests ();
|
|
||||||
void IPreloadComplete ();
|
|
||||||
|
|
||||||
void ICleanupStreams(); // closes and deletes all streams
|
|
||||||
|
|
||||||
void INotifyAuthReconnected ();
|
|
||||||
|
|
||||||
pfSecurePreloader ();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
pfSecurePreloader();
|
||||||
|
~pfSecurePreloader();
|
||||||
|
|
||||||
CLASSNAME_REGISTER(pfSecurePreloader);
|
CLASSNAME_REGISTER(pfSecurePreloader);
|
||||||
GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject);
|
GETINTERFACE_ANY(pfSecurePreloader, hsKeyedObject);
|
||||||
|
|
||||||
~pfSecurePreloader ();
|
void Init();
|
||||||
|
void Start();
|
||||||
void Init ();
|
void Terminate();
|
||||||
void Shutdown ();
|
void Finish();
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
// Client interface functions
|
void PreloadManifest(const NetCliFileManifestEntry manifestEntries[], UInt32 entryCount);
|
||||||
void RequestSingleFile(std::wstring filename); // queues a single file to be preloaded (does nothing if already preloaded)
|
void PreloadManifest(const NetCliAuthFileInfo manifestEntries[], UInt32 entryCount);
|
||||||
void RequestFileGroup(std::wstring dir, std::wstring ext); // queues a group of files to be preloaded (does nothing if already preloaded)
|
void PreloadNextFile();
|
||||||
void Start(); // sends all queued requests (does nothing if already preloaded)
|
void FilePreloaded(const wchar_t* filename, hsStream* stream);
|
||||||
void Cleanup(); // closes all file pointers and cleans up after itself
|
|
||||||
|
plOperationProgress* GetProgressBar() { return fProgress; }
|
||||||
|
|
||||||
// Functions for the network callbacks
|
static pfSecurePreloader* GetInstance();
|
||||||
void RequestFinished(const std::vector<std::wstring> & filenames, const std::vector<UInt32> & sizes, bool succeeded);
|
static void SetInstance(pfSecurePreloader* instance) { fInstance = instance; }
|
||||||
void UpdateProgressBar(UInt32 bytesReceived);
|
|
||||||
void FinishedDownload(std::wstring filename, bool succeeded);
|
|
||||||
|
|
||||||
// Instance handling
|
|
||||||
static pfSecurePreloader * GetInstance ();
|
|
||||||
static bool IsInstanced ();
|
|
||||||
|
|
||||||
// hsKeyedObject
|
|
||||||
hsBool MsgReceive (plMessage * msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __pfSecurePreloader_h__
|
#endif // __pfSecurePreloader_h__
|
||||||
|
Reference in New Issue
Block a user