CMissionManager::RequestStatus CMissionManager::ProcessMissionScreenshotRequest() { if (!IsMissionScreenshotRequestInProgress()) { return NOT_IN_PROGRESS; } RequestStatus status = GetRequestStatusForDownloadId(_modScreenshotDownloadId); // Clean up the result if the request is complete if (status == FAILED || status == SUCCESSFUL) { fs::path tempFilename = g_Global.GetDarkmodPath(); tempFilename /= cv_tdm_fm_path.GetString(); tempFilename /= TMP_MISSION_SCREENSHOT_FILENAME; if (status == SUCCESSFUL) { CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload(_modScreenshotDownloadId); assert(download != NULL); // Mission was stored as userdata in the download object int missionIndex = download->GetUserData().id; int screenshotNum = download->GetUserData().id2; assert(missionIndex >= 0 && missionIndex < _downloadableMods.Num()); DownloadableMod& mission = *_downloadableMods[missionIndex]; assert(screenshotNum >= 0 && screenshotNum < mission.screenshots.Num()); // Open, convert and save the image if (!ProcessMissionScreenshot(tempFilename, mission, screenshotNum)) { gameLocal.Warning("Failed to process downloaded screenshot, mission %s, screenshot #%d", mission.modName.c_str(), screenshotNum); DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Failed to process downloaded screenshot, mission %s, screenshot #%d\r", mission.modName.c_str(), screenshotNum); status = FAILED; } } // Remove the temporary file DoRemoveFile(tempFilename); // Clear the download gameLocal.m_DownloadManager->RemoveDownload(_modScreenshotDownloadId); _modScreenshotDownloadId = -1; } return status; }
CMissionManager::RequestStatus CMissionManager::ProcessReloadModDetailsRequest() { if (!IsModDetailsRequestInProgress()) { return NOT_IN_PROGRESS; } RequestStatus status = GetRequestStatusForDownloadId(_modDetailsDownloadId); // Clean up the result if the request is complete if (status == FAILED || status == SUCCESSFUL) { fs::path tempFilename = g_Global.GetDarkmodPath(); tempFilename /= TMP_MISSION_DETAILS_FILENAME; if (status == SUCCESSFUL) { XmlDocumentPtr doc(new pugi::xml_document); pugi::xml_parse_result result = doc->load_file(tempFilename.string().c_str()); if (result) { CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload(_modDetailsDownloadId); assert(download != NULL); // Mod number was stored as userdata in the download object int modNum = download->GetUserData().id; LoadModDetailsFromXml(doc, modNum); } else { // Failed to parse XML status = FAILED; } } // Remove the temporary file DoRemoveFile(tempFilename); // Clear the download gameLocal.m_DownloadManager->RemoveDownload(_modDetailsDownloadId); _modDetailsDownloadId = -1; } return status; }