// Code to read from the file. Works in debug, but not in release-build, exception: stream_error
void ReceiveDataThread::ReceiveHudData()
{
ApplicationPaths paths;
TableData huddata;
namespace ipc = boost::interprocess;
unsigned int priority; ///< The priority
ipc::message_queue::size_type recvd_size;
std::wstring messagetype;
try
{
ipc::message_queue mqdata(ipc::open_only, MQ_HUDDATA);
messagetype.resize(mqdata.get_max_msg_size());
if(mqdata.try_receive(&messagetype[0], messagetype.size(), recvd_size, priority))
{
if(messagetype.compare(L"tabledata") >= 0) // data send by GUI-App
{
if(boost::filesystem3::exists(wxString::Format(_T("%shuddata.prd"), paths.GetUserLocalDataDir()).ToStdWstring().c_str()))
{
wxLogMessage(L"Restore Tabledata");
RestoreTableData(huddata, wxString::Format(_T("%shuddata.prd"), paths.GetUserLocalDataDir()).ToStdWstring().data());
wxLogMessage(L"Try to set table data");
wxGetApp().SetTableData(huddata);
}
}
}
}
catch (boost::thread_interrupted&)
{
//OutputDebugString("message thread closed");
}
catch (ipc::interprocess_exception& ipcex)
{
//ipc::message_queue::remove("pokerreader_msg");
//OutputDebugString(ipcex.what());
}
catch(boost::archive::archive_exception& ex)
{
ex.what();
}
catch(boost::thread_exception& tex)
{
tex.what();
}
}
void ReceiveDataThread::RestoreTableData(TableData &s, const wchar_t * filename)
{
// open the archive
std::wifstream ifs(filename);
if (!ifs.good())
{
std::cout << "Could not open file to read: " << filename << std::endl;
return;
}
boost::archive::text_wiarchive ia(ifs);
// restore the schedule from the archive
ia >> BOOST_SERIALIZATION_NVP(s);
//std::cout << "Restored, var1=" << s.var1
#if USE_VERSION == 1
// << " var2=" << s.var2
#endif
// << std::endl;
}
// Code to save the file, no problem in debug- and release-build, no exception
try
{
std::wofstream datafile(wxString::Format(_T("%shuddata.prd"), paths.GetUserLocalDataDir()).ToStdWstring().c_str());
#ifdef DATA_TO_XML
boost::archive::xml_woarchive dataarchive(datafile);
dataarchive << BOOST_SERIALIZATION_NVP(huddata);
#else
boost::archive::text_woarchive dataarchive(datafile);
dataarchive << BOOST_SERIALIZATION_NVP(huddata);
datafile.close();
#endif
return true;
}
catch(boost::archive::archive_exception& ex)
{
return false;
}
catch(...)
{
return false;
}