示例#1
0
void PreviewModel::OnResponseReady(void * object, int identifier)
{
	if (identifier == 1)
	{
		delete saveData;
		saveData = (std::vector<unsigned char>*)object;
	}
	if (identifier == 2)
	{
		delete save;
		save = (SaveInfo*)object;
	}
	if (identifier == 3)
	{
		if (saveComments)
		{
			for (size_t i = 0; i < saveComments->size(); i++)
				delete saveComments->at(i);
			saveComments->clear();
			delete saveComments;
			saveComments = NULL;
		}
		saveComments = (std::vector<SaveComment*>*)object;
		commentsLoaded = true;
		notifySaveCommentsChanged();
		notifyCommentsPageChanged();
	}

	if (identifier == 1 || identifier == 2)
	{
		if (save && saveData)
		{
			commentsTotal = save->Comments;
			try
			{
				GameSave *gameSave = new GameSave(*saveData);
				if (gameSave->fromNewerVersion)
					new ErrorMessage("This save is from a newer version", "Please update TPT in game or at http://powdertoy.co.uk");
				save->SetGameSave(gameSave);
			}
			catch(ParseException &e)
			{
				new ErrorMessage("Error", e.what());
				canOpen = false;
			}
			notifySaveChanged();
			notifyCommentsPageChanged();
			//make sure author name comments are red
			if (commentsLoaded)
				notifySaveCommentsChanged();
		}
	}
}
示例#2
0
void PreviewModel::UpdateComments(int pageNumber)
{
	if (commentsLoaded)
	{
		commentsLoaded = false;
		if (saveComments)
		{
			for (size_t i = 0; i < saveComments->size(); i++)
				delete saveComments->at(i);
			saveComments->clear();
			delete saveComments;
			saveComments = NULL;
		}

		commentsPageNumber = pageNumber;
		if (!GetDoOpen())
			RequestBroker::Ref().Start(Client::Ref().GetCommentsAsync(tSaveID, (commentsPageNumber-1)*20, 20), this, 3);

		notifySaveCommentsChanged();
		notifyCommentsPageChanged();
	}
}
示例#3
0
void PreviewModel::UpdateComments(int pageNumber)
{
	commentsLoaded = false;
	if(saveComments)
	{
		for(int i = 0; i < saveComments->size(); i++)
			delete saveComments->at(i);
		saveComments->clear();
		saveComments = NULL;
	}

	//resultCount = 0;
	commentsPageNumber = pageNumber;
	notifySaveCommentsChanged();
	notifyCommentsPageChanged();

	//Threading
	if(!updateSaveCommentsWorking)
	{
		updateSaveCommentsFinished = false;
		updateSaveCommentsWorking = true;
		pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsTHelper, this);
	}
}
示例#4
0
void PreviewModel::Update()
{
	if(updateSaveDataWorking)
	{
		if(updateSaveDataFinished)
		{
			updateSaveDataWorking = false;
			pthread_join(updateSaveDataThread, NULL);

			if(updateSaveInfoFinished && save)
			{
				commentsTotal = save->Comments;
				try
				{
					save->SetGameSave(new GameSave(&saveDataBuffer[0], saveDataBuffer.size()));
				}
				catch(ParseException &e)
				{
					throw PreviewModelException("Save file corrupt or from newer version");
				}
				notifySaveChanged();
				notifyCommentsPageChanged();
			}
		}
	}

	if(updateSaveInfoWorking)
	{
		if(updateSaveInfoFinished)
		{
			if(save)
			{
				delete save;
				save = NULL;
			}
			updateSaveInfoWorking = false;
			pthread_join(updateSaveInfoThread, (void**)(&save));
			if(updateSaveDataFinished && save)
			{
				commentsTotal = save->Comments;
				try
				{
					save->SetGameSave(new GameSave(&saveDataBuffer[0], saveDataBuffer.size()));
				}
				catch(ParseException &e)
				{
					throw PreviewModelException("Save file corrupt or from newer version");
				}
				notifyCommentsPageChanged();
			}
			notifySaveChanged();

			if(!save)
				throw PreviewModelException("Unable to load save");
		}
	}

	if(updateSaveCommentsWorking)
	{
		if(updateSaveCommentsFinished)
		{
			if(saveComments)
			{
				for(int i = 0; i < saveComments->size(); i++)
					delete saveComments->at(i);
				saveComments->clear();
				saveComments = NULL;
			}
			commentsLoaded = true;
			updateSaveCommentsWorking = false;
			pthread_join(updateSaveCommentsThread, (void**)(&saveComments));
			notifySaveCommentsChanged();
		}
	}
}