QTfrontend/hwform.cpp
changeset 533 eebb7684ac22
parent 530 f0b962214436
child 535 a14eaf35cf4b
equal deleted inserted replaced
532:8136a5363586 533:eebb7684ac22
   453 {
   453 {
   454 	game = new HWGame(config, gamecfg, pTeamSelWidget);
   454 	game = new HWGame(config, gamecfg, pTeamSelWidget);
   455 	connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
   455 	connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
   456 	connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &)));
   456 	connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &)));
   457 	connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
   457 	connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
       
   458 	connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
   458 }
   459 }
   459 
   460 
   460 void HWForm::ShowErrorMessage(const QString & msg)
   461 void HWForm::ShowErrorMessage(const QString & msg)
   461 {
   462 {
   462 	QMessageBox::warning(this,
   463 	QMessageBox::warning(this,
   463 			"Hedgewars",
   464 			"Hedgewars",
   464 			msg);
   465 			msg);
   465 }
   466 }
       
   467 
       
   468 void HWForm::GetRecord(bool isDemo, const QByteArray & record)
       
   469 {
       
   470 	QString filename;
       
   471 	QByteArray demo = record;
       
   472 	if (isDemo)
       
   473 	{
       
   474 		demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
       
   475 		demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
       
   476 		filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + cProtoVer;
       
   477 	} else
       
   478 	{
       
   479 		demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
       
   480 		demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
       
   481 		filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + cProtoVer;
       
   482 	}
       
   483 
       
   484 
       
   485 	QFile demofile(filename);
       
   486 	if (!demofile.open(QIODevice::WriteOnly))
       
   487 	{
       
   488 		ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
       
   489 		return ;
       
   490 	}
       
   491 	demofile.write(demo.constData(), demo.size());
       
   492 	demofile.close();
       
   493 }