CSaveFile.cpp 979 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * CSaveFile.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CSaveFile.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. CSaveFile::CSaveFile(const boost::filesystem::path &fname)
  14. : serializer(this)
  15. , sfile(fname.c_str(), std::ios::out | std::ios::binary)
  16. {
  17. sfile.exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
  18. if(!sfile)
  19. throw std::runtime_error("Error: cannot open file '" + fname.string() + "' for writing!");
  20. sfile.write("VCMI", 4); //write magic identifier
  21. serializer & ESerializationVersion::CURRENT; //write format version
  22. sfile.write(SAVEGAME_MAGIC.c_str(), SAVEGAME_MAGIC.length());
  23. }
  24. int CSaveFile::write(const std::byte * data, unsigned size)
  25. {
  26. sfile.write(reinterpret_cast<const char *>(data), size);
  27. return size;
  28. }
  29. VCMI_LIB_NAMESPACE_END