mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
#994 should not crash anymore.
This commit is contained in:
@@ -760,10 +760,17 @@ void YourTurn::applyCl( CClient *cl )
|
||||
}
|
||||
|
||||
void SaveGame::applyCl(CClient *cl)
|
||||
{
|
||||
try
|
||||
{
|
||||
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");
|
||||
save << *cl;
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
tlog1 << "Failed to save game:" << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMessage::applyCl(CClient *cl)
|
||||
{
|
||||
|
@@ -268,17 +268,23 @@ int CSaveFile::write( const void * data, unsigned size )
|
||||
void CSaveFile::openNextFile(const std::string &fname)
|
||||
{
|
||||
fName = fname;
|
||||
try
|
||||
{
|
||||
sfile = make_unique<std::ofstream>(fname.c_str(), std::ios::binary);
|
||||
sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
|
||||
|
||||
if(!(*sfile))
|
||||
{
|
||||
tlog1 << "Error: cannot open to write " << fname << std::endl;
|
||||
sfile = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
THROW_FORMAT("Error: cannot open to write %s!", fname);
|
||||
|
||||
sfile->write("VCMI",4); //write magic identifier
|
||||
*this << version; //write format version
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
tlog1 << "Failed to save to " << fname << std::endl;
|
||||
clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void CSaveFile::reportState(CLogger &out)
|
||||
@@ -290,6 +296,12 @@ void CSaveFile::reportState(CLogger &out)
|
||||
}
|
||||
}
|
||||
|
||||
void CSaveFile::clear()
|
||||
{
|
||||
fName.clear();
|
||||
sfile = nullptr;
|
||||
}
|
||||
|
||||
CLoadFile::CLoadFile(const std::string &fname, int minimalVersion /*= version*/)
|
||||
{
|
||||
registerTypes(*this);
|
||||
|
@@ -1004,11 +1004,12 @@ public:
|
||||
std::string fName;
|
||||
unique_ptr<std::ofstream> sfile;
|
||||
|
||||
CSaveFile(const std::string &fname);
|
||||
CSaveFile(const std::string &fname); //throws!
|
||||
~CSaveFile();
|
||||
int write(const void * data, unsigned size);
|
||||
|
||||
void openNextFile(const std::string &fname);
|
||||
void openNextFile(const std::string &fname); //throws!
|
||||
void clear();
|
||||
void reportState(CLogger &out);
|
||||
};
|
||||
|
||||
@@ -1026,10 +1027,9 @@ public:
|
||||
|
||||
CLoadFile(const std::string &fname, int minimalVersion = version); //throws!
|
||||
~CLoadFile();
|
||||
int read(const void * data, unsigned size);
|
||||
int read(const void * data, unsigned size); //throws!
|
||||
|
||||
void openNextFile(const std::string &fname, int minimalVersion); //throws!
|
||||
|
||||
void clear();
|
||||
void reportState(CLogger &out);
|
||||
};
|
||||
|
@@ -2250,6 +2250,8 @@ void CGameHandler::save( const std::string &fname )
|
||||
sendToAllClients(&sg);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
tlog0 << "Serializing game info...\n";
|
||||
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vlgm1");
|
||||
@@ -2264,6 +2266,11 @@ void CGameHandler::save( const std::string &fname )
|
||||
}
|
||||
tlog0 << "Game has been successfully saved!\n";
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
tlog1 << "Failed to save game: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CGameHandler::close()
|
||||
{
|
||||
|
Reference in New Issue
Block a user