From 1f78a7673717c8cc071692d7fde0751ec615bfee Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 3 Feb 2012 23:23:57 -0500 Subject: [PATCH 1/3] Handle failed downloads better Now, we unlink anything that fails to download. This is more useful than leaving a truncated (0 byte) file on the user's HD. --- .../PubUtilLib/plAgeLoader/plResPatcher.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index a98d146d..c7599db3 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp @@ -59,15 +59,28 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com class plResDownloadStream : public plZlibStream { plOperationProgress* fProgress; + char* fFilename; bool fIsZipped; public: plResDownloadStream(plOperationProgress* prog, const wchar_t* reqFile) - : fProgress(prog) + : fProgress(prog), fFilename(nil) { fIsZipped = wcscmp(plFileUtils::GetFileExt(reqFile), L"gz") == 0; } + ~plResDownloadStream() + { + if (fFilename) + delete[] fFilename; + } + + hsBool Open(const char* filename, const char* mode) + { + fFilename = hsStrcpy(filename); + return plZlibStream::Open(filename, mode); + } + uint32_t Write(uint32_t count, const void* buf) { fProgress->Increment((float)count); @@ -78,6 +91,7 @@ public: } bool IsZipped() const { return fIsZipped; } + void Unlink() const { plFileUtils::RemoveFile(fFilename); } }; ///////////////////////////////////////////////////////////////////////////// @@ -93,7 +107,6 @@ static void FileDownloaded( if (((plResDownloadStream*)writer)->IsZipped()) plFileUtils::StripExt(name); // Kill off .gz writer->Close(); - delete writer; switch (result) { @@ -107,6 +120,7 @@ static void FileDownloaded( // Continue down the warpath patcher->IssueRequest(); delete[] name; + delete writer; return; case kNetErrFileNotFound: PatcherLog(kError, " Download Failed: %s not found", name); @@ -119,8 +133,10 @@ static void FileDownloaded( } // Failure case + ((plResDownloadStream*)writer)->Unlink(); patcher->Finish(false); delete[] name; + delete writer; } static void ManifestDownloaded( From 2599bfbd7a8c6b145dc59d6bc6fc6f0f57764cc1 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 3 Feb 2012 23:24:49 -0500 Subject: [PATCH 2/3] Add an error message for NCAgeJoiner failures Since we have a pfSecurePreloader that doesn't redownload every single launch, I don't feel bad about presenting an error message to the user and killing the client. This is really better than letting them languish at a black screen, groping for the relto book. --- .../PubUtilLib/plNetClient/plNetLinkingMgr.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index ea092f92..9749fb4f 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetTransport/plNetTransportMember.h" // OfferLinkToPlayer() #include "plgDispatch.h" +#include "pnMessage/plClientMsg.h" #include "pnMessage/plTimeMsg.h" #include "plMessage/plLinkToAgeMsg.h" #include "pnKeyedObject/plKey.h" @@ -159,8 +160,19 @@ void plNetLinkingMgr::NCAgeJoinerCallback ( void * notify, void * userState ) { - plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); + NCAgeJoinerCompleteNotify* params = (NCAgeJoinerCompleteNotify*)notify; + + // Tell the user we failed to link. + // In the future, we might want to try graceful recovery (link back to Relto?) + if (!params->success) { + plNetClientMgr::StaticErrorMsg(params->msg); + hsMessageBox(params->msg, "Linking Error", hsMessageBoxNormal, hsMessageBoxIconError); + plClientMsg* clientMsg = new plClientMsg(plClientMsg::kQuit); + clientMsg->Send(hsgResMgr::ResMgr()->FindKey(kClient_KEY)); + return; + } + plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); switch (type) { case kAgeJoinerComplete: { ASSERT(joiner == s_ageJoiner); From e6f31948330c7cbb29b2d697fce43ffa24a77f70 Mon Sep 17 00:00:00 2001 From: branan Date: Sat, 4 Feb 2012 09:41:18 -0800 Subject: [PATCH 3/3] Only shutdown external clients on link fail --- Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index 9749fb4f..9c0fdc9d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -167,8 +167,10 @@ void plNetLinkingMgr::NCAgeJoinerCallback ( if (!params->success) { plNetClientMgr::StaticErrorMsg(params->msg); hsMessageBox(params->msg, "Linking Error", hsMessageBoxNormal, hsMessageBoxIconError); +#ifdef PLASMA_EXTERNAL_RELEASE plClientMsg* clientMsg = new plClientMsg(plClientMsg::kQuit); clientMsg->Send(hsgResMgr::ResMgr()->FindKey(kClient_KEY)); +#endif return; }