//============================================================================ static void DownloadCallback ( ENetError result, void * param, const wchar_t filename[], hsStream * writer ) { if(IS_NET_ERROR(result)) { switch (result) { case kNetErrTimeout: writer->Rewind(); NetCliFileDownloadRequest(filename, writer, DownloadCallback, param); break; default: plString msg = plString::Format("Error getting patcher file: %S", NetErrorToString(result)); plStatusLog::AddLineS("patcher.log", msg.c_str()); if (IS_NET_SUCCESS(s_patchResult)) s_patchResult = result; break; } return; } writer->Close(); delete writer; AtomicAdd(&s_numFiles, -1); if(!s_numFiles) { s_downloadComplete = true; s_updated = true; } }
//============================================================================ static void ManifestCallback ( ENetError result, void * param, const wchar_t group[], const NetCliFileManifestEntry manifest[], unsigned entryCount ) { if(IS_NET_ERROR(result)) { switch (result) { case kNetErrTimeout: NetCliFileManifestRequest(ManifestCallback, nil, s_manifest); break; default: plString msg = plString::Format("Error getting patcher manifest: %S", NetErrorToString(result)); plStatusLog::AddLineS("patcher.log", msg.c_str()); if (IS_NET_SUCCESS(s_patchResult)) s_patchResult = result; break; } return; } #ifndef PLASMA_EXTERNAL_RELEASE if (entryCount == 0) { // dataserver does not contain a patcher s_downloadComplete = true; return; } #endif char ansi[MAX_PATH]; // MD5 check current patcher against value in manifest ASSERT(entryCount == 1); wchar_t curPatcherFile[MAX_PATH]; PathGetProgramName(curPatcherFile, arrsize(curPatcherFile)); StrToAnsi(ansi, curPatcherFile, arrsize(ansi)); if (!MD5Check(ansi, manifest[0].md5)) { // MessageBox(GetTopWindow(nil), "MD5 failed", "Msg", MB_OK); SelfPatcherStream::totalBytes += manifest[0].zipSize; AtomicAdd(&s_numFiles, 1); SetText("Downloading new patcher..."); StrToAnsi(ansi, s_newPatcherFile, arrsize(ansi)); SelfPatcherStream * stream = new SelfPatcherStream; if (!stream->Open(ansi, "wb")) ErrorAssert(__LINE__, __FILE__, "Failed to create file: %s, errno: %u", ansi, errno); NetCliFileDownloadRequest(manifest[0].downloadName, stream, DownloadCallback, nil); } else { s_downloadComplete = true; } }
bool pfPatcherWorker::IssueRequest() { hsTempMutexLock lock(fRequestMut); if (fRequests.empty()) { fRequestActive = false; fFileSignal.Signal(); // make sure the patch thread doesn't deadlock! return false; } else fRequestActive = true; const Request& req = fRequests.front(); switch (req.fType) { case Request::kFile: req.fStream->Begin(); if (fFileBeginDownload) fFileBeginDownload(req.fStream->GetFileName()); NetCliFileDownloadRequest(req.fName, req.fStream, IFileThingDownloadCB, this); break; case Request::kManifest: NetCliFileManifestRequest(IFileManifestDownloadCB, this, req.fName.ToWchar()); break; case Request::kSecurePreloader: // so, yeah, this is usually the "SecurePreloader" manifest on the file server... // except on legacy servers, this may not exist, so we need to fall back without nuking everything! NetCliFileManifestRequest(IPreloaderManifestDownloadCB, this, req.fName.ToWchar()); break; case Request::kAuthFile: // ffffffuuuuuu req.fStream->Begin(); if (fFileBeginDownload) fFileBeginDownload(req.fStream->GetFileName()); NetCliAuthFileRequest(req.fName, req.fStream, IAuthThingDownloadCB, this); break; case Request::kPythonList: NetCliAuthFileListRequest(L"Python", L"pak", IGotAuthFileList, this); break; case Request::kSdlList: NetCliAuthFileListRequest(L"SDL", L"sdl", IGotAuthFileList, this); break; DEFAULT_FATAL(req.fType); } fRequests.pop_front(); return true; }
void plResPatcher::IssueRequest() { if (!fPatching) return; if (fRequests.empty()) // Wheee! Finish(); else { Request req = fRequests.front(); fRequests.pop(); std::wstring title; if (req.fType == kManifest) { char* eapSucksString = hsWStringToString(req.fFile.c_str()); PatcherLog(kMajorStatus, " Downloading manifest... %s", eapSucksString); xtl::format(title, L"Checking %s for updates...", req.fFile.c_str()); NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.c_str()); delete[] eapSucksString; } else if (req.fType == kFile) { char* eapSucksString = hsWStringToString(req.fFriendlyName.c_str()); PatcherLog(kMajorStatus, " Downloading file... %s", eapSucksString); xtl::format(title, L"Downloading... %s", plFileUtils::GetFileName(req.fFriendlyName.c_str())); // If this is a PRP, we need to unload it from the ResManager if (stricmp(plFileUtils::GetFileExt(eapSucksString), "prp") == 0) ((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(eapSucksString); plFileUtils::EnsureFilePathExists(req.fFriendlyName.c_str()); plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile.c_str()); if(stream->Open(eapSucksString, "wb")) NetCliFileDownloadRequest(req.fFile.c_str(), stream, FileDownloaded, this); else { PatcherLog(kError, " Unable to create file %s", eapSucksString); Finish(false); } delete[] eapSucksString; } char* hack = hsWStringToString(title.c_str()); fProgress->SetTitle(hack); delete[] hack; } }
void plResPatcher::IssueRequest() { if (!fPatching) return; if (fRequests.empty()) // Wheee! Finish(); else { Request req = fRequests.front(); fRequests.pop(); 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.c_str()); } }