idStr CDownloadMenu::GetMissionDownloadProgressString( int modIndex ) {
	ActiveDownloads::const_iterator it = _downloads.find( modIndex );
	if( it == _downloads.end() ) {
		return common->Translate( "#str_02180" );
	}
	CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload( it->second.missionDownloadId );
	CDownloadPtr l10nDownload;
	if( it->second.l10nPackDownloadId != -1 ) {
		l10nDownload = gameLocal.m_DownloadManager->GetDownload( it->second.l10nPackDownloadId );
	}
	if( !download && !l10nDownload ) {
		return idStr();
	}
	switch( download->GetStatus() ) {
	case CDownload::NOT_STARTED_YET:
		return common->Translate( "#str_02180" );	// "queued "
	case CDownload::FAILED:
		return common->Translate( "#str_02181" );	// "failed "
	case CDownload::IN_PROGRESS: {
		double totalFraction = download->GetProgressFraction();
		if( l10nDownload ) {
			// We assume the L10n pack to consume 10% of the whole download
			// This is just a rough guess, for some missions the l10n pack
			// is bigger than the mission, for others it is only 5%
			totalFraction *= 0.90f;
			totalFraction += 0.10f * l10nDownload->GetProgressFraction();
		}
		return va( "%0.1f%s", totalFraction * 100, "% " );
	}
	case CDownload::SUCCESS:
		return "100% ";
	default:
		return "??";
	};
}
Example #2
0
CMissionManager::RequestStatus CMissionManager::GetRequestStatusForDownloadId(int downloadId)
{
	CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload(downloadId);

	if (download == NULL) return NOT_IN_PROGRESS;

	switch (download->GetStatus())
	{
	case CDownload::NOT_STARTED_YET:	
		return IN_PROGRESS;

	case CDownload::IN_PROGRESS:
		return IN_PROGRESS;

	case CDownload::FAILED:
		return FAILED;

	case CDownload::SUCCESS:
		return SUCCESSFUL;

	default: 
		gameLocal.Printf("Unknown download status encountered in GetRequestStatusForDownloadId()\n");
		return NOT_IN_PROGRESS;
	};
}
Example #3
0
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;
}
void CDownloadMenu::UpdateDownloadProgress( idUserInterface *gui ) {
	int numSelectedModsPerPage = gui->GetStateInt( "selectedPackagesPerPage", "5" );
	bool downloadsInProgress = false;
	// Check if we have any mission downloads pending.
	// Don't use DownloadManager::DownloadInProgress(), as there might be different kind of downloads in progress
	for( ActiveDownloads::const_iterator it = _downloads.begin(); it != _downloads.end(); ++it ) {
		int missionDownloadId = it->second.missionDownloadId;
		int l10nPackDownloadId = it->second.l10nPackDownloadId;
		CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload( missionDownloadId );
		CDownloadPtr l10nDownload = l10nPackDownloadId != -1 ? gameLocal.m_DownloadManager->GetDownload( missionDownloadId ) : CDownloadPtr();
		if( !download && !l10nDownload ) {
			continue;
		}
		if( download->GetStatus() == CDownload::IN_PROGRESS ||
				( l10nDownload && l10nDownload->GetStatus() == CDownload::IN_PROGRESS ) ) {
			downloadsInProgress = true;
			break;
		}
	}
	// Missions in the download queue
	for( int i = 0; i < numSelectedModsPerPage; ++i ) {
		// Apply page offset
		int listIndex = i + _selectedListTop;
		bool listItemExists = listIndex < _selectedMods.Num();
		// Get the referenced mod index, -1 ==> no mod
		int modIndex = listItemExists ? _selectedMods[listIndex] : -1;
		if( !listItemExists || modIndex == -1 ) {
			gui->SetStateString( va( "dl_mission_progress_%d", i ), "" );
			continue;
		}
		// Update the progress string
		idStr progressStr = GetMissionDownloadProgressString( modIndex );
		if( progressStr.IsEmpty() ) {
			continue;
		}
		gui->SetStateString( va( "dl_mission_progress_%d", i ), progressStr );
	}
	// Update the "in progress" state flag
	bool prevDownloadsInProgress = gui->GetStateBool( "mission_download_in_progress" );
	gui->SetStateBool( "mission_download_in_progress", downloadsInProgress );
	if( prevDownloadsInProgress != downloadsInProgress ) {
		gui->HandleNamedEvent( "UpdateAvailableMissionColours" );
		if( downloadsInProgress == false ) {
			// Fire the "finished downloaded" event
			ShowDownloadResult( gui );
		}
	}
}
Example #5
0
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;
}
Example #6
0
void CDownloadManager::ProcessDownloads()
{
	if (_allDownloadsDone || _downloads.empty()) 
	{
		return; // nothing to do
	}

	if (DownloadInProgress())
	{
		return; // download still in progress
	}

	// No download in progress, pick a new from the queue
	for (Downloads::const_iterator i = _downloads.begin(); i != _downloads.end(); ++i)
	{
		if (i->second->GetStatus() == CDownload::NOT_STARTED_YET)
		{
			DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Starting download: %i", i->first);

			i->second->Start();

			// Check if this download has a related one, if yes, launch both at once
			int relatedId = i->second->GetRelatedDownloadId();

			if (relatedId != -1)
			{
				CDownloadPtr related = GetDownload(relatedId);

				if (related)
				{
					DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Starting related download: %i", relatedId);

					related->Start();
				}
			}

			return;
		}
	}

	// No download left to handle
	_allDownloadsDone = true;
}
void CDownloadMenu::ShowDownloadResult( idUserInterface *gui ) {
	// greebo: Let the mod list be refreshed
	// We need the information from darkmod.txt later down this road
	gameLocal.m_MissionManager->ReloadModList();
	int successfulDownloads = 0;
	int failedDownloads = 0;
	const DownloadableModList &mods = gameLocal.m_MissionManager->GetDownloadableMods();
	for( ActiveDownloads::iterator i = _downloads.begin(); i != _downloads.end(); ++i ) {
		CDownloadPtr download = gameLocal.m_DownloadManager->GetDownload( i->second.missionDownloadId );
		if( download == NULL ) {
			continue;
		}
		if( i->first > mods.Num() ) {
			continue;
		}
		const DownloadableMod &mod = *mods[i->first];
		switch( download->GetStatus() ) {
		case CDownload::NOT_STARTED_YET:
			gameLocal.Warning( "Some downloads haven't been processed?" );
			break;
		case CDownload::FAILED:
			failedDownloads++;
			break;
		case CDownload::IN_PROGRESS:
			gameLocal.Warning( "Some downloads still in progress?" );
			break;
		case CDownload::SUCCESS: {
			// gnartsch
			bool l10nPackDownloaded = false;
			// In case of success, check l10n download status
			if( i->second.l10nPackDownloadId != -1 ) {
				CDownloadPtr l10nDownload = gameLocal.m_DownloadManager->GetDownload( i->second.l10nPackDownloadId );
				CDownload::DownloadStatus l10nStatus = l10nDownload->GetStatus();
				if( l10nStatus == CDownload::NOT_STARTED_YET || l10nStatus == CDownload::IN_PROGRESS ) {
					gameLocal.Warning( "Localisation pack download not started or still in progress?" );
				} else if( l10nStatus == CDownload::FAILED ) {
					gameLocal.Warning( "Failed to download localisation pack!" );
					// Turn this download into a failed one
					failedDownloads++;
				} else if( l10nStatus == CDownload::SUCCESS ) {
					// both successfully downloaded
					successfulDownloads++;
					// gnartsch
					l10nPackDownloaded = true;
				}
			} else { // regular download without l10n ... or l10n download only (gnartsch)
				successfulDownloads++;
				// gnartsch: Consider Localization pack having been dealt with as well
				l10nPackDownloaded = true;
			}
			// Save the mission version into the MissionDB for later use
			CModInfoPtr missionInfo = gameLocal.m_MissionManager->GetModInfo( mod.modName );
			missionInfo->SetKeyValue( "downloaded_version", idStr( mod.version ).c_str() );
			// gnartsch: Mark l10n pack as present, so that the mission may disappear from the list of 'Available Downloads'
			missionInfo->isL10NpackInstalled = l10nPackDownloaded;
		}
		break;
		};
	}
	gameLocal.Printf( "Successful downloads: %d\nFailed downloads: %d\n", successfulDownloads, failedDownloads );
	// Display the popup box
	GuiMessage msg;
	msg.type = GuiMessage::MSG_OK;
	msg.okCmd = "close_msg_box;onDownloadCompleteConfirm";
	msg.title = common->Translate( "#str_02142" ); // "Mission Download Result"
	msg.message = "";
	if( successfulDownloads > 0 ) {
		msg.message += va(
						   // "%d mission/missions successfully downloaded. You'll find it/them in the 'New Mission' page."
						   GetPlural( successfulDownloads, common->Translate( "#str_02144" ), common->Translate( "#str_02145" ) ),
						   successfulDownloads );
	}
	if( failedDownloads > 0 ) {
		// "\n%d mission(s) couldn't be downloaded. Please check your disk space (or maybe some file is write protected) and try again."
		msg.message += va( common->Translate( "#str_02146" ),
						   failedDownloads );
	}
	gameLocal.AddMainMenuMessage( msg );
	// Remove all downloads
	for( ActiveDownloads::iterator i = _downloads.begin(); i != _downloads.end(); ++i ) {
		gameLocal.m_DownloadManager->RemoveDownload( i->second.missionDownloadId );
		if( i->second.l10nPackDownloadId != -1 ) {
			gameLocal.m_DownloadManager->RemoveDownload( i->second.l10nPackDownloadId );
		}
	}
	_downloads.clear();
}